osCommerce and osCMax shopping cart software forums

Shopping Cart Software

osCommerce with teeth!

 
 

Auto Update Currency Exchange Rate

This is a discussion on Auto Update Currency Exchange Rate within the New osCommerce Contributions forums, part of the osCommerce 2.2 Forums category; The code has two parts, the 1st part is reading exchange rate and make a catch file in your web ...


Go Back   osCommerce and osCMax shopping cart software forums > osCommerce 2.2 Forums > New osCommerce Contributions

Register FAQ Members List Calendar Mark Forums Read


Free community membership! Fast easy FREE membership
Reply

 

LinkBack Thread Tools
  #1  
Old 02-13-2008, 12:11 AM
michael_s's Avatar
osCMax Developer

 
Join Date: Jul 2002
Location: Phoenix, AZ
Posts: 10,977
Thanks: 80
Thanked 345 Times in 324 Posts
Rep Power: 10
michael_s has a reputation beyond reputemichael_s has a reputation beyond reputemichael_s has a reputation beyond reputemichael_s has a reputation beyond reputemichael_s has a reputation beyond reputemichael_s has a reputation beyond reputemichael_s has a reputation beyond reputemichael_s has a reputation beyond reputemichael_s has a reputation beyond reputemichael_s has a reputation beyond reputemichael_s has a reputation beyond repute
Post Auto Update Currency Exchange Rate

The code has two parts, the 1st part is reading exchange rate and make a catch file in your web server. The 2nd part is updating your currency exchange rate.

Due to the exchange rate came from Euro bank, we need to do some calculations for other currency.

However, the code is written for GBP web site, therefore, little modification need to be made if you want to use USD or other currency as your default currency.

// Update Currency Rate

# Read currency exchanges rates
# Cache file if appropriate ...
if (time()-filemtime("eurofxref-daily.xml") > 36000) {
$stuff = file("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml");
$fh = fopen("eurofxref-daily.xml","w");
foreach ($stuff as $line) { fputs($fh,$line); }
fclose ($fh);
$xld = "loaded afresh (and not cached)";
} else {
# .. or read from cache
$stuff = file("eurofxref-daily.xml");
$xld = "cached (and not loaded afresh)";
}
# $xld may be used in your output to inform you user or admin
# Extract exchange rates
$exchrate[EUR] = 1.00;
foreach ($stuff as $line) {
ereg("currency='([[:alpha:]]+)'",$line,$gota);
if (ereg("rate='([[:graph:]]+)'",$line,$gotb)) {
$exchrate[$gota[1]] = $gotb[1];
}
}
// Get exchange rate for EUR based on your default currency.
$value1 = round(1 / $exchrate[GBP], 8); // Change $exchrate[***] to your default currency

// Get exchange rate for extra currency based on your default currency
$value2 = round($value1 * $exchrate[USD], 8); // Change $exchrate[***] to any other extra currency

tep_db_query("update currencies set value = ". $value1 ." where code = 'EUR'");

tep_db_query("update currencies set value = ". $value2 ." where code = 'USD'");
// Change ‘USD’ to any other currency you defined for value2


More...
__________________
Michael Sasek
osCMax Developer


  • osCMax Templates - Hundreds of premium quality templates designed for osCMax 2. Loyalty discounts up to 30% off!
    Each purchase supports the osCMax project with much needed funds!

  • xShop for osCMax - Windows Based osCMax administration. Improved workflow, security, speed and convenience.

  • osCMax Hosting - From basic hosting to High Availability, Load Balanced arrays, the most experienced osCMax host. Default multi server configuration for exceptional performance!

  • osCMax Template Tutorial - Learn how to make your own custom templates and how to use the powerful features of the osCMax template system.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Advertisement
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Auto Update Currency Exchange Rate michael_s New osCommerce Contributions 0 01-25-2008 07:12 AM
Currency exchange rates - auto-update? stuart@pantons.co.uk osCMax v2 Customization/Mods 0 05-08-2007 07:18 AM
Currency Update Frankie69 osCMax v2 Customization/Mods 6 05-25-2006 08:39 PM
Currency Update Error! Picman osCMax v1.7 Installation 2 02-28-2004 02:11 AM
currency won't update?? gellnsh osCommerce 2.2 Modification Help 0 09-18-2003 01:25 PM


All times are GMT -8. The time now is 09:30 AM.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO
http://www.oscmax.com/forums/
Copyright 2008 osCMax