1

We are building an API for an app and want to order our products by popularity. Now is my question, how would I go about that? We are already loading products via /catalog/product (and it all works and stuff) but for some reason I can't see to be able to order the products on popularity. From what I understand from it, I have to join a different table to do this. Isn't there an easier way of doing this? Also, how does the default sorting behavior work? When I make a call without an orderBy, does it automatically order on position?

Another question to add: do you have tips on google-ing stuff like this? Often times Google comes up with answers who are not entirely related to my question or more frontend related.

2
  • What is "popularity" for your use case? Commented Jan 10, 2014 at 12:01
  • Depends, if there is a standard function for it, I'd use that. Something like most viewed or most ordered. Commented Jan 10, 2014 at 12:17

1 Answer 1

2

What is "popularity" for your use case? – Fabian Blechschmidt

Depends, if there is a standard function for it, I'd use that. Something like most viewed or most ordered. – Tim Wachter

For neither of the both exists a method and both are hard to calculate things, so the standard way is to order the products whatever you want them to be sorted, but be careful, if you have anchor categories, the sorting is a little bit weird - don't ask me how, never checked it, but there are plenty explanations on the web, just look for it.

The second idea is, to add a new attribute (I recommend to make it static, so it is added to the catalog_product_entity table, add an index on it, and then write into it whatever you want to sort it by, quantified by a number. Then you just need to add this attribute to be sortable and make it standard. For both the things here again, I don't know exactly how to do it (make it sortable/add it to the dropdown and where to hook in to make it the default order), but you might use the event catalog_product_collection_load_before in <frontend> to not affect the backend and grids.

1
  • Thanks for taking the time to read and comment! We will think about it some more, maybe we will just end up using the 'position' field. Thanks again! Commented Jan 10, 2014 at 12:49

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.