In Magento 2, suppose we sort by price with DESC order in payload then they sort products by variant's lowest price and that lowest price will be in descending order of all other product's variant price.

Suppose I have 2 configurable products A and B.

A have variants whose prices are 10,20,30,40 B have variants whose prices are 15,20,25,30

It will show correct sorting for Low to High. But for High to low sorting, they should sort like A then B because A has the highest value of 40

But currently, it is showing sort B then A because Magento choose the lowest value of the product which is 15 for B and 10 for A, so they sort B then A

Please suggest me way to fix it.

Thank you, Vijay Gupta

1 Answer 1

  1. Sorting by price should work perfectly for any kind of products if you have Price Attribute chosen if Available Sort Options (on Category edit page) and if you have Price Index built well.

Just try to add "?dir=desc&order=price" to your category URL and see if it will change sorting

  1. But if you would like to apply your custom sorting anyway - you can use the Observer method, which is described here

  2. But, the call for "loadByAttribute" for all products in the collection is very heavy. Instead of it you need to use next code:

$products = $observer->getCollection();



->order('price_index.final_price', 'asc');

Your Answer

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

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