Jump to content
FantasyArt

Trying to find exchange rate auto updater.

Recommended Posts

I am trying to find an auto update exchange rate module to help keep our prices updated to our international customers.

 

We purchase some of our products from the UK also so trying to figure out if we need to have a way of putting UK Prices on those specific products or whether or not we can put the exchange rate price at the time of entry.

 

The current module that I am looking at is called Auto Update Currency Exchange Rate code and installation process below.

 

 

Hi All

 

I've modified this contribution to do the following:

 

- Integrate with the native Currency functionality of OSC (ie when you go to Admin->Localization->Currencies) it will update the currencies using the European Central bank rates

- Because it integrates with the native Currencies functionality, it will work with as many Currencies as you want. Just use the OSC's Localization->Currency functionality to add and manage currencies.

 

- Will work with all stores, regardless of what the Default Currency is (ie the store default currency doesn't have to be EUR or GBP). It will auto detected the store's native currency and calculate the exchange rates correctly.

 

- Will work with all currencies provided by EC Bank (EUR, GBP, USD, CAD, HKD, and many more ....; it won't work with currencies not listed by the EC Bank).

 

 

INSTALLATION INSTRUCTIONS:

 

Step 1) Edit /admin/includes/functions/localization.php

 

At the end of the document, paste the following code (before the "?>" line):

 

function quote_ECBank_currency($to) {

# Read currency exchanges rates

$xmlcontents = file("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml");

 

# $xld may be used in your output to inform you user or admin

# Extract exchange rates

foreach ($xmlcontents as $line) {

ereg("currency='([[:alpha:]]+)'",$line,$gota);

if (ereg("rate='([[:graph:]]+)'",$line,$gotb)) {

$exchrate[$gota[1]] = $gotb[1];

}

}

$exchrate['EUR'] = 1; /* manually add 1 EUR = 1 EUR to the array (all Exch.Rates are from EUR to X because we're getting them from ECB*/

 

if (!array_key_exists(DEFAULT_CURRENCY, $exchrate)) {

return false; /* the Store Default currency must be present in the list because these exchange rates are based in 1EUR=xx

Therefore we need to calculate the rate from EUR to the Default currency and then from the Default currency to the destination currency */

}

 

if (!array_key_exists($to, $exchrate)) {

return false;

}

 

$DefaultCurr_to_EUR_Rate = round(1 / $exchrate[DEFAULT_CURRENCY], 8);

$DefaultCurr_to_DestCurr = round($DefaultCurr_to_EUR_Rate * $exchrate[$to], 8);

 

if (is_numeric($DefaultCurr_to_DestCurr) && $DefaultCurr_to_DestCurr > 0) { /* make sure we got a valid number */

return $DefaultCurr_to_DestCurr;

} else {

return false;

}

}

 

Save the file.

 

 

Step 2: Edit admin/includes/application_top.php

 

Find the line that starts with "define('CURRENCY_SERVER_PRIMARY', " and replace the whole line with:

define('CURRENCY_SERVER_PRIMARY', 'ECBank');

 

Save the file.

 

All done.

 

 

TESTING THE INSTALLATION:

 

Now go to the Admin section, select Localization and then Currencies.

Click Update.

 

You should see a message saying that all currencies were successfully updated via ECBank.

 

If you see an error about updating via ECBank, see the troubleshooting bellow:

 

 

 

TROUBLESHOOTING:

 

1) If you see an error when testing it may be caused by 2 things:

 

A) Your server is not being able to fetch the file from the EC bank.

B) There's a poorly written sanity check in the file admin/currencies.php that may cause these issues.

 

To fix case B) do this:

Edit admin/currencies.php

Find the line that says "if (tep_not_null($rate)) {" and replace the whole line with:

if (is_numeric($rate) && $rate > 0) {

 

Save the file and test again.

 

2) You may also want to adjust your Exchange Rate BACKUP server (in case the updating via the primary server - ECBank - fails).

In admin/includes/application_top.php

 

Find the line that looks like "define('CURRENCY_SERVER_BACKUP', 'XXXX');"

replace 'XXXX' with 'oanda' or 'xe' depending on which server you want to use as backup server.

 

 

I hope you find the contribution useful. :)

 

 

As always, BACKUP ALL FILES before modifying them.

Contributions used at your own risk. ( I will not be responsible for any direct or indirect damage or loss derived of using this contribution. )

 

Regards

Pedro

 

We use osCommerce Online Merchant v2.3.3 with OzPost MultiQuote and Paypal Website Payments Standard.

 

Hope someone can help with this and you understand my questions. All help appreciated.

Share this post


Link to post
Share on other sites

What is the question? What's the point posting the installation instructions? I suggest my addon, only because I know it works, which isn't to say the above doesn't.

Share this post


Link to post
Share on other sites

I have managed to install the above module, which is only made up of the instructions above.

 

My question was as stated above, is there a exchange module that operates in reverse?

 

The reason why I state I require it to run in reverse is because we purchase items from a supplier in the UK and all prices are in GBP. At the moment I have had to place all prices in our store as AUD at the exchange rate at the time. I suppose I need to know whether this is what I am supposed to do or place the GBP Price in our store even though the primary dollar is AUD.

 

Hope this makes sense.

 

Any help on this matter is appreciated.

Share this post


Link to post
Share on other sites

There's not an addon that does that, as far as I know. You could set GBP as the default currency and then the update code would work for AU but that probably isn't a good thing for the site since your customers would have to choose AU to see the cost in something they understand. The easy way would be if your supplier could provide AU prices, but they probably won't do that. If they offer the products in a list with the prices, it would not be too big a job to write a script to convert the prices using that list. There may be other ways but a lot of them, like these, would depend upon how you receive the list of products and their cost..

Share this post


Link to post
Share on other sites

@@Jack_mcs I get all the prices directly from the suppliers website as we only provide a small selection of their products. I am not that qualified in PHP so don't know how to write a script for what I need to do. I know it needs to be able to update the currency on a daily basis to keep up with the exchange rate and be able to change the British Pound to Australian Dollar and other currencies our store supports.

 

I know this is a big ask and don't even know that this is possible for a single category or set of products but keep the rest of the store set up to change the currency rate from the AUS Dollar.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×