Wednesday, May 2, 2012

Magento: Sort products by Created At filter

Many times, we want to sort products by the newest first and the oldest last. But in magento, there are only three sorting filters by default, i.e. Name, Price and Best Value.

So, to make products list sorted by Newest first, we need to override some core code of magento.

To do this, go to:
and copy List.php to [local] folder to override it.

Find the code of block:

$this->_productCollection = $layer->getProductCollection()

and replace it with:

$this->_productCollection = $layer->getProductCollection()->addAttributeToSort('created_at','DESC');

That's all.. Enjoy.. :)

Note: This method will work if you don't want to see dropdown of default sort filters, and just want to sort by newest products first.

If you also want to sort by default sort filters of Magento, i.e. Name, Price and Position, as well as add your custom filter to sort dropdown, then try with:

No comments: