Question

I've added the following code to the checkout page (item.phtml).

$_regularPrice = $_product->getPrice(); 
$_finalPrice = $_product->getFinalPrice();
if($_finalPrice < $_regularPrice):
    $special_percent = ceil(100 - (( 100/$_regularPrice ) * $_finalPrice )); echo $special_percent.'%'; else: echo '0%'; 
endif;

This code is showing proper percentage if I add special price to the product. But it is not working if I add Shopping Cart Pricing Rule. The output is always 0% if I add a Shopping Cart Pricing Rule, is there a way to do the same for Shopping Cart Pricing Rule?

Thanks.

Was it helpful?

Solution

Final price does not respect discount. Because final price is the PRODUCT attribute, and discount is the CART ITEM attribute. Just use the $item, not $product.

discount: $item->getDiscountAmount()

original price: $item->getCalculationPrice();

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top