To create a support ticket, start a search

Combinations Grid: Adding field 'disabled'


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 choices
 

From the Advanced Properties panel on the right handside:

- select the menu List of choices and enter:

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

           

- select the menu SQLSelect and enter:

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 ';


- select the menu PHP definition and enter:​

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


            
- select the menu PHP onAfterUpdateSQL and enter:​                            

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);
    }
}

 

Exit the editing window.

The new field is now present in the list of available fields and you can add it to your combination grid.

 


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
         

From the Advanced Properties panel on the right handside:

- select the menu After import process and enter:

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
 

From the Advanced Properties panel on the right handside:

- select the menu Combinations fields and enter:                   

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;
    }
}