Fixing the Magento price sort issue

Ian Hancock Stuff

During our recent work on a number of Magento websites we have uncovered (as many people have) the problem where Magento will not correctly sort the product searches by price. The scenario is this:

1. You do a search on your site for something, say “Glass TV Stands”

2. Magento returns a list of matching products in sorted by Relevance. You want to find the cheapest so you select ‘Price’ from the drop down and voila…

3. Nothing happens. At least nothing happens relting to the list being sorted by price.

Outcome: Sorting by price in Magento does not work!!

After  a number of days investigating this problem, my esteemed colleague, Roland has a fix. Now this fix may look fairly simple and inocuos but it took a lot of function searching and code trawling to find.

In the file:

Appcodecoremagecatalogmodelresourceeavmysql4productcollection.php line:1155

Change thus:

"{$entityCondition} AND {$storeCondition} AND {$groupCondition} AND {$attributeCondition}",
"{$entityCondition} AND {$storeCondition} AND {$attributeCondition}",
$this->getSelect()->order('_price_order_table.value ' . $dir);

And everything in the world is right again.

Feel free to comment on whether this fix has worked for you.