Add "New" product filter option in Product listing Magento


For this open the file Mage_Catalog_Model_Config and we need to make changes to the function getAttributeUsedForSortByArray().


public function getAttributeUsedForSortByArray()
   {
       $options = array(
           'position'  => Mage::helper('catalog')->__('Position'),
           'created_at'  => Mage::helper('catalog')->__('New')
       );
       foreach ($this->getAttributesUsedForSortBy() as $attribute) {
           /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
           $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
       }

       return $options;
   }

This will sort the product by it's created date.

You need to override this class to make the changes. For that you need to do following.
In your Module etc/config.xml you need to add following code.


<models>
            <catalog>
                <rewrite>
                    <config>Company_Test_Model_Config</config>
                </rewrite>
            </catalog>
</models>

and in your Model/Config.php


<?php
class Company_Test_Model_Config extends Mage_Catalog_Model_Config
{
   public function getAttributeUsedForSortByArray()
    {
        $options = array(
           'position'  => Mage::helper('catalog')->__('Position'),
           'created_at'  => Mage::helper('catalog')->__('New')
       );
       foreach ($this->getAttributesUsedForSortBy() as $attribute) {
           /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
           $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
       }

       return $options;
    }
}

Hit like or leave comment if post help!

2 comments: Click to see all comments

 

Copyright @ 2014 HK Magento Blog.