Show Alternate Price in Other Currency
I thought I’d share this post in case it helps anyone, but to be honest it’s pretty specific to the site I was working on. Here’s the scenario: I created a function which takes the price (either in Euros or Pounds) and then displays the price in the other currency. So if pounds are currently set it will show the Euro price and vice versa. So I created a function called getAlternatePrice, and it looks like this:
public function getAlternatePrice($price){
$currency = Mage::app()->getStore()->getCurrentCurrencyCode();
$base_currency = Mage::app()->getBaseCurrencyCode();
$allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
$rates = Mage::getModel('directory/currency')->getCurrencyRates($base_currency, array_values($allowedCurrencies));
$europrice = $price*$rates['EUR'];
$gbpprice = $europrice/$rates['EUR'];
switch ($currency) {
case "EUR":
$symbol = Mage::app()->getLocale()->currency("GBP")->getSymbol();
$price = $gbpprice;
$price = $symbol.number_format($price, 2, '.', '');
$name = "GBP";
break;
case "GBP":
$symbol = Mage::app()->getLocale()->currency("EUR")->getSymbol();
$price = $europrice;
$price = $symbol.number_format($price, 2, '.', '');
$name = "Euro";
break;
}
echo '<span class="price-excluding-tax">
<span class="label">'.$name.':</span>
<span id="price-excluding-tax-88" class="price">'.$price.'</span>
</span>';
}
Call the function using the helper:
Mage::helper('function')->getAlternatePrice($_product->getFinalPrice());
Then the frontend will display like so:

If anyone knows of a cleaner way of doing this then please share it and I’ll make note of it on the blog. Thanks for reading the Magento Blog at Ecommerce Website Design.
