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: Another table
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 '._DB_PREFIX_.'tot_switch_attribute_disabled tsad 
                WHERE tsad.id_product_attribute=pa.id_product_attribute AND id_shop='.SCI::getSelectedShop().')>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'])) {
    $id_shop = SCI::getSelectedShop();
    $sql = "SELECT id_product_attribute FROM " . _DB_PREFIX_ . "tot_switch_attribute_disabled WHERE id_product_attribute=" . (int)$id_product_attribute . " AND id_shop=" . (int)$id_shop;
    $exist = Db::getInstance()->getValue($sql);
    $used = (int)$_POST['used'];
    if ($exist && empty($used)) {
        $sql = "DELETE FROM " . _DB_PREFIX_ . "tot_switch_attribute_disabled WHERE id_product_attribute=" . (int)$id_product_attribute . " AND id_shop=" . (int)$id_shop;
        Db::getInstance()->Execute($sql);
    } elseif (!$exist && !empty($used)) {
        $sql = "INSERT INTO " . _DB_PREFIX_ . "tot_switch_attribute_disabled (id_product_attribute,id_shop) VALUES (" . (int)$id_product_attribute . "," . (int)$id_shop . ")";
        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 id_product_attribute FROM " . _DB_PREFIX_ . "tot_switch_attribute_disabled WHERE id_product_attribute=" . (int)$id_product_attribute . " AND id_shop=" . (int)$id_shop;
    $exist = Db::getInstance()->getValue($sql);
    $used = (int)$value;
    if ($exist && empty($used)) {
        $sql = "DELETE FROM " . _DB_PREFIX_ . "tot_switch_attribute_disabled WHERE id_product_attribute=" . (int)$id_product_attribute . " AND id_shop=" . (int)$id_shop;
        Db::getInstance()->Execute($sql);
    } elseif (!$exist && !empty($used)) {
        $sql = "INSERT INTO " . _DB_PREFIX_ . "tot_switch_attribute_disabled (id_product_attribute,id_shop) VALUES (" . (int)$id_product_attribute . "," . (int)$id_shop . ")";
        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 "._DB_PREFIX_."tot_switch_attribute_disabled WHERE id_product_attribute=" . (int)$id_product_attribute." AND id_shop=".(int)$selected_shops_id;
    $exist = Db::getInstance()->ExecuteS($sql);
    if (count($res) > 0) {
        $field = 1;
    }
}

 




Related articles