Sort products by 2 attributes in magento catal

3.7k Views Asked by At

On my magento site we have the requirement to sort the product listings by 2 attributes, 'Manufacturer', 'Name' and then falling back to the Unique and default attribute 'Entity ID'.

Seems magento only lets you order by 1 then entity_id. I dont mind having to do this in a hacky way if required.

Looking around a few people have the problem but no one seems to offer an answer so thought I'd give this ago ( First question too, had to be a toughie :) ).

http://www.magentocommerce.com/boards/viewthread/7314/

http://www.magentocommerce.com/boards/viewthread/206869/

1

There are 1 best solutions below

0
On

After some research ( I'm not a php developer =/ ), the following seems to work:

The setOrder() method accepts an array.

$Collection->setOrder(array('attribute1', 'attribute2'), asc);

I'm not sure how anyone would want to use this but I modified this line in Toolbar.php in the Catalogue/Product/List/ directory.

 if ($this->getCurrentOrder()) {
      $this->_collection->setOrder(array($this->getCurrentOrder(), 'name'), $this->getCurrentDirection());
 }

So all my collections are sorted by the current order ( default order ) and then hardcoded to order by name afterwards. Still doing some testing on it but seems to work......