When I am in the listening product when I mark order alphabet by name I want to use two attributes. First my attribute, later name.

This is my structure name product: my_attribute name_product

I want to sort first by my_attribute when value my_attriute is the same I want to filter by name product.

I try to modify setCollection method in Mage_Catalog_Block_Product_List_Toolbar(later I create custom module) but this is no work. I tried $collection->setOrder('my_attribute, name', asc) not work. When in this function I dump ids product sort is ok, but somewhere this sort is overridden. Do you have any hints?


2 Answers 2


If you want to setOrder to collection using two attributes,You can use the below code

$collection->getSelect()->order(new Zend_Db_Expr('my_attribute ASC, name ASC'));

I think it will work perfectly.

Try and let me know, If it's works.


You can call setOrder() or getSelect()->order() multiple times, like

$collection->setOrder('my_attribute', Zend_Db_Select::SQL_ASC);
$collection->setOrder('name', Zend_Db_Select::SQL_ASC);

getSelect()->order(...) also accepts an array as parameter ...

$orderBy = array(
    'my_attribute ' . Zend_Db_Select::SQL_ASC,
    'name ' . Zend_Db_Select::SQL_ASC


... there is also a fallback to ascending order ...

$collection->getSelect()->order(array('my_attribute', 'name'));

Note: fallback for setOrder() depends on collection type, so better add direction there.

Your Answer

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

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