To create a support ticket, start a search

Specific Prices (window): Adding a field from a table outside the specific prices table


Prerequisites

  • Store Commander version 2014-03-12
  • SC Grids Editor Pro Add-on - version 1.0
  • The field needs to exist in your database


 

Target

We would like to add the field "My field" which is located in the table ps_ma_table (this table does not exist in PrestaShop by default).

We will then be able to:

  • use filters to optimize the selection of specific prices
  • mass-edit this field using Store Commander's copy/paste option
  • rapidly export the specific prices panel with this field


 

Setup

  • To add the field to the list of available fields for your products grids, click on the add.png in the 'Add a field' panel and enter the following information:


What is the field ID? : my_field (should be exactly the name as it is in the database).
 

  • SC creates the field, you now need to populate the grid with:


Field name: My field

Table: special

Type: multiple choice (should corresponds to the type of your field, here with preset values)


 

  • In this example, the fields are in table ps_my_table:

 

id_of_my_table, id_product, mon_champ

 

  • From the Advanced Properties panel:

List of choices (only if the field type is 'multiple choices, otherwise leave blank)

return array(0=>_l('None'), 1=>_l('Value 1'), 2=>_l('Value 2'));


 

SQLSelectDataSelect :

return ' ,mt.my_field ';
 

SQLSelectDataLeftJoin : 

return " LEFT JOIN "._DB_PREFIX_."my_table  mt  ON (mt.id_product= p.id_product)";

 

onAfterUpdateSQL : 

if(isset($_POST["my_field"])) {

$sql = "SELECT * FROM "._DB_PREFIX_."ma_table WHERE id_product=".(int)$id_product;
$res=Db::getInstance()->ExecuteS($sql);
$my_field = (int)Tools::getValue('mon_champ',0);
if (count($res))
{

   if ($mon_champ)
   {
   $sql = "UPDATE "._DB_PREFIX_."my_table  SET my_field=".(int)$my_field."  WHERE id_product=".(int)$id_product;
   Db::getInstance()->Execute($sql);
   }else{
   $sql = "DELETE FROM "._DB_PREFIX_."my_table  WHERE id_product=".(int)$id_product;
   Db::getInstance()->Execute($sql);
   }
}else{
   $sql = "INSERT INTO "._DB_PREFIX_."my_table  (id_product,my_field) VALUES (".(int)$id_product.",".pSQL($my_field).")";
   Db::getInstance()->Execute($sql);
}

}

 

You will need to adapt this code to your needs.

 

  • Exit the editing window and add the field to your grids.