Thursday, 8 January 2015

How to display discount percentage for Special Price in Magento

If price. phtml file not in your theme, please copy from here




first set special price in magento product.


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

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

echo $_discountPercentage."%";


this code use for display discount in percentage.

$_actualPrice  it's retailer of product
$_convertedFinalPrice it's special price.

if you want to check that 

echo "retail price:- ".$_actualPrice."</br>";
echo "special price:- ".$_convertedFinalPrice."</br>";

if you want round figger value in percentage. then

echo $_discountPercentage."%";

this value display round price discount 

if you want price in float check below code


$_discountPercentage = number_format((float)$_discountPercentage, 2, '.', '');

echo $_discountPercentage."%";

it will diplay value decimal two 20.00%

1 comment:

  1. This is fine and working properly.. I need this same discount percentage to be in range at the layered navigation filter. How to get that?


Thank You For Comment