1

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?

  • try this product collection $collection = Mage::getModel('catalog/category')->load($categoryId) ->getProductCollection() ->addAttributeToSort('category', 'ASC'); – Magento 2 Nov 13 '15 at 9:17
  • I know I can sort custom product collection, however I need to sort the automated one retrieved on standard category view. So all the filters and pagination still works - but with custom sorting – Marrbacca Nov 13 '15 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.