Prestashop tutorial - Show the number of orders per customer

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

Get this Advanced Cart Rules module

New module.

Xleft module

Xleft shows customers how much more they need to spend to get free shipping in real time.

Latest modules update!

ChargeMe v5.4.1 ⊙
Clear the cart & redirect to the checkout page.


Age Restriction - 18+ v2.3.4⊙
Fix the Smarty issues.


Newsletter Popup v3.2.4 ⊙
Fixed the duplicate coupon codes issue.


Trusty v1.4.7 ⊙
Compatible with both PrestaShop 1.7 & PrestaShop 8.

PrestaSOO team
Everything you need to make a living doing work you love.

Discover

It is a wise investment

PrestaShop modules we created first to solve the problem of our own business - an e-Commerce site. That means they are very useful for serious business. If you value your web property, these modules are a wise investment.
Sarah Reeves, App Developer @ PrestaSOO
Made with in Paris & Hanoi
PrestaSOO © 2024. All rights reserved. // Privacy Policy Terms of Service