Apr 25, 2013

Magento Special price products page

Magento special price products page. We will be creating a new CMS page that will display all the Special or Sale products. We can make a product as a Special by filling it’s “Special From” and “Special To” price in “Prices” tab in Manage Products individual screen.

So let’s first create CMS Page, by going to CMS > Pages, which we will name it as “Specials”. In the Content tab of that Page, paste the below line of code:

{{block type="catalog/product_special" template="catalog/product/list.phtml" column_count="3" num_products="0"}}

and save the page.

– Here we are saying Magento to display Product List template by looking at our new block type file, Catalog/Product/Block/Special.php. So let’s create this file, Special.php in local/Mage/Catalog/Product/Block/ directory. You will have to create this directory path if it’s not already there.

class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_List
    protected function _getProductCollection()
        if (is_null($this->_productCollection)) {
            $categoryID = $this->getCategoryId();
              $category = new Mage_Catalog_Model_Category();
              $category->load($categoryID); // this is category id
              $collection = $category->getProductCollection();
            } else
              $collection = Mage::getResourceModel('catalog/product_collection');
            $todayDate = date('m/d/y');
            $tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y'));
            $tomorrowDate = date('m/d/y', $tomorrow);
            $collection->addAttributeToSort('created_at', 'desc');
            $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');
            $numProducts = $this->getNumProducts() ? $this->getNumProducts() : 0;
            $collection->setPage(1, $numProducts)->load();
            $this->_productCollection = $collection;
        return $this->_productCollection;


  • Hi there,

    Thanks for the tutorial – I’m developing a Magento site however when I enter the code you’ve mentioned I receive an exception of “exception ‘Mage_Core_Exception’ with message ‘Invalid block type: Mage_Catalog_Block_Product_Special'” and the page dies halfway through loading. Do you have any suggestions please?

    Many thanks, Chris

    • I hope you have created the file Special.php at “app/code/local/Mage/Catalog/Block/Product/” and pasted the content of the file I provided in the post. If the file is in place, then you should not get this error.

  • Hi Sir,

    I want to hide all products which have special price(ie if product contain special price it should be hidden from listing page),
    i have tried with layer.php as well as list.php but i haven’t find solution please help me out .
    how should hide all the products which which have special prices as null
    i have also tried to addAttributetofilter but haven’t find solution.

    Please Reply as soon as possible.

    • Hi. In products list.phtml file, filter $_productCollection with special_price equal to null. Something like

      $_productCollection->addAttributeToFilter('special_price', array('null'=>true));
  • Hi,
    Thanks for this post.It really helps a lot.
    Can you tell me how can i add left panel filters like on normal category page to this special product page.

  • Hi

    What about if I am using Magento enterprise, dose the same code apply or i need to do some changes to the codes.

    • Yes it should apply, although I have not checked it. Check it in your local and if it works, then move it to production.

  • Just tried following you great tutorial, but i just get a blank CMS page when loading it 🙁

    Placed the code in the 2 places mentioned

    I think the problem is the folder structure

    I had to create the folders “Mage” –> “Catalog” –> “Product” –> “Block” so I could place the Special.php

    Shouldn’t the folder structure be there already? http://screencast.com/t/ZrDOE4I3

    • Hi Allan, the file/folder structure should be Mage -> Catalog -> Block -> Product -> Special.php
      The folder structure will not there already, as we are doing it in local codepool.
      Check all the steps are done correctly, it should work.

  • Changed the structure: http://screencast.com/t/r3Byd0hcF

    CMS page looks like this: http://screencast.com/t/SwRR4VKt2DzO

    Still no special products shows up 🙁

    • Hi Allan, I know this is very late reply but I just came across this page and checked your screenshots again to know why it was not working for you. The issue was, the double quotes were not in correct format. This usually happens if you copy-paste the code, and as double quotes are easily missed to get noticed.

      Hope this will help someone with such kind of issue.

  • Hi,
    how to limit the number of displayed products?
    how to use buttons to sort the product?
    Allan try turn off compilation.

  • Hi, thank you for this code, it is working great on Magento

  • My friend I used your code and it works fine but I have problems with the template, it shows in disorder the products… can we use layered navigation? 🙂 Thanks for your help

  • Is it compulsary to create a page with name “Specials”. Can I call block code in other cms page?

  • Thank you for this code.. Worked well… Thanks a lot

  • it works for me. thanks for a great tutorial Kalpesh.

  • Many thanks Kalpesh .

  • Thank you for post, I have import this code , but CMS page blank, Please help me…

Leave a comment


Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!




Magento top 50 contributors

Magento top 50 contributors