Question

I need to display two currencies simultaneously, but only for appearance, not function.

It should look like this 100euro/80USD or similar. I would like them to show side by side.

Was it helpful?

Solution

The simplest way (although not necessarily the best), would be to iterate over the currencies you've chosen to enable on your store in price.phtml.

At the top of price.phtml, just before the HTML, add

$store = Mage::app()->getStore();
$currentCurrency = $store->getCurrentCurrencyCode();
$currencies = array();

$codes = Mage::app()->getStore()->getAvailableCurrencyCodes(true);
if (is_array($codes) && count($codes) > 1) {
    $rates = Mage::getModel('directory/currency')->getCurrencyRates(
        Mage::app()->getStore()->getBaseCurrency(),
        $codes
    );

    foreach ($codes as $code) {
        if (isset($rates[$code])) {
            $currencies[$code] = Mage::app()->getLocale()
                ->getTranslation($code, 'nametocurrency');
        }
    }
}

foreach($currencies as $code => $value): 

?>

    <?php $store->setCurrentCurrency(null)->setCurrentCurrencyCode(strtoupper($code), false); ?>
    <?php if(strtoupper($code) != strtoupper($currentCurrency)) $this->setIdSuffix($this->getIdSuffix().'-'.strtolower($code)); ?>

Then at the very end of the HTML, close the loop and reset the currency,

<?php endforeach; ?>

<?php $store->setCurrentCurrency(null)->setCurrentCurrencyCode($currentCurrency); ?>

OTHER TIPS

The only solution i know is to add them with javascript.

Maybe it is also possible to change the price.phtml and show two prices of different store views.

the first thing you need is the currency rates. magento has support for that, but the default service doesn't seem to be working anymore. i've written an extension that uses OpenExchangeRates.org - https://github.com/firewizard/Mandagreen_CurrencyRates

once you have these, you need to use a helper method everywhere the price is displayed - price.html or direct getPrice() calls.

the quickest solution is to use javascript, like Reinsch pointed out. you could pass the currency rate at the top of the page, then once the dom is ready replace all .price references with both prices.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top