Magento display two currencies (get currency rate)

Magento display two currencies (get currency rate)

July 30, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento display two currencies (get currency rate)

Displaying Multiple Currencies in Magento: A Comprehensive Guide

When it comes to e-commerce platforms like Magento, displaying prices in multiple currencies is a common requirement for global businesses. However, calculating the correct exchange rates can be a challenge if you’re not sure where to start. Let’s dive into how to display both GBP and EUR on your product page while allowing customers to only checkout using their selected currency.

Understanding Currency Configuration in Magento

Before we get into the code, it’s important to understand that Magento allows you to configure multiple currencies for your store. You can set up different store views with different currencies, but by default, Magento only allows one active currency per store view at a time. To enable multiple currencies:

  1. Go to Stores > Configuration.

  2. Under ‘Currency Setup’, enable both GBP and EUR in the ‘Allowed Currencies’ field.

  3. Set your base currency as required (this is used for internal calculations).

  4. Save changes.

Importing Currency Rates

To ensure accurate conversions, you need to import real-time currency rates into Magento. You can use various web services like WebserviceX or Open Exchange Rates to fetch the latest rates. Here’s how it works:

  1. Enable Caching: Go to Stores > Configuration > System > Cache Management and enable ‘Currency’ cache.

  2. Import Rates: Use a cron job or script to fetch live exchange rates every hour (or as required) using one of these services.

  3. Store the data in Magento’s currency table (core_currency_rates). You can use the following example code:

$rates = Mage::getModel('directory/currency')->fetchAll();
foreach ($rates as $rate) {
    if (!Mage::getStoreConfig('currency/options/base')) {
        continue;
    }
    if ($rate->currency_code == 'GBP' || $rate->currency_code == 'EUR') {
        // Fetch live rate from your preferred service
        $liveRate = fetchLiveRateFromService($rate->currency_code);
        Mage::getModel('directory/currency')->updateRate(
            Mage::getStoreConfig('currency/options/base'),
            $rate->currency_code,
            $liveRate
        );
    }
}

Displaying Prices in Multiple Currencies

Now, let’s write the code to display prices for both GBP and EUR on your product page. You can create a block or extend an existing one:

class MultiCurrency extends Mage_Core_Block_Template {
    public function getProductPrice($product) {
        $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
        $currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();

        foreach ($allowedCurrencies as $currency) {
            if ($currency != $currentCurrencyCode && in_array($currency, array('GBP', 'EUR'))) {
                $rate = Mage::getModel('directory/currency')->getRate($currency, $currentCurrencyCode);
                $priceInForeignCurrency = $product->getPrice() * $rate;
                echo "GBP/EUR Price: {$this->formatPrice($priceInForeignCurrency)}";
            }
        }

        return $this->formatPrice($product->getFinalPrice());
    }
}

Remember to add this block to your product view template file.

Conclusion

Displaying multiple currencies in Magento requires a combination of proper configuration, currency rate management, and custom code. By following the steps outlined above, you can successfully show prices for both GBP and EUR on your product page while maintaining a single active currency per store view.

For more advanced features like custom exchange rate rules or real-time currency updates every minute, consider exploring Magento’s enterprise edition or third-party extensions available at https://laravelcompany.com/magento-extensions.

Checkout Catalog Cache Configuration

Our network