I am trying to display a sale badge over the image of products with a special price on the catalog and product pages.
I have used the following PHP:
<?php // sale badge ?> <?php $specialPrice = $_product->getSpecialPrice(); $specialPriceFromDate = $_product->getSpecialFromDate(); $specialPriceToDate = $_product->getSpecialToDate(); ?> <?php if ($specialPrice || ($currentDate >= $specialPriceFromDate && $currentDate <= $specialPriceToDate) || ($currentDate >= $specialPriceFromDate && $specialPriceFromDate != '' && $specialPriceToDate == '')): ?> <span class="sale-badge"><?php echo $this->__('Sale') ?></span> <?php endif; ?>
This displays the badge correctly unless the special price to date has passed when it still displays the badge even though the product is no longer at the special price.
The idea is for the badge to display in the following scenarios:
- there are no special from or special to dates set (i.e. the product is permanently on special until manually altered)
- there is a from date but no to date (i.e. once the from date passes the product is permanently on special until manually altered)
- there is no from date but there is a to date (i.e. the product is on special until the to date passes)
- there is a from and a to date (i.e. the product is only on special within the defined period)
I am sure I have just missed something obvious but can someone point out what it is please?