Saturday, February 18, 2012

Magento : Special product Page

Magento : Special product Page

For showing special products(products which have special price) in a cms page ,
follow the below steps:

1) Create a file   "/app/code/local/Mage/Catalog/Block/Product/Special.php "
     with following contents:




     <?php
if(version_compare(Mage::getVersion(), '1.4.0.0', '>=') || version_compare(Mage::getVersion(), '1.6.0.0', '<=')){
//Code
class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_List
{
   function get_prod_count()
   {
      //unset any saved limits
      Mage::getSingleton('catalog/session')->unsLimitPage();
      return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 12;
   }// get_prod_count

   function get_cur_page()
   {
      return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;
   }// get_cur_page

   /**
    * Retrieve loaded category collection
    *
    * @return Mage_Eav_Model_Entity_Collection_Abstract
   **/
   protected function _getProductCollection()
   {
      $todayDate = date('m/d/y');
      $tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y'));
      $tomorrowDate = date('m/d/y', $tomorrow);


            
        $collection = Mage::getResourceModel('catalogsearch/advanced_collection')
            ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->addMinimalPrice()
            ->addStoreFilter();
       
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
       
        $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->setProductCollection($collection);

      return $collection;
   }// _getProductCollection
}// Mage_Catalog_Block_Product_Special
}


2)  Create a CMS page "SPECIAL" by going to
Magento -> Admin ->CMS -> Pages

3)  In the above CMS page
Go to Design-> Layout Update XML
and
Paste



<reference name="content">
   <block type="catalog/product_special" name="product_new" template="catalog/product/list.phtml">
      <action method="setCategoryId"><category_id>10</category_id></action>
      <action method="setColumnCount"><column_count>6</column_count></action>
      <action method="setProductsCount"><count>0</count></action>
      <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
         <block type="page/html_pager" name="product_list_toolbar_pager" />
         <action method="setDefaultGridPerPage"><limit>12</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>12</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>24</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>36</limit></action>
         <action method="addPagerLimit"><mode>grid</mode><limit>48</limit></action>
         <action method="addPagerLimit" translate="label"><mode>grid</mode><limit>all</limit><label>All</label></action>
      </block>
      <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>6</count></action>
      <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
   </block>
</reference>


 


Your CMS Page is created .
You can see your page at
www.yoursite.com/SPECIAL

---------------------------------------------------------------------------------------------------

If you want special product on homepage

Paste
<reference name="content">
<block type="catalog/product_special" name="catalog_product_special" as="product_homepage"  template="catalog/product/lists.phtml"/>
</reference>

in Layout Update XML of "Home Page" CMS

A useful link also is available at:
http://www.dnawebagency.com/displaying-new-products-in-magento-with-pagination

18 comments:

  1. really wonderful post. Thanks for sharing this wonderful information.

    ReplyDelete
  2. Need your appreciation to continue my effort.....

    ReplyDelete
  3. Thanks very much, really helpful, can u tell me how to make page for latest producs , like this ? with thanks

    ReplyDelete
  4. 1) Create a file "/app/code/local/Mage/Catalog/Block/Product/Special.php "
    with following contents:
    in my magento /app/code/core/Mage/Catalog/Block/Product/

    ReplyDelete
  5. Add filter in line 43: ->addAttributeToFilter('special_price', array('gt' => 0));
    it filters the promotion products without price set.
    I made a Brazilian version, available at: http://adonaidiofanes.com.br/blog/magento-criar-uma-pagina-com-produtos-em-promocao/

    ReplyDelete
  6. Hi,
    Nice method and works great, but the products on offer set in the catalog price rules are not displayed. Any solution to this?

    thanks

    ReplyDelete
  7. bookmark first.i'm using magento 1.7.0.2 doest that work too? Thanks!

    ReplyDelete
  8. Very useful and good post.............really helpful.....

    http://trimurtyinfotech.com/dev/bts/shop-by-brand/?manufacturer=59
    i want to add toolbar on this page, how to do this.
    I mean i want to add toolbar on brand page. please hepl me ASAP.

    ReplyDelete
  9. In that pager is not working...give me some hope guys

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Great Read! I am impressed on how you make your article easy to understand. I'll come back for more :D

    offshore magento development

    ReplyDelete
  12. The filter is not working, all products with a special price are being displayed. How can I fix this? My version of magento is 1.9.2.4

    ReplyDelete
  13. I do agree with all the ideas you have presented in your post. They’re really convincing and will certainly work. Still, the posts are very short for newbies. Could you please extend them a little from next time?..Keep this great work
    magento development company in bangalore 

    ReplyDelete
  14. Great content thanks for sharing this informative blog which provided me technical information keep posting.
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

    ReplyDelete
  15. From your discussion I have understood that which will be better for me and which is easy to use. Really, I have liked your brilliant discussion. I will comThis is great helping material for every one visitor. You have done a great responsible person. i want to say thanks owner of this blog.
    python Training in Pune
    python Training in Chennai
    python Training in Bangalore

    ReplyDelete
  16. Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
    python training in bangalore

    ReplyDelete