To create a support ticket, start a search

Images Grid: Adding a field from a specific table (editable)


Prerequisites:

- Store Commander version 2014-03-12 (minimum)
- SC Grids Editor Pro Add-on - version 1.0 (minimum)
- The field needs to exist in your database
- The field needs to exist in PrestaShop Product Class to be used in your Front Office templates (optional) 

 

Target:

We would like to add the field 'specific action' stored in ps_my_table.

 

Setup:

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

What is the field ID?: specific_action (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: Specific Action

Table: enter: special

Type: editable

 

  • From the Advanced Properties panel:
SQLSelectDataSelect :
 
return ' ,my_table.specific_action ';
 
 
 
SQLSelectDataLeftJoin : 
 
return " LEFT JOIN "._DB_PREFIX_."my_table ON (my_table.id_image= i.id_image)";
 
 
 
Gris JS on EditCell :
 
idx_specific_action=prop_tb._imagesGrid.getColIndexById('specific_action');
if(stage==2)
{
if (cInd == idx_specific_action){
$.post("index.php?ajax=1&act=cat_image_update&action=update&id_lang="+SC_ID_LANG+"&"+new Date().getTime(),{'id_product': lastProductSelID, col: 'specific_action', val: nValue.replace(/#/g,''), 'list_id_image':prop_tb._imagesGrid.getSelectedRowId()},function(data){});
}
}
 
 
 
onAfterUpdateSQL : 
 
if($col=='specific_action')
{
$sql = "SELECT * FROM "._DB_PREFIX_."my_table WHERE id_image=".(int)$id_image;
$res=Db::getInstance()->ExecuteS($sql);
if (count($res))
{
   $sql = "UPDATE "._DB_PREFIX_."my_table SET specific_action=".pSQL($val)."  WHERE id_image=".(int)$id_image;
   Db::getInstance()->Execute($sql);
}else{
   $sql = "INSERT INTO "._DB_PREFIX_."my_table (id_image,specific_action) VALUES (".(int)$id_image.",".pSQL($val).")";
   Db::getInstance()->Execute($sql);
}
}

 

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