Magento how to find if a product is on sale to add on sale tag
I couldn’t find a easier solution yet.
This is what I use to find out if a product is on sale in order to add a corresponding tag:
<?php
$specialPrice = Mage::getModel(‘catalog/product’)->load($_product->getId())->getSpecialPrice();
$specialPriceFromDate = Mage::getModel(‘catalog/product’)->load($_product->getId())->getSpecialFromDate();
$specialPriceToDate = Mage::getModel(‘catalog/product’)->load($_product->getId())->getSpecialToDate();
$rightNow = time();
if($specialPrice && ($rightNow >= strtotime( $specialPriceFromDate) && $rightNow <= strtotime($specialPriceToDate) || $rightNow >= strtotime( $specialPriceFromDate) && is_null($specialPriceToDate))): ?>
<!– replace the line below with your on sale tag –>
<div class=”tag-sale”><?php echo $this->__(‘Sale’); ?></div>
<?php endif; ?>