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.

Aktualizacja najnowszych modułów!

Age Restriction - 18+ ⊙
Rozwiąż niektóre problemy z wyświetlaniem na urządzeniach przenośnych.


Newsletter Popup v3.2.2
Edycja świąteczna, aby zwiększyć sprzedaż.


Trusty v1.4.7 ⊙
Kompatybilny zarówno z PrestaShop 1.7, jak i PrestaShop 8.

PrestaSOO team
Wszystko, czego potrzebujesz, aby zarabiać na życie wykonując pracę, którą kochasz.

Odkryć

To mądra inwestycja

Moduły PrestaShop, które stworzyliśmy jako pierwsze, aby rozwiązać problem naszego własnego biznesu - strona e-Commerce. Oznacza to, że są bardzo przydatne w poważnym biznesie. Jeśli cenisz swoją usługę internetową, te moduły są mądrą inwestycją.
Sarah Reeves, Programista aplikacji @ PrestaSOO
Wykonane z w Paris i Hanoi
PrestaSOO © 2024. Wszelkie prawa zastrzeżone. // Polityka prywatności Warunki usługi