Wednesday, July 18, 2012

Magento: Display Products On Home Page

New Products
       >> To Display New product on home page add this block to your CMS home page in content section..

{{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}

       >>   Now Set the date to these attributes:
                             >>    Set Product as New from Date and
                             >>    Set Product as New to Date



                                                          OR

      >> Place this code to this path:- app/code/core/Mage/Cataloge/Model/Product.php

    public function isNew($date=null)
    {
        if($date==null) {
            $date = $this->getResource()->formatDate(time());
        }
        
        if(!$this->getData('news_from_date')) {
            return false;
        }
        
        $current_date = new DateTime($date); // compare date
        $from_date = new DateTime($this->getData('news_from_date')); // begin date
        $to_date = new DateTime($this->getData('news_to_date')); // end date
        
        $return = ($current_date >= $from_date && $current_date <= $to_date);
        
        return $return;
    } 

   >> Next add this code into your phtml page where you want to show this product:-

    <div class="new">
      <?php if ($_product->isNew() == true): ?>

            //YOUR CODE FOR NEW PRODUCTS GOES HERE

      <?php endif; ?>
    </div>


All Products
    >>  Add this block to your CMS home page in content section..
{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/list.phtml"}}


Display Products of a category
    >>  Add this block to your CMS home page in content section..
 {{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" category_id="4" template="catalog/product/list.phtml"}}




No comments:

Post a Comment