To create a support ticket, start a search

Export Products: Add a 'yes/no declination' field

Target

We would like to export number of sales on a specific period (1 year)

 

Setup

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

What is the field ID?: nb_sale_1_year (has to correspond exactly to the field name in Product Class)

 

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

ID: nb_sale_1_year
Name: nb_sale_1_year

 

From the Advanced Properties panel on the right handside:

- select the menu Export Process and enter:

if (in_array($switchObject, array('nb_sale_1_year'))) {
    $field = 0;
    $sql = "SELECT SUM(od.product_quantity) AS nb
    FROM `"._DB_PREFIX_."order_detail` od
    INNER JOIN `"._DB_PREFIX_."orders` o ON (od.id_order = o.id_order)
    WHERE od.product_id = '".(int)$p->id."'
    ".(!empty($id_product_attribute)?" AND od.product_attribute_id='".(int)$id_product_attribute."' ":"")."
    AND o.valid=1
    AND o.date_add >= (SELECT DATE_ADD('".date("Y-m-d")." 00:00:00', INTERVAL -1 YEAR))";
    $res = Db::getInstance()->getValue($sql);
    if (!empty($res)) {
        $field = (int)$res;
    }
}

 

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