Sort products by 2 attributes in magento catal

On my magento website, we have a requirement to sort the product lists by 2 attributes: "Manufacturer", "Name", and then return to the "Unique" and "Object ID" attributes by default.

It seems like magento allows you to order only 1 and then entity_id. I do not mind if necessary, if necessary.

Looking back at a few people, there is a problem, but no one seems to be giving an answer, so I thought that I would give it back (the first question also had to be tough :)).

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

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

+4
source share
1 answer

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

The setOrder () method takes an array.

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

I'm not sure how anyone will want to use this, but I changed this line in Toolbar.php in the Catalog / Product / List / directory.

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

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

+3
source

Source: https://habr.com/ru/post/1338458/


All Articles