Magento: How to get Currency Rates

Share

You can see the currency Rates from Magento Admin
System -> Manage Currency Rates

You can change base currency and allowed currencies from
System -> Configuration -> GENERAL -> Currency Setup -> Currency Options

Now, here I will show you how you can get currency rates values for any given currency code.

Here, I will be fetching currency rates for base currency. You can keep any currency code instead of basecurrency.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* Get the base currency
*/
$baseCurrencyCode = Mage::app()->getBaseCurrencyCode();
/**
* Get all allowed currencies
* returns array of allowed currency codes
*/
$allowedCurrencies = Mage::getModel(‘directory/currency’)
->getConfigAllowCurrencies();
/**
* Get the currency rates
* returns array with key as currency code and value as currency rate
*/
$currencyRates = Mage::getModel(‘directory/currency’)
->getCurrencyRates($baseCurrencyCode, array_values($allowedCurrencies));

Similarly, you can get currency rates for any currency code. But remember that the currency should be set as allowed currency in
System -> Configuration -> GENERAL -> Currency Setup -> Currency Options -> Allowed Currencies

$allowedCurrencies = Mage::getModel(‘directory/currency’)
->getConfigAllowCurrencies();
/**
* Get currency rates for Nepalese Currency
*/
$currencyRates = Mage::getModel(‘directory/currency’)
->getCurrencyRates(‘NPR’, array_values($allowedCurrencies));

Comments are closed.