Display Percentage of Discount on Product List and Product View Page in Magento

catalog-price-rulespromotions

enter image description hereWe used "Promotions > Catalog price Rule " to give discounts for all products in our site.

for some category products we gave 20 % off and for some products we gave 10 % off.

i want to display percentage of discount on "product list " and "product view page" as like below

" [20 off]%"

please help me to find solution.

Best Answer

Here is how you can get the discount percentage.
Let's say $_product is the current product instance:

<?php 
$originalPrice = $_product->getPrice();
$finalPrice = $_product->getFinalPrice();
$percentage = 0;
if ($originalPrice > $finalPrice) {
    $percentage = ($originalPrice - $finalPrice) * 100 / $originalPrice;
}

if ($percentage) {
    echo $this->__('You save %s', $percentage . '%');
}

for the product list you can integrate this in the foreach loop that lists all products and on the product view page you can add it anywhere.

Related Topic