1

How can I do a currency converter in Magento Community edition 1.8? Does Magento has this functionality by default or do I have to developed it?

I need to show a second currency in on each of my product page (in parentheses) when you select a currency option from the converter's dropdown.

it is like this store in Euro currency and I can get it converted to Pound,

enter image description here

Is it possible?

2 Answers 2

1

You might have noticed the “Currency Setup” tab in Magento’s Administration under “System->Configuration” menu. There you should select default site currency, and besides that, all currencies you want to support.
Screenshot:
scshot

After doing that, go to “System->Manage Currency Rates” and set rates for currencies you’ve chosen before. You can use Webservicex to import currency rates from Webservicex service.
After this, create a custom file, save it in “YOUR_PACKAGE/YOUR_THEME/template/currency/" as currency.phtml and put this code.

<?php if($this->getCurrencyCount() > 1): ?>
<div class="form-language">
    <label for="custom-currency-selector"><?php echo $this->__('Your Currency:') ?></label>
    <select onchange="window.location.href=this.value" name="custom-currency-selector" id="custom-currency-selector">
        <?php foreach ($this->getCurrencies() as $_code => $_name): ?>
        <option value="<?php echo $this->getSwitchCurrencyUrl($_code)?>"
            <?php if($_code == $this->getCurrentCurrencyCode()): ?>
                selected="SELECTED"
            <?php endif; ?>>
            <?php echo $_code ?>
        </option>
        <?php endforeach; ?>
    </select>
</div>
<?php endif; ?>  

Reflect these chances in magento, create a local.xml file, use this code:

    <?xml version="1.0"?>
    <layout version="0.1.0">
        <default>
            <reference name="header">
                <block type="directory/currency" name="custom_currency_selector" template="currency/currency.phtml"/>
            </reference>
        </default>  
</layout>  

Clear cache and you will get the selected currencies in dropdown box of magento header. When you select any other currency, then current value of currency will be converted into selected currency. There is no need to implement currency conversion. Magento comes with built-in currency converter. To display multiple currencies in product page, you may try this link, I had tried this earlier and it worked for me. Link: Adding new currencies in product lists page

6
  • thanks but the code doesn't work - it does not pull the currencies from the list of Allowed Currencies that I have selected. I only get EURO for var_dump($this->getCurrencies());.
    – Run
    Jul 2, 2014 at 11:56
  • You can use Webservicex to import currency rates from Webservicex service. how do you import currency rates with that? in Webservicex, it only has this input field - Connection Timeout in Seconds and I don't know what that is...
    – Run
    Jul 2, 2014 at 11:59
  • It works, I've tested it in magento 1.9.0.1, Select a default display currency, base currency and allowed currencies. In my case, default display currency was USD, base currency was USD and allowed currencies were EUR and INR. After selecting the values and saving, go to var/cache, delete all files, log out from admin panel, re log in, go to 'Manage currency rates', import the conversion rates by using webserviceex, then click on save. Then use the codes. Jul 2, 2014 at 12:11
  • I'm on Magento CE 1.8 though... and nothing I can import from there. Have you tried it before on 1.8?
    – Run
    Jul 2, 2014 at 18:35
  • 1
    My pleasure.... Hope that you'll learn a lot :) Jul 3, 2014 at 4:44
2

Try this code snippet !! This will convert current currency with base currency. you can give your (GBP) as current currency and get converted price.

$_taxHelper = $this->helper('tax');
$_store = $_product->getStore();
$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
$_convertedFinalPrice = Mage::helper('directory')->currencyConvert($_product->getFinalPrice(), $baseCurrencyCode, $currentCurrencyCode);
$_finalPrice = $_taxHelper->getPrice($_product, $_convertedFinalPrice);

You can get available currency codes to covert from base currency with this code

$_store = $_product->getStore();
$availableCurrencyCodes = $_store->getAvailableCurrencyCodes();
print_r($availableCurrencyCodes);
3
  • How can I use GBP in the snippet?
    – Run
    Jul 2, 2014 at 12:04
  • 1
    $availableCurrencyCodes = $_store->getAvailableCurrencyCodes(); gets you availble means "Allowed Currencies", you can loop through them and get appropriate code, and apply it as $currentCurrencyCode, Thats how you can show more than one currency conversions at a time. I should have mention that you need to select your allowed currencies as per @Ajay Kulkarni screenshot. Jul 3, 2014 at 6:12
  • Thanks! I was looking for Mage::helper('directory')->currencyConvert() .. very helpful Sep 19, 2019 at 19:38

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.