Jump to content

[NOT SOLVED] How to add a new column with "checked button" in backoffice product list?


ajnglagla

Recommended Posts

I want to change a database field value by clicking checkit.gif in back-office product list. (0 or 1)

 

The field which i want to change is "bigimage" (tinyint) in my ps_image database. "bigimage" inside have just "1" or "0".

 

I know how to  add column and pull data to show in product list (in AdminProductsConroller.php) but I dont know how to add a "checked button" and change a data in database.

 

Can someone help me how to do that please?

 

CIClGVD.jpg

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

hello

in field list definition

		$this->fields_list['bigimage'] = array(
			'title' => $this->l('Big Image'),
			'active' => 'status',
			'filter_key' => 'SQL FIELD NAME',
			'align' => 'text-center',
			'type' => 'bool',
			'class' => 'fixed-width-sm',
			'orderby' => false
		);

change SQL FIELD NAME with name of your field you want to change

  • Like 1
Link to comment
Share on other sites

hello

in field list definition

		$this->fields_list['bigimage'] = array(
			'title' => $this->l('Big Image'),
			'active' => 'status',
			'filter_key' => 'SQL FIELD NAME',
			'align' => 'text-center',
			'type' => 'bool',
			'class' => 'fixed-width-sm',
			'orderby' => false
		);

change SQL FIELD NAME with name of your field you want to change

 

 

Thanks soooo much. Its showing right. But there is a small problem.

When i click on "bigmage" checked button , "status" checked button is changing to "X".

 

I am using this SQL code. am i missing something?

 

$this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'image` bigi ON (bigi.`id_image` = i.`id_image` AND bigi.`cover` = 1 AND bigi.`id_product` = a.`id_product`)';

$this->fields_list['bigimage'] = array(
'title' => $this->l('Big Image'),
'active' => 'status',
'filter_key' => 'bigi!bigimage',
'align' => 'text-center',
'type' => 'bool',
'class' => 'fixed-width-sm',
'orderby' => false
);

 

Screenshot:HOOiPbF.jpg

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

Pulling data is ok, but inserting / changing data is painful for my limited skills.

I have tried this, (i hoped that code could work for me) but i am not sure how to say this code if (product_id = product_id AND image_cover = 1 ) you change the data.

		$this->fields_list['bigimage'] = array(
			'title' => $this->l('Büyük Foto'),
			'width' => 70,
			'active' => 'isBigimage',
			'filter_key' => 'bigi!bigimage',
			'align' => 'center',
			'type' => 'bool',
			'orderby' => false
		);
public function postProcess()
{
	if (isset($_GET['isBigimage'.$this->table]))
	{
	     $this-> processBigimage();
	} 
}
public function processBigimage()
	{
		$image = new Image($this->id_object);
		if (!Validate::isLoadedObject($image))
			$this->errors[] = Tools::displayError('An error occurred while updating bigimage information.');
		$image->bigimage = $image->bigimage ? 0 : 1;
		if (!$image->update())
			$this->errors[] = Tools::displayError('An error occurred while updating bigimage information.');
		Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token);
	}

But i took this error

[PrestaShopException]

Property Image->id_product is empty
at line 837 in file classes/ObjectModel.php
Link to comment
Share on other sites

  • 5 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...