Last active
March 17, 2021 22:09
-
-
Save ivandoric/83562fc7644a5d5fd416 to your computer and use it in GitHub Desktop.
magento: Check if product is new in product listing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$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"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You absolutely must NOT convert and validate dates manually, because this can cause timezone issues. Magento has built-in method
isStoreDateInInterval()
inMage_Core_Model_Locale
class. So you should create helper method which can look like thisMore details you can find here http://m-grater.info/all/check-product-is-new/