Sort products by 2 attributes in magento catal

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/

One thought on “Sort products by 2 attributes in magento catal”

  1. 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……

Leave a Reply

Your email address will not be published. Required fields are marked *