Jump to content



Photo
- - - - -

Auto Update Currencies


  • Please log in to reply
78 replies to this topic

#1   Jack_mcs

Jack_mcs
  • Members
  • 26,496 posts
  • Real Name:Jack York
  • Gender:Male
  • Location:Michigan

Posted 16 December 2008 - 13:30

If your shop offers more than one currency, you need this contribution. With excahnge rates changing daily, at times, it is important to keep them up-to-date. Many, if not most, shop owners are not aware that this needs to be done. This contribution can be ran as a cron job or semi-automatically and will handle the updates for you. The existing Update Currencies contribution uses an external site that has changed their policy which means the updates may not always work. It also uses code that will prevent cron jobs from working on all servers. This contribution uses changed code and the same sites that oscommerce has always used so those problems should not occur.

Jack

Edited by Jack_mcs, 16 December 2008 - 13:34.


#2   seb1188

seb1188
  • Members
  • 165 posts
  • Real Name:Sebastian Keany
  • Location:England, UK

Posted 28 December 2008 - 04:53

If your shop offers more than one currency, you need this contribution. With excahnge rates changing daily, at times, it is important to keep them up-to-date. Many, if not most, shop owners are not aware that this needs to be done. This contribution can be ran as a cron job or semi-automatically and will handle the updates for you. The existing Update Currencies contribution uses an external site that has changed their policy which means the updates may not always work. It also uses code that will prevent cron jobs from working on all servers. This contribution uses changed code and the same sites that oscommerce has always used so those problems should not occur.

Jack



i've given it a shot, but there seems to e a problem. roughly 1 in 5 (but random) currencies do not update?

Edited by seb1188, 28 December 2008 - 05:02.

osCommerce is GREAT. When it works...

#3   seb1188

seb1188
  • Members
  • 165 posts
  • Real Name:Sebastian Keany
  • Location:England, UK

Posted 28 December 2008 - 05:37

i've given it a shot, but there seems to e a problem. roughly 1 in 5 (but random) currencies do not update?



it's a problem with the servers. XE does not work at all anymore (they charge for it these days) and oanda seems to be giving in too.

anyone know of any other servers that can be used?
osCommerce is GREAT. When it works...

#4   Jack_mcs

Jack_mcs
  • Members
  • 26,496 posts
  • Real Name:Jack York
  • Gender:Male
  • Location:Michigan

Posted 28 December 2008 - 14:01

That was the reason I wrote it using those servers. My site upgrades all currencies every night without any failures but another that I installed this script into will upgrade some currencies on some tries and others at others. I can only guess that it is a busy server issue. All of the online services I checked are wanting subscriptions to be made. While some are free, even onanda, it makes setting up a contribution like this impossible. If anyone knows of a reliable, free site, please let me know and I will add it to the code. In the meantime, I suggest you use the email option in the script and monitor the updates. You may find that all of the currencies get updated - just not everytime.

Jack

#5   seb1188

seb1188
  • Members
  • 165 posts
  • Real Name:Sebastian Keany
  • Location:England, UK

Posted 28 December 2008 - 16:40

That was the reason I wrote it using those servers. My site upgrades all currencies every night without any failures but another that I installed this script into will upgrade some currencies on some tries and others at others. I can only guess that it is a busy server issue. All of the online services I checked are wanting subscriptions to be made. While some are free, even onanda, it makes setting up a contribution like this impossible. If anyone knows of a reliable, free site, please let me know and I will add it to the code. In the meantime, I suggest you use the email option in the script and monitor the updates. You may find that all of the currencies get updated - just not everytime.

Jack



i've just set my cron to run every hour... with 24 tries per day it's bound to get them all right at some point in 24 hours!!!! although that's probably what caused this issue in the first place... too many sites updating too often.

Edited by seb1188, 28 December 2008 - 16:41.

osCommerce is GREAT. When it works...

#6   seb1188

seb1188
  • Members
  • 165 posts
  • Real Name:Sebastian Keany
  • Location:England, UK

Posted 28 December 2008 - 18:21

I've found a few feeds you might want to look into. I've also foun a free API that looks REALLY useful:

http://xurrency.com/api

Check it out: if it's accurate and reliable it'd be really simple to use.


As for XML feeds:
The first is the European Central Bank, so uses the EUR as base rate (simple calculation can convert this to whatever):
http://www.ecb.int/s...fxref-daily.xml

Another website, currencysource.com, seems quite useful, though they only allow you to check each currency once every 15 minutes and don't update it at weekends (though for the most part forex doesn't chnage at weekends, as its only Australia that really trades on our Sundays, and a few weirdos in Claifornia trading on Saturday mornings...):
http://www.currencys...hangerates.html

Don't know much about this one, just where it is, but it's especially useful as it doesn't use only one base rate:
http://www.webservic...;ToCurrency=GBP
obviously GBP and USD would be replaced with variables to get any currency you want...

Bank of Canada (so CAD is only base rat available):
http://www.bankofcan...tes/rss_fx.html

Edited by seb1188, 28 December 2008 - 18:26.

osCommerce is GREAT. When it works...

#7   Jack_mcs

Jack_mcs
  • Members
  • 26,496 posts
  • Real Name:Jack York
  • Gender:Male
  • Location:Michigan

Posted 29 December 2008 - 04:30

Thanks for the links. I'll test them out at some point.

Jack

#8   apilon45

apilon45
  • Members
  • 20 posts
  • Real Name:Alain Pilon

Posted 29 December 2008 - 05:24

If your shop offers more than one currency, you need this contribution. With excahnge rates changing daily, at times, it is important to keep them up-to-date. Many, if not most, shop owners are not aware that this needs to be done. This contribution can be ran as a cron job or semi-automatically and will handle the updates for you. The existing Update Currencies contribution uses an external site that has changed their policy which means the updates may not always work. It also uses code that will prevent cron jobs from working on all servers. This contribution uses changed code and the same sites that oscommerce has always used so those problems should not occur.

Jack



Good evening

I installed your contribution and set up a cron job via cpanel and set the permission to 755 on the file and now this is what i am getting

/home/digitalh/public_html/admin/auto_update_currencies.php: line 1: ?: No such file or directory
/home/digitalh/public_html/admin/auto_update_currencies.php: line 2: /aquota.user: Permission denied
/home/digitalh/public_html/admin/auto_update_currencies.php: line 3: Auto: command not found
/home/digitalh/public_html/admin/auto_update_currencies.php: line 4: osCommerce,: command not found
/home/digitalh/public_html/admin/auto_update_currencies.php: line 5: http://www.oscommerce.com: No such file or directory
/home/digitalh/public_html/admin/auto_update_currencies.php: line 7: syntax error near unexpected token `c'
/home/digitalh/public_html/admin/auto_update_currencies.php: line 7: ` Copyright © 2003 osCommerce'

any help would be appreciated


Alain

#9   Jack_mcs

Jack_mcs
  • Members
  • 26,496 posts
  • Real Name:Jack York
  • Gender:Male
  • Location:Michigan

Posted 29 December 2008 - 12:58

That isn't a problem with the contribution. It is failing before it even loads the file. My guess is that either the file was corrupted when uploaded or your server is setup somehow to prevent it from working. If the script runs when ran manually, http://yoursite.com/..._currencies.php, then the problem is with cron and you will need to talk to your host. If it fails the same way, then try replacing the script.

Jack

#10   PLByrne

PLByrne
  • Members
  • 9 posts
  • Real Name:P Byrne

Posted 29 December 2008 - 14:06

Good evening

I installed your contribution and set up a cron job via cpanel and set the permission to 755 on the file and now this is what i am getting

/home/digitalh/public_html/admin/auto_update_currencies.php: line 1: ?: No such file or directory
/home/digitalh/public_html/admin/auto_update_currencies.php: line 2: /aquota.user: Permission denied
/home/digitalh/public_html/admin/auto_update_currencies.php: line 3: Auto: command not found
/home/digitalh/public_html/admin/auto_update_currencies.php: line 4: osCommerce,: command not found
/home/digitalh/public_html/admin/auto_update_currencies.php: line 5: http://www.oscommerce.com: No such file or directory
/home/digitalh/public_html/admin/auto_update_currencies.php: line 7: syntax error near unexpected token `c'
/home/digitalh/public_html/admin/auto_update_currencies.php: line 7: ` Copyright © 2003 osCommerce'

any help would be appreciated


Alain

It looks like it isn't executing it as PHP... try entering this in the cron box:

php /home/digitalh/public_html/admin/auto_update_currencies.php
I'm guessing that you haven't got the php bit at the front [img]http://forums.oscommerce.com/style_emoticons/default/smile.gif[/img]

#11   apilon45

apilon45
  • Members
  • 20 posts
  • Real Name:Alain Pilon

Posted 29 December 2008 - 18:25

It looks like it isn't executing it as PHP... try entering this in the cron box:

php /home/digitalh/public_html/admin/auto_update_currencies.php
I'm guessing that you haven't got the php bit at the front [img]http://forums.oscommerce.com/style_emoticons/default/smile.gif[/img]



Thanks it solved the problem

#12   TOG

TOG
  • Members
  • 3 posts
  • Real Name:Leon

Posted 05 January 2009 - 15:46

Hey Guys, I've done the installation and set the Cronjob but get the following result:

/bin/sh: -c: line 0: syntax error near unexpected token `newline'
/bin/sh: -c: line 0: `/home/httpd/cgi-bin/php4 <auto_update_currencies.php>'


My ISP has given me the following info:

1. To run a PHP 4 script. use the following: "/home/httpd/cgi-bin/php4 <filename>"
2. To run a PHP 5 script. use the following: "/home/httpd/cgi-bin/php5 <filename>"
3. To run a bash script, use the following: "/bin/bash <filename>"



This is the Cronjob command I used:

/home/httpd/cgi-bin/php4 <auto_update_currencies.php>


Can you help me with this error?

(I'm not too clued-up, so be gentle please)
Regards,
Leon

Edited by TOG, 05 January 2009 - 15:58.


#13   Jack_mcs

Jack_mcs
  • Members
  • 26,496 posts
  • Real Name:Jack York
  • Gender:Male
  • Location:Michigan

Posted 05 January 2009 - 16:18

You have to give it the path to the file. Go to admin->modules and the full path will be listed on the page. Copy that and change it so it ends in admin/auto_update_currencies.php.

Jack

#14   TOG

TOG
  • Members
  • 3 posts
  • Real Name:Leon

Posted 06 January 2009 - 09:22

You have to give it the path to the file. Go to admin->modules and the full path will be listed on the page. Copy that and change it so it ends in admin/auto_update_currencies.php.

Jack



Thanks Jack,

(My domain is www.leon.co.za)

I'm now trying this:
/home/httpd/cgi-bin/php4/leon/catalog/admin/auto_update_currencies.php

and getting this:
/tmp/cron_run_command_leon.sh: line 3: /home/httpd/cgi-bin/php4/leon/catalog/admin/auto_update_currencies.php: Not a directory

Or trying this:
/home/httpd/cgi-bin/php4 <leon/catalog/admin/auto_update_currencies.php>

I'm getting this:
/tmp/cron_run_command_leon.sh: line 3: syntax error near unexpected token `newline'
/tmp/cron_run_command_leon.sh: line 3: `/home/httpd/cgi-bin/php4 <leon/catalog/admin/auto_update_currencies.php>'

Can't figure it out...

Appretiating your help!

#15   Jack_mcs

Jack_mcs
  • Members
  • 26,496 posts
  • Real Name:Jack York
  • Gender:Male
  • Location:Michigan

Posted 06 January 2009 - 13:14

The usual structure is
"path to php" "space" "path to file"
Your host told you the path to php:
/home/httpd/cgi-bin/php4
so add a space after it and place the full path
/home/httpd/cgi-bin/php4 /home/leon/catalog/admin/auto_update_currencies.php

I don't know that the second part is correct. As mentioned, you have to get that from the admin section. If it isn't correct, then you need to ask your host. That's what they are there for.

Jack

Edited by Jack_mcs, 06 January 2009 - 13:15.


#16   Jack_mcs

Jack_mcs
  • Members
  • 26,496 posts
  • Real Name:Jack York
  • Gender:Male
  • Location:Michigan

Posted 08 January 2009 - 02:55

A new version has been uploaded. The following has been change:

- Reversed order of servers being checked since xe.com seems to provide quicker updates. These are settable in the file
so they can be switched back if desired.
- Added date checked code so that the updates are not attempted if an update has already been done within a certain number of hours. That number is settable in the file.

Jack

#17   seb1188

seb1188
  • Members
  • 165 posts
  • Real Name:Sebastian Keany
  • Location:England, UK

Posted 08 January 2009 - 08:58

A new version has been uploaded. The following has been change:

- Reversed order of servers being checked since xe.com seems to provide quicker updates. These are settable in the file
so they can be switched back if desired.
- Added date checked code so that the updates are not attempted if an update has already been done within a certain number of hours. That number is settable in the file.

Jack


In this new version, is the date checked only set if the update was succesful (and not when the update runs, but doesn't work)?

If so, great work, solves a lot of problems!

Thanks.
osCommerce is GREAT. When it works...

#18   Jack_mcs

Jack_mcs
  • Members
  • 26,496 posts
  • Real Name:Jack York
  • Gender:Male
  • Location:Michigan

Posted 08 January 2009 - 11:38

I'm not sure I understand your question but here is what it does. When the script is ran, it reads in the last update value from the database for each currency. If the last update is more than the time value option in the file, the outdated currecny is checked. If it is successfully updated, the database last update value is updated. Otherwise it is not changed so the next time the script is ran, that currecny will be checked again.

Jack

#19   Jack_mcs

Jack_mcs
  • Members
  • 26,496 posts
  • Real Name:Jack York
  • Gender:Male
  • Location:Michigan

Posted 08 January 2009 - 16:04

I just realized there is a slight mistake in the code. The line in the file that reads
return $ndays;
should be changed to
return $nhours;


Jack

#20   BlindingLight

BlindingLight
  • Members
  • 72 posts
  • Real Name:MR. Ed
  • Gender:Male
  • Location:Sunny Florida

Posted 10 January 2009 - 08:06

I just realized there is a slight mistake in the code. The line in the file that reads

return $ndays;
should be changed to
return $nhours;


Jack


Maybe this is not related to this contribution but i have this problem -> Warning: file() [function.file]: URL file-access is disabled in the server configuration in /nfs/c03/h04/mnt/56589/domains/html/admin/includes/functions/localization.php on line 14

This what I see every time I click on update and this is the same problem i get from the cron job.
Any idea?