Sort products by 2 attributes in magento
In magento site suppose you have the requirement to sort the product listings by 2 attributes like "in stock" and "popularity"
After some research, it seems to work.
Use the following code given below:
<?php
$Collection->setOrder(array('attribute1', 'attribute2'), asc); //the setOrder() method accepts an array.
?>
Modified this line in Toolbar.php in the Catalogue/Product/List/ directory.
<?php
if ($this->getCurrentOrder())
{
$this->_collection->setOrder(array($this->getCurrentOrder(), 'in stock'), $this->getCurrentDirection());
}
?>
Hope this will work!
In magento site suppose you have the requirement to sort the product listings by 2 attributes like "in stock" and "popularity"
After some research, it seems to work.
Use the following code given below:
<?php
$Collection->setOrder(array('attribute1', 'attribute2'), asc); //the setOrder() method accepts an array.
?>
Modified this line in Toolbar.php in the Catalogue/Product/List/ directory.
<?php
if ($this->getCurrentOrder())
{
$this->_collection->setOrder(array($this->getCurrentOrder(), 'in stock'), $this->getCurrentDirection());
}
?>
Hope this will work!