To create a support ticket, start a search

Product Import: Importing a product combination


Prerequisites

The field has to be present in the database, in ps_product and ps_product_attribute tables

 

Target

We would like to import information (numerical value) onto a product from a CSV file.

If the product does not use combinations, ps_product field will be updated.

If the product uses combinations, the value on the base product will be set to 0 and the corresponding combination will be updated.

 

Setup

To add the field to the list of available fields to import, click on the add_dis.png in the 'Add a field' panel and enter the following information:

What is the field ID?: my_field (has to correspond exactly to the field name in the table)

 

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

ID: my_field
Name: my_field

 

From the Advanced Properties panel on the right handside:

- select the menu Import Process and enter:

if ($switchObject == 'my_field' && $GLOBALS['import_value'] != '') {
    $id_prd = (!empty($id_product) ? (int)$id_product : (int)$newprod->id);
    $TODO[] = "UPDATE " . _DB_PREFIX_ . "product 
                SET `" . $switchObject . "`='" . importConv2Float($GLOBALS['import_value']) . "' 
                WHERE id_product=" . (int)$id_prd;
}

 

- select the menu Import Combinations Process and enter:

if ($switchObject == 'my_field' && isCombinationWithID() && $GLOBALS['import_value'] != '') {
    $id_prd = (!empty($id_product) ? (int)$id_product : (int)$newprod->id);
    $TODO[] = "UPDATE " . _DB_PREFIX_ . "product SET `".$switchObject."`=0 WHERE id_product=" . (int)$id_prd;
    $TODO[] = "UPDATE " . _DB_PREFIX_ . "product_attribute SET `".$switchObject."`='" . importConv2Float($GLOBALS['import_value']) . "' WHERE id_product_attribute=" . (int)$id_product_attribute;
}

 

You will need to adapt this code to your needs.

 

Exit the editing window.

The new field can now be included in your import mapping.

 




Related articles