Pour créer un ticket support, commencez par une recherche

Code index


Select Options

Pour utiliser cet outil, le cell type de votre champ doit être 'multiple choice'.
Cette section vous permet de configurer les options du menu de sélection lorsque l'utilisateur clique pour éditer la cellule.

Pour mettre en place les options, vous devez utiliser return a PHP array:

return array(1=>'Yes' , 0=>'No');

Vous pouvez utiliser un code plus complexe pour récupérer les options de la table :

$sql = 'SELECT id_logistician,name_logistician FROM ps_logistician ORDER BY name_logistician';
$res = Db::getInstance()->ExecuteS($sql);
$tmparray = array(0 => 'NA');
foreach ($res AS $row) {
    $tmparray[$row['id_logistician']] = $row['name_logistician'];
}
return $tmparray;

 

SQL Select

Ici vous devez récupérer le nom du champ qui sera affiché dans les grilles. 
Cela sera utilisé dans la requête principale pour obtenir les informations produits/commandes.

Vous pouvez utiliser ces variables :

$view - name of the current grid view
$cols - array of columns of the grid
$id_lang - language used in the interface

Exemple:

return ' ,myTableAlias.myTableFieldName AS myFieldName';


You can use a more complex code to get the feature value of the product:

return ' , (SELECT fvl.value FROM `ps_feature_product` fp 
                LEFT JOIN `ps_feature_value_lang` fvl 
                ON (fp.id_feature_value=fvl.id_feature_value and fvl.id_lang=2)
                WHERE fp.id_feature = 3 
                AND fp.id_product = p.id_product) as myFeature ';


Un autre exemple pour ajouter le nom des produits commandés dans la grille des commandes (exemple complet disponible sur notre base de connaissance) :

return ' , (SELECT GROUP_CONCAT(product_name SEPARATOR '') 
                FROM `'._DB_PREFIX_.'order_detail` od 
                WHERE od.id_order = o.id_order) as orderProductsNames ';

 


SQL Left Join

Vous ne devez pas utiliser les alias qui correspondent aux tables classiques de Prestashop pour les champs de tables externes (ne pas utiliser "p.", "a.", etc.)

Vous pouvez utiliser ces variables :

$view - name of the current grid view
$cols - array of columns of the grid
$id_lang - language used in the interface

Exemples:

return " LEFT JOIN "._DB_PREFIX_."myTable myTableAlias ON (myTableAlias.id_product= p.id_product) ";


Attention : si vous utilisez plusieurs champs d'une table externe (myTable), vous devez insérer cette information une seule fois pour tous les champs.

 

Grid JS onBeforeUpdate

Work in progress...

 

Grid JS onEditCell

This event is triggered when a cell is edited by the user in the interface.

// onEditCell(stage,rId,cInd,nValue,oValue)
// rId is the row ID
// cInd is the column INDEX
// nValue is the new value
// oValue is the old value

if (nValue != oValue) {
    idxDeliveryInfo = cat_grid.getColIndexById('DeliveryInfo');
    if (cInd == idxDeliveryInfo) {
// here we truncate the data entered by the user
        cat_grid.cells(rId, idxDeliveryInfo).setValue(cat_grid . cells(rId, idxDeliveryInfo).getValue().substr(0, 100));
    }
}


Grid JS onAfterUpdate

Work in progress...

 

PHP definition

When you add a field to the combinations grid, you need to declare it in this section.

$combArray[$combinaison['id_product_attribute']]['myFieldName'] = $combinaison['myFieldName'];


PHP onBeforeUpdateSQL

Work in progress...

 

PHP onAfterUpdateSQL

This event is triggered when the user's browser sends the data to the server.
In this section we need to store the new value in the database.

You can use these variables:

$id_product
$id_lang 

Example:

$sql = "SELECT * FROM "._DB_PREFIX_."myTable WHERE id_product=".(int)$id_product;
$res = Db::getInstance()->ExecuteS($sql);
$myFieldName = Tools::getValue('myFieldName', -1);
if (count($res)) {
    if (in_array($myFieldName, array('North', 'East'))) // we check if the new value is in the expected range of values
    {
        $sql = "UPDATE "._DB_PREFIX_."myTable SET myFieldName=".psql($myFieldName)." WHERE id_product=".(int)$id_product;
        Db::getInstance()->Execute($sql);
    } else {
        $sql = "DELETE FROM "._DB_PREFIX_."myTable WHERE id_product=".(int)$id_product;
        Db::getInstance()->Execute($sql);
    }
} else {
    $sql = "INSERT INTO "._DB_PREFIX_."myTable (id_product,myFieldName) VALUES (".(int)$id_product.",'".psql($myFieldName)."')";
    Db::getInstance()->Execute($sql);
}