To create a support ticket, start a search

Product Import: importing a language field in a table

Prerequisites

  • Store Commander version 2015-07-01
  • SC Grids Editor Pro Add-on - version 1.2
  • The field has to be present in the database

 

Target

We would like to import a language field in a table, language that will be selected in the import mapping beforehand.

 

Setup

  • To add the field to the list of available fields to import, click on the add.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 (right hanside) > Import Combinations Process, add the following

 

if ($switchObject=='my_field' && $GLOBALS['import_value']!='')
{
$value = $GLOBALS['import_value'];
$id_lang = intval($getIDlangByISO[$mappingData['CSV2DBOptions'][$firstLineData[$key]]]);
if(!empty($id_lang))
{
$sql="SELECT * FROM "._DB_PREFIX_."mytable_lang WHERE id_product='".intval($id_product)."' AND id_lang = ".intval($id_lang);
$lang_row = Db::getInstance()->ExecuteS($sql);
if(!empty($lang_row[0]["id_product"]))
{
$TODO[]="UPDATE "._DB_PREFIX_."mytable_lang SET my_field='".psql($value)."' WHERE id_product='".intval($id_product)."' AND id_lang = ".intval($id_lang);
}
else
{
$TODO[]="INSERT INTO "._DB_PREFIX_."mytable_lang (id_product, id_lang, my_field)
VALUES ('".intval($id_product)."','".intval($id_lang)."','".psql($value)."')";
}
}
}

 

IMPORTANT NOTE: for tables product_lang product_attribute_lang, do not add the following to the above:

else
{
$TODO[]="INSERT INTO "._DB_PREFIX_."mytable_lang (id_product, id_lang, my_field)
VALUES ('".intval($id_product)."','".intval($id_lang)."','".psql($value)."')";
}
 

  • From the Advanced Properties panel (right hanside) > selected language, add the field name (separated by a comma if you need to add multiple fields)

          Example: last_field,my_field

 

You will need to adapt this code to your needs.

 

  • Exit the editing window and you can use the field in your import mapping