Show new product in Home page in magento!!

we can see the newly added products to our store by adding this code

we have to add to type of code

1. app\code\core\Mage\Catalog\Block\Product\New.php

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

/**
 * New products block
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Mage_Catalog_Block_Product_New extends Mage_Catalog_Block_Product_Abstract
{
    protected $_productsCount = null;

    const DEFAULT_PRODUCTS_COUNT = 5;

    protected function _beforeToHtml()
    {
        $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
        
        $collection = Mage::getResourceModel('catalog/product_collection');
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
        
        $collection = $this->_addProductAttributesAndPrices($collection)
            ->addStoreFilter()
            ->addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))
            ->addAttributeToFilter('news_to_date', array('or'=> array(
                0 => array('date' => true, 'from' => $todayDate),
                1 => array('is' => new Zend_Db_Expr('null')))
            ), 'left')
            ->addAttributeToSort('news_from_date', 'desc')
            ->setPageSize($this->getProductsCount())
            ->setCurPage(1)
        ;
        $this->setProductCollection($collection);

        return parent::_beforeToHtml();
    }

    public function setProductsCount($count)
    {
        $this->_productsCount = $count;
        return $this;
    }

    public function getProductsCount()
    {
        if (null === $this->_productsCount) {
            $this->_productsCount = self::DEFAULT_PRODUCTS_COUNT;
        }
        return $this->_productsCount;
    }
}

2. app\design\frontend\default\default\template\catalog\product\new.phtml

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   default_default
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<div class="box recently">
		<div style="background:#FFFFFF url(../images/base_mini_head_bg.gif) repeat-x scroll 0 0; border-bottom:1px solid #DDDDDD; padding:2px 8px; margin:0 1px;">
    		<h3  align="center"><?php echo $this->__('New Products') ?></h3>
		</div>
    <table cellspacing="0" class="recently-list" id="new-products-list-table">
    <?php $i=0; foreach ($_products->getItems() as $_product): ?>
        <?php if ($i>=2): continue; endif; ?>
	
	<tr style=" border:thin #C4C1BC">
    
        <td >
            <div align="center">
			
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><img class="product-image" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(120, 130) ?>" width="120" height="130" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
            </div>
			
                <p align="center"><a class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a>
				
				</p>
				<div align="center">
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php echo $this->getPriceHtml($_product, true, '-new') ?>
				</div>
                <?php if($_product->isSaleable()): ?>
				<p align="center">
                <button type="button" class="form-button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart') ?></span></button>
				</p>
                <?php else: ?>
				
                <div class="out-of-stock"><?php echo $this->__('Out of stock') ?></div>
                <?php endif; ?>
				
                <div class="clear"></div>
				
               <?php /*?> <p class="add-to" align="center">
				
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                    <a href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-cart"><?php echo $this->__('Add to Wishlist') ?></a>
					
                    <?php endif; ?>
					
                    <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?><br />
                    <a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare') ?></a>
                    <?php endif; ?>
					
                </p><?php */?>
				
            </td>
      
        </tr>
		<tr><td style=" border:thin #C4C1BC">
		<?php $i++; endforeach; ?>
    <?php for($i;$i%3!=0;$i++): ?>
	</td></tr>
		<?php endfor ?>
    </table>
</div>
<?php endif; ?>

Then call it where u like to see it.

Advertisements

Tagged: , , ,

3 thoughts on “Show new product in Home page in magento!!

  1. Magician January 14, 2010 at 8:47 am

    Top Page! Compliments on the top work!

  2. Despina Kriete January 20, 2010 at 1:46 am

    Hello there, I was wondering do you consider guest writers. I have been writing on this subject for quite a while now and would love to share my thoughts. Regards.

  3. tallinn accommodation July 29, 2010 at 7:19 am

    Nice post. Thanks. You have brought some clarity to something I have been trying to figure out.

Comments are closed.

%d bloggers like this: