The field has to be present in the database
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.
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 (in_array($switchObject, ['my_field'])) {
$id_prd = (!empty($id_product) ? (int)$id_product : (int)$newprod->id);
$sql = 'SELECT `id_product`
FROM `' . _DB_PREFIX_ . 'my_table`
WHERE `id_product` = ' . (int)$id_prd;
$exist = Db::getInstance()->getValue($sql);
if (!empty($exist)) {
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'my_table`
SET `' . $switchObject . '`= "' . pSQL($GLOBALS["import_value"], true) . '"
WHERE id_product=' . (int)$id_prd);
} else {
Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'my_table` (`id_product`, `' . $switchObject . '`)
VALUES ("' . (int)$id_prd . '","' . 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.