To create a support ticket, start a search

Product Export: exporting number of products 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_ventes'))) {
    $sql = 'SELECT SUM(od.product_quantity) AS nb_ventes
            FROM `' . _DB_PREFIX_ . 'order_detail` od
            RIGHT JOIN `' . _DB_PREFIX_ . 'orders` o ON (od.id_order = o.id_order)
            WHERE od.product_id = ' . (int)$p->id . ' 
            AND o.valid = 1 
            AND o.date_add >= "2020-04-01 00:00:00" AND o.date_add <= "2021-10-31 23:59:59"';
    $field = (int)Db::getInstance()->getValue($sql);
}

 

Exit the editing window.

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

 




Related articles