The following code has been added to the list.phtml but is working only for simple products. When they have an special price with a date range, a sale label is attached to the product image on the category pages. This is also displaying a new label on products that are set as NEW with a date range (the new label is working for all products).
I am trying to find a way to combine a special price check that works for simple products and for configurable products in the case that all child products of a configurable product have an special price.
<?php
$specialprice = $_product->getSpecialPrice();
$specialPriceFromDate = $_product->getSpecialFromDate();
$specialPriceToDate = $_product->getSpecialToDate();
$now = date("Y-m-d");
$newsFrom = substr($_product->getNewsFromDate(), 0, 10);
$newsTo = substr($_product->getNewsToDate(), 0, 10);
$today = time();
$class_has_new = "";
if ($newsTo != '' || $newsFrom != '') {
if (($newsTo != '' && $newsFrom != '' && $now >= $newsFrom && $now <= $newsTo) || ($newsTo == '' && $now >= $newsFrom) || ($newsFrom == '' && $now <= $newsTo)) {
$class_has_new = " has-new";
}
}
if ($specialprice) {
if ($today >= strtotime($specialPriceFromDate) && $today <= strtotime($specialPriceToDate) || $today >= strtotime($specialPriceFromDate) && is_null($specialPriceToDate)) { ?>
<div class="label-product label-sale<?php echo $class_has_new; ?>">
<span class="sale-product-icon">
<?php echo __('Sale'); ?>
</span>
</div>
<?php }
}
?>
<?php
if ($newsTo != '' || $newsFrom != '') {
if (($newsTo != '' && $newsFrom != '' && $now >= $newsFrom && $now <= $newsTo) || ($newsTo == '' && $now >= $newsFrom) || ($newsFrom == '' && $now <= $newsTo)) { ?>
<div class="label-product label-new">
<span class="new-product-icon"><?php echo __('New'); ?></span>
</div>
<?php }
} ?>