1


My client wants to display 3 different formats of currency which should be displayed on the product list page. Here is the screen shot for reference.
Currency

Do you see that $23.00 on right side? My client wants to display Euro and INR values to be displayed right under that USD value. How to do that. I took USD as default currency and INR and Euro as allowed currencies and imported standard conversion rates by using webserviceex. Please help me out.... I'm not understanding that where should I add the following line of codes...

$baseCode = Mage::app()->getBaseCurrencyCode();      
    $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies(); 
    $rates = Mage::getModel('directory/currency')->getCurrencyRates($baseCode, array_values($allowedCurrencies));
    var_dump($rates);

Help me

3

1 Answer 1

1

If you have only simple products this should be easy.
Just add the following code in app/design/frontend/{package}/{theme}/catalog/product/view/type/default.phtml right under $this->getPriceHtml($_product).

<?php
//remember the current currency
$currentCurrency = Mage::app()->getStore()->getCurrentCurrencyCode();
//remember the current currency object
$currentCurrencyObject = Mage::app()->getStore()->getCurrentCurrency();
//get allowed currencies
$allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
foreach ($allowedCurrencies as $currency) {
    //skip the current currency
    if ($currency != $currentCurrency) {
        //load the currency object
        $currObject = Mage::getModel('directory/currency')->load($currency);
        //change the store currency
        Mage::app()->getStore()->setCurrentCurrencyCode($currency);
        Mage::app()->getStore()->setCurrentCurrency($currObject);
        //show the price in the new currency
        echo $this->getPriceHtml($_product, false, '-'.$currency);
    }
}
//reset the store currency
Mage::app()->getStore()->setCurrentCurrencyCode($currentCurrency);
Mage::app()->getStore()->setCurrentCurrency($currentCurrencyObject);
?>

You may also need to add the same in app/design/frontend/{package}/{theme}/template/catalog/product/view/price_clone.phtml but change echo $this->getPriceHtml($_product, true, '-'.$currency); to echo $this->getPriceHtml($_product, true, '-clone-'.$currency);

If you have custom options involved or configurable or bundle products this may not work. Most probably you will need some custom javascript to make the prices change when you change the options.

[EDIT]
The answer above is for the product view page. But it should work for product list page also. Just add the same code after the price is shown. You can also optimize this so you won't have to load the currencies each time you show a product in the list.

5
  • Can't we do it from backed? Can we add 2 custom price fields under price tab and make them default to EURO and INR? Jun 16, 2014 at 8:15
  • 1
    I think so. You can use Mage::helper('core')->currency(YOUR VALUE HERE, true, false) to print the values.
    – Marius
    Jun 16, 2014 at 8:20
  • Will it work for multiple products? Jun 16, 2014 at 9:21
  • Most probably. You can try it.
    – Marius
    Jun 16, 2014 at 10:17
  • yeah, tried and it didn't work for rwd theme Jun 16, 2014 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.