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

copy

App/design/frontend/base/default/template/catalog/product/price.phtml

paste
App/design/frontend/default/YOURTEMPLATE/template/catalog/product/price.phtml


first set special price in magento product.

<?php

$_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 

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

if you want round figger value in percentage. then
<?php

echo $_discountPercentage."%";

?>
this value display round price discount 

if you want price in float check below code

<?php

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

echo $_discountPercentage."%";

?>
it will diplay value decimal two digit.like 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?

    ReplyDelete

Thank You For Comment