Output Price with Correct Currency Symbol
If you want to echo out the price of something using the correct currency symbol for your store there are (probably more than but these are the only ones I can think of at the moment) two ways to do it.
First of all you can get your symbol manually, and concatenate that in front of a number formatted price.
$symbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(); $price = $product->getFinalPrice(); echo $symbol.number_format($price,2);
This is a bit of a long way around as the next solution will show you. For some reason there is a very nice hidden method in Magento that allows your to do the following with only one line of code:
- Add <span class=”price”> around your figure
- Attach the current symbol to your price
- Number format your price
And here’s the code:
$price = $product->getFinalPrice(); echo Mage::helper('core')->currency($price);
That’s it for today, thanks for visiting the magento blog here at e-commerce web design!