To create a support ticket, start a search

Product Export: Exporting a Language field in Product Class

Prerequisites

The field has to be present in the database and in a Product_lang class override

Target

We would like to export a field added to PrestaShop Product_lang class.

Setup

To add the field to the list of available fields to export, 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 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 Language and enter:

my_field

- select the menu Export Process and enter:

if (in_array($switchObject, array('my_field'))) {
    $field = $p->my_field;
}

Specific case

If the field is present in the database but the override has not been done in the Product class, it is still possible to retrieve its value by adding code that generates an SQL query rather than using the Product object.

if ($switchObject == 'my_field') {
    $field = '';
    $sql = "SELECT `".$switchObject."` FROM " . _DB_PREFIX_ . "product_lang
            WHERE id_product=" . (int)$id_product."
            AND id_lang=".(int)$getIDlangByISO[$f['lang']]."
            AND id_shop=".(int) $selected_shops_id;

        $field = (string)Db::getInstance()->getValue($sql);
}

You will need to adapt this code to your needs.

Exit the editing window.

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



Related articles