Converting Prices Between Base and Display Currency in Magento

Converting Prices Between Base and Display Currency in Magento

Stores that sell in several currencies keep prices in a base currency and convert them for display. When you build custom blocks, you often need to do the same conversion yourself.

Finding the currency codes

These two calls return the store’s default currency and the one the shopper has currently selected:

<?php 

Mage::app()->getStore()->getDefaultCurrencyCode();

Mage::app()->getStore()->getCurrentCurrencyCode();
?>

Converting a price

Pass the amount, the base code and the current code to the directory helper:

<?php

$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode(); 
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode(); 

$price = Mage::helper('directory')->currencyConvert($pricetoconvert, $baseCurrencyCode, $currentCurrencyCode); 

?>

The helper uses the rates saved under System > Manage Currency Rates, so keep those up to date (manually or with the scheduled import).

Heads up: this guide applies to Magento 1, which stopped receiving official security updates in June 2020. If your store still runs it, plan a move to Magento 2 or Adobe Commerce soon. We can help with the migration.

Want this done for you? Find out more about our Magento development service.

Keep reading

Related articles

All articles

Need a hand?

Stuck on something similar?
We can fix it with you.

Send us the problem. A senior developer reads every message and replies within one working day.