fbpx

Prestashop tutorial - Show the number of orders per customer

5 1 1 1 1 1 Rating 100%

It's very helpful if you can show the number of orders per customer on "Manage the Customers" page. In this tutorial, i will describe step by step how to show it ( Visit Customers -> Customers on Prestashop Backend Office page ).

Well, we only need to edit 1 file ( AdminCustomersController.php ) to get the data and show it. It's very easy.

How to show the number of orders per customer on Prestashop

Step I - Open AdminCustomersController.php file

As i say, we only need to edit AdminCustomersController.php file to get and show the information. Open it ( your-website/controllers/admin/AdminCustomersController.php ).

Find there line that defines what fields controller will get from database, it starts with $this->_select and place somewhere near 80 line. Add this code :

  (SELECT COUNT(*) FROM '._DB_PREFIX_.'orders o where o.valid =1 AND (o.id_customer = a.id_customer)) AS nb_of_orders
  

Here we get the data ( the number of orders per customer ). Look at this screenshot for more detail :

Get the data to show the number of orders per customer

Step II - Add code that will display our field

Our data is ready to be displayed. Find there line that starts with $this->fields_list - this is definition of what controller will display inside the list of customers. At the end please add code that will display our field from mysql query named nb_of_orders:

  'nb_of_orders' => array(
      'title' => $this->l('Total orders')
  ),
  

This is my file:

This code are used to show the number of orders per customer

Save your file and enjoy the change. I think "show the number of orders per customer" is a good idea for the Merchants. Does Prestashop 1.7 use it ? I don't know. Subscribe our Prestashop Tutorials page for Prestashop latest news.

P/s: This tutorial is working well with both Prestashop 1.5 and 1.6. Here is what we have on Prestashop 1.5 :

Show the number of orders per customer on Prestashop 1.5

PrestaSOO website uses cookies. By continuing to use this website, you are giving consent to cookies being used. More details… X