Jump to content

Add new field in admin product field prestashop 1.61.6


Marius05

Recommended Posts

Hi!

 

I want to add new column admin product listing to display or not product in website.

 

1. I have create an override for classes/Product.php in controllers/AdminProductsController.php and add new column in database tables (product, product_shop) . Column name is hideproduct

 

In Product.php i have:

class Product extends ProductCore
{
 
	
	public $hideproduct = false;
	
	public function toggleHideProduct()
	{
		$this->setFieldsToUpdate(array('hideproduct' => true));
	 	$this->hideproduct = !(int)$this->hideproduct;
		return $this->update(false);
	}
	
	public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
	{
		self::$definition['fields']['hideproduct'] = array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool');
	
		parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
	}
 
}

In AdminProductsController.php i have:

class AdminProductsController extends AdminProductsControllerCore
{
 
	public function initProcess()
	{
		parent::initProcess();
		
		if ((isset($_GET['hideproduct'.$this->table]) || isset($_GET['hideproduct'])) && Tools::getValue($this->identifier))
		{
			if ($this->tabAccess['edit'] === '1')
				$this->action = 'hideproduct';
			else
				$this->errors[] = Tools::displayError('You do not have permission to edit this.');
		}
	}
 
	public function __construct()
	{
		parent::__construct();
 
		$this->fields_list['hideproduct'] = array(
			'title' => $this->l('Hide product'),
			'active' => 'hide',
            'filter_key' => 'sa!hideproduct',
			'type' => 'bool',
			'class' => 'fixed-width-sm',
			'orderby' => false
		);
	}
 
	public function processhideproduct()
	{
		if (Validate::isLoadedObject($object = $this->loadObject()))
		{
			$object->toggleHideProduct();
			$this->confirmations[] = $this->l('Actiune efectuata cu succes');
		}
		return $object;
	}
 
}

In attach is images with database column structure and admin new column.

 

 

Everything seems fine but when I want to change their status to product not working.
Can anyone tell me what is the cause?

 

Thank you!

Marius

post-283916-0-56965400-1488539373_thumb.jpg

post-283916-0-71370200-1488539383_thumb.jpg

Edited by Marius05 (see edit history)
Link to comment
Share on other sites

Hi!

I want product link and product info  to be listed, if i use Status i have product link but all the info disapear.

Therefore I tried to create my new method of hidding product

 

Another option is to use Visibility. But how ken I use and display Vsibility in admin product listing column ?

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...