Magento has only 3 pre-defined sort methods for catalog products list, namely by Position, Name, and Price. It’s not unusual that the customers or catalog editors would want to sort the products by creation date so that the newest products are displayed at the forefront. We will make this happen in this article.
Step 1
Find file /app/code/core/Mage/Catalog/Model/Config.php and copy it to /app/code/local/Mage/Catalog/Model/Config.php. Open the copied file (open it still if it already exists before the copy) and find this function.
Add the bolded line:
public function getAttributeUsedForSortByArray()
{
$options = array(
'position' => Mage::helper('catalog')->__('Position'),
// This line that adds the 'Date' option to the Sort By dropdown methods.
'created_at' => Mage::helper('catalog')->__('Date')
);
foreach ($this->getAttributesUsedForSortBy() as $attribute) {
/* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
$options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
}
return $options;
}
Step 2
Create and upload this file /app/etc/modules/SortByDate_Catalog.xml
<?xml version="1.0"?>
<config>
<modules>
<SortByDate_Catalog>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Catalog />
</depends>
</SortByDate_Catalog>
</modules>
</config>
Step 3
Create and upload this file /app/code/local/SortByDate/Catalog/etc/config.xml
<?xml version="1.0"?>
<config>
<global>
<models>
<catalog>
<rewrite>
<config>SortByDate_Catalog_Model_Config</config>
</rewrite>
</catalog>
</models>
</global>
Step 4
Create and upload this file /app/code/local/SortByDate/Catalog/Model/Config.php
<?php
class SortByDate_Catalog_Model_Config extends Mage_Catalog_Model_Config {
public function getAttributeUsedForSortByArray()
{
$options = parent::getAttributeUsedForSortByArray();
if (!isset($options['created_at'])) {
$options['created_at'] = Mage::helper('catalog')->__('Date');
}
return $options;
}
}
That’s it.
Now refresh your category pages and you would see an additional sort method ‘Date’ in the ‘Sort By’ dropdown list and selecting it would make the catalog display the items by creation date. Clicking the small arrow to the right would toggle between descending order and ascending order.





