top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to Add Discount price amount in percentage on product in magneto frontend?

+3 votes
373 views
How to Add Discount price amount in percentage on product in magneto frontend?
posted Jan 27, 2016 by Vrije Mani Upadhyay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

To display Special Price percentage discount in Magento, you need to do following steps

1) Goto app/design/frontend/YOURTHEME/default/template/catalog/product/price.phtml
2) Basically we need to find the percentage of the difference between the actual price and special price. So first we will obtain both special and actual price of the product using following code

$_actualPrice = $_store->roundPrice($_store->convertPrice($_product->getPrice()));
$_convertedFinalPrice = $_store->roundPrice($_store->convertPrice($_product->getFinalPrice()));

Here Both these prices are already retrived in the file price.phtml
3) To get the discount percentage use the following code

$_discountPercentage = round((($_actualPrice-$_convertedFinalPrice)/$_actualPrice)*100);

Now you got the discount percentage stored in $_discountPercentage variable. Next you need to display this percentage only where Special price is available. To do so you need to find the class “special-price” and under that class you can enter the discount amount percentage.

You can simply call it using echo $_discountPercentage.”%”. You can format it as per your requirement.

answer Jan 27, 2016 by Manikandan J
...