How to Check if Product in Cart is on Sale in Magento

cartspecial-price

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.

Best Answer

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;
Related Topic