cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting product collection on category view

Sorting product collection on category view

Hi,

I'm trying to set custom sort for product collection on category view and I'm hitting wall.

I tried simple observer for event: 

catalog_block_product_list_collection

with  

$collection = $observer->getCollection();
$collection->getSelect()->join(array('options_sort' => 'eav_attribute_option'), 'e.course = options_sort.option_id', array('sort_order' => 'sort_order'));

$collection->getSelect()->reset(Zend_Db_Select::ORDER);
$collection->getSelect()->order('sort_order', 'ASC');

This solution works, when I print the collection query on list.phtml I can see that sorting order was changed, however products are still displaying in the wrong order...

 

I have also fiddled with layout updates and ended up with something like:

<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
<action method="setSortBy"><value>sort_order</value></action>
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<action method="addOrderToAvailableOrders"><order>sort_order</order><value>Sort order</value></action>
<action method="setDefaultOrder"><field>sort_order</field></action>
</block>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>

however it's also not working.

Have anyone knows the answer?