Adding Style to Price Elements in Magento

One of our client’s requirements was to display the price as separate 3 elements (currency symbol, price value before decimal & after decimal, as separate). For that we adopted the following method and solved the issue. Here is the screenshot of my work


 

The procedure we adopted in this work is as follows..

In price.phtml mainly there are 4 condition checking, such as

      1.Whether the product is grouped or not.
      2.Is there any discount/ Special price.
      3.Show both price (include and exclude tax) or any one only.
      4.Finally the FPT (fixed product tax or ecological tax) display type (FPT again include 4 condition but it’s normally not in use for most of the countries, So most probably we proceed with its else condition).

The price format is displayed by calling the method formatPrice($price, $includeContainer = true) from class Mage_Core_Helper_Data in the price template.

Here we are includluding a new method separateformatPrice($price, $includeContainer = true) in class Mage_Core_Helper_Data
as
var $pro;
public function separateformatPrice($price, $includeContainer = true)
{
$this->pro= array();
$this->pro[0]= Mage::app()->getLocale()->currency(Mage::app()->getStore()
->getCurrentCurrencyCode())->getSymbol();
$num_price= Mage::app()->getLocale()->getNumber($price);
$pri=explode('.',$num_price);
$this->pro[1]=$pri[0];
$this->pro[2]= ".";
if($pri[1]!=0):
$this->pro[3]=$pri[1];
else:
$this->pro[3]="00";
endif;
return $this->pro;
}

and this method is called in the places where you want to display the separated price in the price.phtml template file.

For that now call the function separateformatPrice($price, $includeContainer = true) by replacing
formatPrice($_price, false) ?>
with

<?php $prices = $_coreHelper->separateformatPrice($_price, false) ?>
$i=1;
foreach ($prices as $pric):      { ?>
<span id="price-element<?php echo $i; ?>">
<?php echo $pric;?>
</span>
<?php $i++;
}
endforeach;
?>

Note: the variable $_price may change as the condition fails.

Thank you for your time to read this and wish you the best to solve your challenges

Bookmark and Share
This entry was posted in Magento Developer Notes. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>