Get Free Audit

Best Sellers in Prestashop

May 29, 2013

4086 Alex Simonchik

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:

Andrey_Dubina
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Andrey


1

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.

Need a dedicated PrestaShop development team to grow your online store? Contact BelVG to move your business forward.

Andrey Dubina
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Andrey

16 Comments

  1. Hi, Peter

    An answer to this question will not fit into a comment. Please contact our support.

  2. Hi,
    I know this is an old post but as Matt above I wonder how I can take best sellers for the last month? I have had a shop since 2014 and we had a great sell for one product during 2015, this product is still in top on our best seller list but we haven’t sold a single one of this product during 2018. This is a big problem for us, we want to show the best sellers during 2018 not the 2015 best sellers.

  3. 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.

  4. hi alex, thanks for the post. i have a question and if you are busy then it is no problem. i have PS here vouchoff.com/shop . 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

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

    Сразу готового метода нету, но его можно создать. Для этого нужно расширить класс 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);
    }

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

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

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

  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. 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
    Thanks

  9. 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.

  10. nik,

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

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

  12. 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’

  13. 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!

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *