To create a support ticket, start a search

Product Import: Importing a field in a table (insert and update)


Prerequisites

The field has to be present in the database

 

Target

We would like to import additional information onto a product from a CSV file to a field in a table. If the information already exists in a table, it will be updated. If the information does not exist yet, it will be created.

 

Setup

To add the field to the list of available fields to import, click on the 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 Product Class)

 

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 Combination Process and enter:

if ($switchObject == 'my_field' && !empty($newprod->id)) {    $sql = "SELECT *            FROM " . DB_PREFIX . "my_table            WHERE id_product=" . (int)$newprod->id;    $exist = Db::getInstance()->ExecuteS($sql);    if (!empty($exist[0]["id_product"])) {        $TODO[] = "UPDATE " . DB_PREFIX . "my_table                    SET " . $switchObject . "='" . pSQL($GLOBALS["import_value"], true) . "'                    WHERE id_product=" . (int)$newprod->id;    } else {        $TODO[] = "INSERT INTO " . DB_PREFIX . "my_table(id_product, " . $switchObject . ")                    VALUES ('" . (int)$newprod->id . "','" . pSQL($GLOBALS["import_value"], true) . "')";    } }

 

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.