Best Sellers in Prestashop

Best Sellers in Prestashop

Prestashop Top Sellers feature offers a great possibility of alleviating customers’ need to wander around your store looking for perfect items. They all will be displayed in an automatically created list in the best sellers section as well as on the main page. How does Prestashop create this list and how the stats for the best sales can be viewed? Find the info in our article.

There is a special controller which is responsible for generating the Best Sellers page: controllers/front/BestSalesController.php.  This controller implements only 2 methods: initContent and setMedia and it is inherited from the FrontController class. Let’s take a look at each of them:


A special place in this controller is hold by the method ProductSale::getBestSales, which outputs the list of the most frequetly purchased items. It is worth noting that if you need to get the information about product sales rates it is better first to check the methods of this class. It is possible that the information you need can be obtained via the standard methods of the class PrоduсtSаle.  I will only briefly list and describe these methods, as for their implementation you can see it in this file:  classes/ProductSale.php.

  • ProductSale::fillProductSales() – Fill the product_sale SQL table with data from order_detail
  • ProductSale::getNbSales – Get number of actives products sold
  • ProductSale::getBestSales ($id_lang, $page_number = 0, $nb_products = 10, $order_by = null, $order_way = null) – Get required informations on best sales products
  • ProductSale::getBestSalesLight($id_lang, $page_number = 0, $nb_products = 10, Context $context = null) – Get required informations on best sales products
  • ProductSale::addProductSale($product_id, $qty = 1) – input data into the table product_sale
  • ProductSale::getNbrSales($id_product) – returns the number of sales per specific product
  • ProductSale::removeProductSale($id_product, $qty = 1) – this function is opposite to addProductSale, it removes the parameter qty from the data in the field Quantity of the table product_sale

To finish with this controller we need to see what is inside the best-sales.tpl template:

The content of the template shows that this is just a compilation of other templates, which we saw on the catalog page. Such an approach makes the markup of the page much easier: you just need to properly markup the Category template.

Finally, I would like to mention the possibility of viewing statistics for the best sales. All you need is to activate the standard Best Selling Products module from the Analytics and Stats section.


  1. Great post Alex. Do you know how to modify the number of best sellers showing up. Ie, from 5 items to 10 items in the sidebar. Thanks in advance!

  2. Carlos,

    For bestsellers is responsible the function ‘ProductSale::getBestSales($id_lang, $page_number = 0, $nb_products = 10, $order_by = null, $order_way = null’. Perhaps you mean the number of products displayed on a page. In this case you need to change the transmitted parameter ‘$nb_products’

  3. Скажите как можно сделать отображение продуктов
    за последние 10 дней или за 30 дней

  4. nik,

    Имеются в виду бестселлеры за последние несколько дней? В этом случае нужно изменять поведение метода ProductSale::getBestSales

  5. Sham,

    They are shown when there are orders with invoices for those products. You need to check the class ProductSale to better understand this process.

  6. Hi,
    Presta by default gets all the products that have minimum 1 sale. How we can just get the first 10 or 20 products with the best sales ?

    Nice article

  7. Thanos,

    You need to change the parameter that is transmitted in MYSQL: LIMIT. Unfortunately, I cannot say now where exactly you should do this, because I do not quite understand what block you refer to. So, please, provide more details.

  8. Александр, очень долго искал подобную статью.
    Если возможно, подскажите, как можно было бы добавить ярлык “Топ продаж” на странице товара на его картинке.

    Собственно говоря, интересует, как находясь на странице товара, можно определить, что он относится к “Топ продаж”?

  9. Здравствуйте Юрий,

    Сразу готового метода нету, но его можно создать. Для этого нужно расширить класс ProductSale с методом
    public static function isBestSale($id_product) {
    return (bool) Db::getInstance()->getValue(‘SELECT id_product FROM '.DB_PREFIX.'product_sale WHERE id_product = ‘ . (int)$id_product);

    и в шаблоне вызывать эту функцию

  10. hi alex, thanks for the post. i have a question and if you are busy then it is no problem. i have PS here . when i click “best sellers” , sale, new labels are missing. price, discount price and discount amount are also missing. do you know how to address this? thanks alex have a nice day, trev

  11. hi Alex

    how do i show best sale products in a month? bcz its showing old dated sales like fifa 15 game :D, best sales is not helping more for do advertisement.

Post a new comment