To create a support ticket, start a search

Combinations Grid: Adding field 'disabled'


Prerequisites

Store Commander version 2014-03-12 minimum
Grids Editor Pro version: 1.0 minimum
The field need to exist in the database


Target

We would like to include the field 'Used' from the Enable/Disable combination Module
 

Setup

  • To add the field to the list of available fields for the combinations panel, click on the  icon and enter the following information:

           What is the field ID? used
 

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


            ID: used
            ​Field name: Disabled
            Table: None
            Type: Multiple choice
 

  • From the Advanced Properties panel: 

           
           List of choice

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


           

           SQL Select

return ', IF( (SELECT COUNT(tsad.id_tot_switch_attribute_disabled) 
                FROM pre9680_tot_switch_attribute_disabled tsad 
                WHERE tsad.id_product_attribute=pa.id_product_attribute)>0, 1, 0 ) as used ';


           

          PHP definition

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


            

          PHP onAfterUpdateSQL

if (isset($_POST['used'])) {
    $sql = "SELECT * FROM pre9680_tot_switch_attribute_disabled WHERE id_product_attribute=" . (int)$id_product_attribute;
    $exist = Db::getInstance()->ExecuteS($sql);
    $used = (int)$_POST['used'];
    if (count($exist) > 0 && empty($used)) {
        $sql = "DELETE FROM pre9680_tot_switch_attribute_disabled WHERE id_product_attribute=" . (int)$id_product_attribute;
        Db::getInstance()->Execute($sql);
    } elseif (count($exist) <= 0 && !empty($used)) {
        $sql = "INSERT INTO pre9680_tot_switch_attribute_disabled (id_product_attribute,id_shop) VALUES (" . (int)$id_product_attribute . ",'1')";
        Db::getInstance()->Execute($sql);
    }
}

 

  • Exist the window and you can then add the field to the combinations panel:

 


To add this field to SC Import
 

  • Once you have selected Catalog > Import Products: click on  and enter the following information:
     

            ID: used
            Name: _combination - used
         

  • In the Advanced Properites panel: After import process


                        

if ($switchObject=='used') {
    $sql = "SELECT * FROM pre9680_tot_switch_attribute_disabled WHERE id_product_attribute=" . (int)$id_product_attribute;
    $exist = Db::getInstance()->ExecuteS($sql);
    $used = (int)$value;
    if (count($exist) > 0 && !empty($used)) {
        if (!empty($used)) {
            $sql = "DELETE FROM pre9680_tot_switch_attribute_disabled WHERE id_product_attribute=" . (int)$id_product_attribute;
            Db::getInstance()->Execute($sql);
        }
    } elseif (count($exist) <= 0 && empty($used)) {
        $sql = "INSERT INTO pre9680_tot_switch_attribute_disabled (id_product_attribute,id_shop) VALUES (" . (int)$id_product_attribute . ",'1')";
        Db::getInstance()->Execute($sql);
    }
}

 


To add this field to SC Export

  • Once you have selected Catalog > Export Products: click on  and enter the following information:

            ID: used
            Name: _combination - used
 

  • In the Advanced Properties panel: Combinations fields
if (in_array($switchObject, array('used'))) {
    $field = 0;
    $sql = "SELECT * FROM pre9680_tot_switch_attribute_disabled WHERE id_product_attribute=" . (int)$id_product_attribute;
    $exist = Db::getInstance()->ExecuteS($sql);
    if (count($res) > 0) {
        $field = 1;
    }
}