Create a separate “On sale” product listing page Magento

Create a separate “On sale” product listing page Magento

This post provides the most effective way to create a separate “On sale” product listing page with the design which includes layered navigation and list toolbar too.

 

This is the common requirement on most of the magento stores and you may have spent lot of your time roaming around the internet for a working solution and I think you may not have found the way to achieve your requirement. Most of the tutorials gives the way to list the “On sale” products but that doesn’t include the layered navigation which looks little off design.

 

So don’t worry you have come to the right place. Below are the easy steps which you help you get the sale products on the product listing page.

Step 1: Create a category for on sale. Let’s name it “Specials”. Choose is anchor to “Yes”.

Step 2: Now after saving it. You can see the category id aside of category name.Note that category id we will use it later.

Step 3: Now copy /app/code/core/Mage/Catalog/Model/Layer.php to /app/code/local/Mage/Catalog/Model/Layer.php .Here we are overwriting the layer.php file.

Go to line# 97

 

Replace following function code

 

public function getProductCollection()

{

if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {

$collection = $this->_productCollections[$this->getCurrentCategory()->getId()];

} else {

$collection = $this->getCurrentCategory()->getProductCollection();

$this->prepareProductCollection($collection);

$this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;

}

return $collection;

}

 

with

public function getProductCollection()

{

if (isset($this->_productCollections[$this->getCurrentCategory()->getId()]))

{

$collection = $this->_productCollections[$this->getCurrentCategory()->getId()];

}

else

{

//21 is my category id replace it with your category id that you noted previously.

if($this->getCurrentCategory()->getId() == '21')

{

$collection = Mage::getResourceModel('catalog/product_collection');

$todayDate = date('m/d/y');

$tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y'));

$tomorrowDate = date('m/d/y', $tomorrow);


$collection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))

->addAttributeToFilter('special_to_date', array('or'=> array(

0 => array('date' => true, 'from' => $tomorrowDate),

1 => array('is' => new Zend_Db_Expr('null')))

), 'left');

$this->prepareProductCollection($collection);

$this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;

//custom code end

}

else

{


$collection = $this->getCurrentCategory()->getProductCollection();

$this->prepareProductCollection($collection);

$this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;

}

}

return $collection;

}

 

save it. And that’s all. you just need to change the category id according to your requirement.

 

That’s it.Now you can get the listing of products with only special price.

 

Happy Coding!!