Exchange Rates

This is an Expression Engine module that allows you to get live currency exchange rates.

Support can be found in the comments and in this EE forum thread.

Download Exchange Rates
Current Version: 1.1 (released 21 February 2009)

* Works with ExpressionEngine 1.6 and higher.

1. Concept

This module provides the ability to display prices in multiple currencies using live exchange rates. The rates are taken from the European Central Bank website and are updated daily.

2. How It Works

The Exchange Rates module can be called from within a template as well as from an add-on. Every time the module is called it checks if the currency exchange rates have been updated in the last hour. If not then it automatically updates them.


Getting the exchange rate from one currency to another:

{exp:exchange_rates:get_rate from="EUR" to="USD" decimals="5"}
				

The from parameter is required and represents the currency code of the currency we want to get the rate from.

The to parameter is required and represents the currency code of the currency we want to get the rate to.

The decimals parameter is optional and if included defines how many decimal places the result will have.


Converting a specified amount from one currency to another:

{exp:exchange_rates:convert amount="100" from="USD" to="JPY" decimals="2"}
				

The amount parameter is required and represents the amount that we want to convert. The amount value can be a field value within a weblog entries tag.

The from parameter is required and represents the currency code of the currency we want to convert from.

The to parameter is required and represents the currency code of the currency we want to convert to.

The decimals parameter is optional and if included defines how many decimal places the result will have.


The module can be called from within an add-on as follows:

// create exchange rate object
if (!class_exists('Exchange_rates'))
{
	require '/home/mypath/public_html/system/modules/exchange_rates/mod.exchange_rates.php';
}

$ER = new Exchange_rates();

$USD_to_EUR_rate = $ER->get_rate('USD', 'EUR');
				

3. Installation

Download and unzip exchange_rates.zip, then follow the steps below:

  1. Upload the exchange_rates folder to the system/modules folder
  2. Upload lang.exchange_rates.php to the system/language/english folder
  3. Install the Exchange Rates module (Control Panel -> Modules -> Install)

4. Download

You can download and use the Exchange Rates module for free here:

If this module has helped you and you are feeling generous then please make a small donation, it is much appreciated:

5. Changelog

Version 1.1
  • Added decimals parameter

6. Comments

Blank Avatar
Malcolm
20 February 2009


This is a great module - just downloaded and given it a test - wondered if there was any way to restrict the number decimal places? To 2 (e.g. 12.99)?

Thanks, Malcolm.

Blank Avatar
Ben
21 February 2009


hi malcolm, great feature request, i've added it to version 1.1 which you can download now.

Blank Avatar
Malcolm
22 February 2009


Ben - fantastic.

Thanks for the updated version - works a treat :-)

Blank Avatar
Beebs
03 March 2009


This is great.

My question is How to create a dropdown/pullout option where the parameter "from" and "to" are open so that user can decide which currency need to be converted? - Of course there should be default set in the dropdown/pullout.

Great module!

Blank Avatar
Beebs
03 March 2009


Sorry for my second post - I thought I will just save time.

The module was installed successfully and I have read your instruction, somehow I confuse to display it in the template.

Can you please give me an example?

Cheers

Blank Avatar
Ben
04 March 2009


Beebs: to let the user decide the currencies, you would have to set up a form with "from" and "to" currency fields and amount. you could then use php to read in the fields on the submitted form, so you'd have:

<?php global $IN; ?>
{exp:exchange_rates:convert amount="<?php echo $IN->GBL('amount'); ?>" from="<?php echo $IN->GBL('from'); ?>" to="<?php echo $IN->GBL('to'); ?>" decimals="2"}

just make sure that php is enabled and parsed on input.

Blank Avatar
Danny Tam
06 April 2009


I have a {price} custom field that has the input of "7.99" in it. I have the following Exchange Rates single tag in my template:

{exp:exchange_rates:convert amount="{price}" from="CAD" to="USD" decimals="2"}

It is throwing out this error when I visit my site:
"The following errors were encountered:
Exchange Rates Module: Amount, From and To are all required template variables"

Any ideas?

Blank Avatar
Danny Tam
06 April 2009


I've resolved the issue. The problem is that I had used the {price} field in my weblog entries list and not every entry had the {price} field populated.

Can you possibly make a parameter that can omit the error page so whatever entries who don't use the field won't get their content displayed.

Or do you think it's just better to use a conditional, such as:
{if price !=''}
{exp:exchange_rates:convert amount="{price}" from="CAD" to="USD" decimals="2"}
{/if}

Blank Avatar
Danny Tam
06 April 2009


Dear Ben,

I've tried the conditionals as is (above) and it seems even if the code is inserted into conditionals and I visit a weblog entry with it inserted, it will still throw me an error.

I use the same standard template for all my weblog entries, so having a parameter to disable the error page would be great. I thought the conditional would've worked, but I was wrong!

Any solutions is appreciated. Excellent work once again (as with your sitemap module, of which I am a customer).

Blank Avatar
Ben
06 April 2009


hi danny,

strange that the conditional didn't solve it, can you try the following:

{if "{price}" !=""}
{exp:exchange_rates:convert amount="{price}" from="CAD" to="USD" decimals="2"}
{/if}

Blank Avatar
Mike
19 September 2009


Could this module work in a wordpress blog which is rebuild to a webshop?
Let's say I wanna fetch all input data in posts/pages that looks like this:

8.00 USD

And get the live currency rate for UK Pounds displayed:

4 GBP

If not this module can do it, any tips on plugins, scripts that might handle such actions?

Kindly
Mike


» View more comments


Leave A Comment

name (required)
email (required but will be kept completely private)
website