Check if product is set as New in Magento.

Magento has a great functionality to mark product as New within a range of date. At times we want the new product to be highlighted with the TAG say NEW as shown in the figure below.

new-product

To make such a tag in product listing page you need to follow below steps

1) Goto app/design/frontend/YOURTHEME/default/catalog/product/list.phtml
2) Add the following code at appropriate place in your file. This code will check the start date and end date of the product marked as new and will display the tag accordingly.

$newFromDate = Mage::getModel(‘catalog/product’)->load($_product->getID())->getNewsFromDate();
$newToDate = Mage::getModel(‘catalog/product’)->load($_product->getID())->getNewsToDate();
$now = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
if(($newFromDate < $now && $newFromDate != NULL) && ($newToDate > $now || $newToDate == “”)){
echo “New Product”;
}

Here, We just checked the codition if the product is set as NEW or not. In case of any confusion please feel free to contact us.

Now you can design the TAG as you wish. Please provide your feedback on this.

Advertisements

5 thoughts on “Check if product is set as New in Magento.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s