How can I sort catalogsearch results by 2 attributes instead of "position" or "relevance" only?
Not in toolbar, need to sort by default .. for example, first sort products with "attribute1" and then sort with "attribute2" without changing the toolbar and select any of them?
for more info, I have 4 products:
- 121/24R
- 123/83C
- 123/15H
- 121/55H
I have 2 attributes that first is for 123,121 and another one is for 24,83,15,55
Now I want to sort products results with first attribute in 'asc' and another one in 'desc'?
like this :
- 121/55H
- 121/24R
- 123/83H
- 123/15C
How can I use this method ?
Best Answer
First, create an extension (in my example it's called Emzee_Sorter) and listen to the event
catalog_block_product_list_collection
in yourconfig.xml
:Then create the observer class:
sort_2
is the attribute containing55H
and so on. Make sure that you setUsed in Product Listing
toYes
for this attribute so that the attribute can be found when flat catalog is enabled.This code will sort the products on search results and category pages. If you want to limit the functionality to search results, you can do something like this: