To create a support ticket, start a search

Combinations Export: exporting number of combinations sold


Target

We would like to export the quantity of products sold for a specific period of time.

 

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_sales

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

ID: nb_sales
Name: _NB_sales

 

Here we're exporting the quantity sold for the period 2020-04-01 to 2020-10-31

From the Advanced Properties panel on the right handside:

- select the menu Export Process and enter:

if (in_array($switchObject, array('nb_sales'))) {
    $field = "0";
    $sql = 'SELECT SUM(od.product_quantity) AS nb_sales
            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.'" IF('.(int)$id_product_attribute.'>0, AND od.product_attribute_id = '.(int)$id_product_attribute.',"")
            AND o.valid=1
            AND o.date_add >= "2020-04-01 00:00:00" AND o.date_add <= "2020-10-31 23:59:59"
            LIMIT 1';
    $res = Db::getInstance()->ExecuteS($sql);
    if (!empty($res[0]['nb_sales'])) {
        $field = (int)$res[0]['nb_sales'];
    }
}

 

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.