How to load new attribute in Magento

How to load new attribute in Magento.

  • The new attribute is defined by two database fields (or attributes) new from and new to .
  • Using these parameters in list.phtml, requires you to modify the attribute set returned by the Mage_Catalog_Block_Product_List class to be found in appcodecoreMageCatalogBlockProductList.php
  • In function _getProductCollection, paste the following line
  • $this->_productCollection->addAttributeToSelect(‘news_from_date’)->addAttributeToSelect(‘news_to_date’);  Obvisouly this comes just after the product collection definition around line 75 of the List.php$this->_productCollection = $layer->getProductCollection();

list.phtml template now has access to the data and checking that a product is new is as simple as performing PHP based date comparisons. We provide here basic comparison that will only work for products where both news_from and news_to have been filled.  Add the following PHP code somewhere in your productcollection loop and the work is done !
$now = date(“Y-m-d”);
$newsFrom= substr($_product->getData(‘news_from_date’),0,10);
$newsTo= substr($_product->getData(‘news_to_date’),0,10);
if ($now>=$newsFrom && $now<=$newsTo)

?> <h3 class=”nouveauteProductList” >NEW PRODUCT!<h3>




Posted in:

Leave a Reply