Written by on

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.

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 :

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:

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 :