To create a support ticket, start a search

Products Grid: Add a column displaying a product feature (editable)

Prerequisites:

- Store Commander version 2014-03-12
- SC Grids Editor Pro Add-on - version 1.0

 

Target:

We would like to add a column displaying values of a specific feature in the products grid.

We will then be able to:

- use the filters in the grids to optimize the selection of products
- rapidly export the products grid with this field
- edit quickly the feature on several products

 

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?: myfeature

 

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

Field name: Delivery

Table: enter: special

Refresh combinations: keep 'no'

Type: multiple choice

 

  • From the Advanced Properties panel:

 

SQLSelect:

 

return ' , (SELECT fp.id_feature_value FROM `ps_feature_product` fp 
where fp.id_feature = "3" 
and fp.id_product = p.id_product) 
as myfeature ';

 

Select options : 


$sql = "SELECT fvl.* 
FROM "._DB_PREFIX_."feature_value_lang fvl 
INNER JOIN "._DB_PREFIX_."feature_value fv ON (fv.id_feature_value=fvl.id_feature_value) 
WHERE fvl.id_lang=1 
AND fv.id_feature = 3"; 
$res=Db::getInstance()->ExecuteS($sql); 
$tmp = array(); 
$tmp[0]=" "; 
foreach($res as $row) 
$tmp[$row["id_feature_value"]]=$row["value"]; 
return $tmp;

 

PHP onAfterUpdateSQL : 

if ($feature_value = (int)Tools::getValue('myfeature',0))
{

$sql = "SELECT * FROM "._DB_PREFIX_."feature_product WHERE id_product='".(int)$idproduct."' AND id_feature='3'"; 
$res=Db::getInstance()->ExecuteS($sql); 
if (count($res)) 

if ($feature_value) 

$sql = "UPDATE "._DB_PREFIX_."feature_product SET id_feature_value='".(int)$feature_value."' WHERE id_product='".(int)$idproduct."' AND id_feature='3'"; 
Db::getInstance()->Execute($sql); 
}else{ 
$sql = "DELETE FROM "._DB_PREFIX_."feature_product WHERE id_product='".(int)$idproduct."' AND id_feature='3'"; 
Db::getInstance()->Execute($sql); 

}else{ 
$sql = "INSERT INTO "._DB_PREFIX_."feature_product (id_feature,id_product,id_feature_value) VALUES ('3','".(int)$idproduct."','".(int)$feature_value."')"; 
Db::getInstance()->Execute($sql); 
}

}

 

In this instance, we use feature ID3. You can change the feature by looking for its ID in the Features panel (SC Catalog>Features)

 

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