2

I am trying to implement Best seller sort by in category list page.

Followed below link, but that is not working in Magento 2.3.4.

Magento 2 add Sort By Best Sellers Option on category products litsing page

Any suggestions how this can be achieved? the above solution having problem with page load. That is taking more than 20mins to load.

Also it has other problem, collection is not filtering and showing the Best seller items in list page.

Please someone suggest me how can we get Best seller option in sort By in list and search result page. Thanks in Advance!!

2 Answers 2

1
+100

I have written a solution that involves an additional product attribute called 'Best Sellers'. This attribute is auto-created by the module.

Each time an order is made for a product (If a configurable product is added, it is the parent product that is accounted with the sale), the product attribute 'best sellers' value is increased. (the quantity is not taken into account in my implementation) Then, this solution reads the number of sales on the fly rather than using a cron.

it is a solution I have used already in production in the past but I have rewritten it today to use the Magento 2 best principles I know of.

https://bitbucket.org/magstaging/bestseller/src/master/

1

I suggest try another approach that I did in a Magento 1 store: instead of try rewrite how the resource/collection is assembled, create a new attribute in native way for best seller (save the qty of purchases) and create an extension with a cron to populate the data in this field.

Using this way the core feature of sort of Magento will works as expected in any scenario. Of course it won't be in real time. In my case with Magento 1 I did a cron that update best seller attribute in the products every day at midnight.

So a quick list with the steps for you:

  1. Create the extension with a crontab job.
  2. Create the attribute to storage the quantity of sales for products (you can created it inside the admin panel if you want). Make sure to make it usable to sort and set this attribute to default sort attribute in Magento admin.
  3. Create a model with a function to get the sales order items created since last execution (last 24h) and update the product's bestseller attribute increasing the number.
  4. Do a customization to change the default direction of sort because you want the bigger number first (DESC direction). This link can help you: https://www.customerparadigm.com/changing-default-product-sorting-in-magento-2/

Also in github there are some extensions for get it, but I never tested in Magento 2:

In the end there is a third way to try it: Instead of create a cron to fill the attribute for qty of purchases, you can create an event to increment the attribute after place each order. But I don't like this way because can impact the time to place an order.

3
  • hi @Denis, Thanks for the suggestion, I tried 1 and 3 links, both are not working in Magento 2.3.4, the 2nd link is not useful for my requirement' May 21, 2020 at 15:56
  • @jafarpinjar I don’t think use any of them are good idea at all. I really believe that create your own extension using the steps that I answered is a good approach. May 21, 2020 at 16:05
  • hi@Denis, will be very helpful, if you can update me the code, I have created a module with as per the suggestion from previous answer, pls try to update me if you can May 21, 2020 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.