How to update currency rates in OsCommerce store

A client of mine wanted to display product prices in US dollar, Canadian dollar, British pound and Australian dollar so that the customer could view prices in their own currencies. The default currency was set to Euro. Now anyone who has used Oscommerce or developed modules in it would know that this is quite a simple task and was not a lot of work. However the client wanted the currencies to be updated in real time.

I first browsed through the Oscommerce website add-on section and surely there were some good modules there for this purpose. However, after seeing some of the code which had been written in earlier versions of PHP I decided to write my own.

The rates were to be fetched from the European Central Bank website. The rates are updated on the website every couple of hours and people could use them to display the most recent rates to their customers. As the output was in XML I decided to use the SimpleXML object which allowed you to process the XML as an object in PHP.

The code fetches the currency rates and updates them in the currency table. You can even setup a cron job which can fetch the rates on a timely basis and update your database.

You can download the code from here

Leave a Comment