How to display discount percentage for Special Price in Magento

This post is posted on Saurabh Patel’s Request. He required this thing to be done in Magento.

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.

Thats it. Please provide your feedback as a comments

Advertisements

6 thoughts on “How to display discount percentage for Special Price in Magento

  1. Thanks a lot, but how can I display $_discountPercentage in my view.phtml file?
    I wish to show discount price in product description, not in price block.
    I copied the code into price.html but the variable is undefined in view.phml.
    Any ideas?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s