4

I'm trying to add an icon to all products with special price in a cart and I've to check if products are on sale. Anyone got any idea how to do it? It was simple to do in list and product cart but now I'm stuck.

10

You can do this by below code:

    if($product->getPrice()>$product->getFinalPrice()):
    // product in sales
    endif;

If want only basic of Special price,Then you can try the below:

$specialprice = $product->getSpecialPrice();
$specialPriceFromDate = $product->getSpecialFromDate();
$specialPriceToDate = $product->getSpecialToDate();
$today =  time();

if ($specialprice && ($product->getPrice()>$product->getFinalPrice())):
        if($today >= strtotime( $specialPriceFromDate) && $today <= strtotime($specialPriceToDate) || 
    $today >= strtotime( $specialPriceFromDate) && is_null($specialPriceToDate)):
   //product in sales
    endif; 
endif;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.