Jump to content
Jack_mcs

Auto Update Currencies

Recommended Posts

hi

 

thanks for all your help on here

 

i set up a cron job - my hosting provider calls it scheduled tasks?? and it ran on time

 

i kept getting

 

US Dollar was not updated since it has been updated in the last 24 hours.

Euro was not updated since it has been updated in the last 24 hours.

Pounds was not updated since it has been updated in the last 24 hours.

 

so did what was suggested in this tread about changing the code

 

$nhours = round($nseconds / 3600) * (($ndays > 1) ? $ndays : 1); // One hour has 3600 seconds

$nseconds = $nseconds % 3600;

$nminutes = round($nseconds / 60); // One minute has 60 seconds, duh!

$nseconds = $nseconds % 60;

 

return $nhours;

 

and it works just great

 

if this is a common problem, does it need changing in the add on

 

anyhow - thanks for all the help and all up and running

 

mark

Share this post


Link to post
Share on other sites

I'm pleased to hear it is working for you. That change you made is already in the next version.

Share this post


Link to post
Share on other sites

PHP 5.3 and above has introduced a built in function - date_diff. That means trouble for auto_update_currencies.php as it has a function of the same name - so a 'cannot redeclare function date_diff' error results.

 

Just change the name of the function date_diff to something else (eg date_diffnce) and also amend the call on line 58 to use the new name.

 

Cheers

 

KD

Share this post


Link to post
Share on other sites

Hello Jack,

 

I am using your contrib since a couple of years now and everything was fine and I would like to thank you for this.

Now it seems that oanda has changed the path. When I update I have this error :

 

Warning: fsockopen() [function.fsockopen]: unable to connect to www.oanda.com:5011 (Connection refused) in /includes/functions/localization.php on line 16
Warning: fsockopen() [function.fsockopen]: unable to connect to www.oanda.com:5011 (Connection refused) in /includes/functions/localization.php on line 16
Warning: fsockopen() [function.fsockopen]: unable to connect to www.oanda.com:5011 (Connection refused) in /includes/functions/localization.php on line 16
Warning: fsockopen() [function.fsockopen]: unable to connect to www.oanda.com:5011 (Connection refused) in /includes/functions/localization.php on line 16
Currencies Update Report
Currencies updated on Thu Jun 7 10:26:45 2012
The exchange rate for US Dollar was not successfully updated.
The exchange rate for UK Pounds was not successfully updated.
The exchange rate for Euro was not successfully updated.
The exchange rate for Franc suisse was not successfully updated.

 

and here is ligne 16 of localization.php

 

$s = fsockopen('www.oanda.com', 5011, $err_num, $err_msg, 5);

 

I have just put away the complete path before the /include.

 

Do you know what should be changed in order for the code to go to the right path on www.oanda.com ?

 

Thank you for your help and have a nice day.

 

smalto

Edited by smalto

oscommerce 2.2 ms1 with contrib - lilibikini.com - 2005

Share this post


Link to post
Share on other sites

It still works for me and if i try updating currencies directly in admin, it also works and shows it was from oanda. Does that not happen for you?

Share this post


Link to post
Share on other sites

No it says that

unable to connect to www.oanda.com:5011 (Connection refused)

any clue to what has changed or what should be given as new path because it seems that it cannot connect to www.oanda.com:5011

 

Thank you for your help.

 

smalto


oscommerce 2.2 ms1 with contrib - lilibikini.com - 2005

Share this post


Link to post
Share on other sites

I just tried updating manually in my site and got this result:

 

The exchange rate for US Dollar (USD) was updated successfully via oanda.

The exchange rate for Pounds (GBP) was updated successfully via oanda.

 

Notihng has changed in that part of my shop for years so it seems oanda is working fine.

Share this post


Link to post
Share on other sites

hi Jack!

 

I'd like to install this contrib (in fact, I think I may used it years ago on a MS 2.2 site) but today I'm using 2.3.3.4

 

First, thanks for making this contrib! A couple Q's;

 

1) will this mod work on 2.3.3.4 ?

2) Is there any way to make it so that it checks the currency during the checkout process? To me, running a task to update the currency, let's say, 4 times per day and each time a person checks out would make the most sense (given that my site is not that busy)

 

Thanks very much~!


Best & Thanks;
Marvin
----------------------
osCommerce 2.3.3.4 

Share this post


Link to post
Share on other sites

I haven't tried it on a 2.3.3.4 shop so I can't say. But it uses MySQL calls, versus the shops MySQL overlays, so my guess Is no. As far as updating on the shop side, that seems like it could cause a problem with the customer. Most exchanges don't change that often but if a customer had a large total for their cart and then went to checkout and an update occurred, they might think you are trying to pull something. It may also slow the site down since the code does have to wait for the other sites to respond.

Share this post


Link to post
Share on other sites

Good points all - thanks for the reply Jack. Perhaps one day you'll be able to take a look at 2.3.3.4 and and massage it :)


Best & Thanks;
Marvin
----------------------
osCommerce 2.3.3.4 

Share this post


Link to post
Share on other sites

Hi Jack,

 

I just installed your addon - I have not set up a cronjob yet, but installed the code at the end of admin/index.php as instructed.

 

When I go into admin however I get this warning at the bottom of the page:

 

Fatal error: Cannot redeclare date_diff() in /home/creativ3/public_html/orders/admin/auto_update_currencies.php on line 44

 

And obviously, my currencies are not updated either.

 

Any ideas as to what is the problem?

Share this post


Link to post
Share on other sites

Hello bigbird_3156,

 

Take a look on the previous page, exactly the #57 message (thanks to kdenby) : http://forums.oscommerce.com/topic/323818-auto-update-currencies/page-3#entry1636500


Get the latest Responsive osCommerce CE (community edition) here .

(Live   : OsC 2.2, php 5.4 & UTF-8  |  Local : Phoenix for future shop)

Share this post


Link to post
Share on other sites

Hello bigbird_3156,

 

Take a look on the previous page, exactly the #57 message (thanks to kdenby) : http://forums.oscommerce.com/topic/323818-auto-update-currencies/page-3#entry1636500

Thanks for that,

 

I did look through the old posts but was more concerned with finding the same error message as I got so missed it all together!

Share this post


Link to post
Share on other sites

Sorry to post again so soon...

 

Do you know if there is an easy way to get the inverse values for the exchange rates?

 

I have a site set up with static prices for each foreign currency I use and I need this to convert them to AUD to charge the customer (yes they know that it happens this way).

Share this post


Link to post
Share on other sites

I don't understand what it is you want to do but this addon just updates the exchange rate so that $1US = $1AUS. You could install the Second Currency addon, so that both AUS and some other currency can be displayed at the same time on the site.

Share this post


Link to post
Share on other sites

Sorry, to explain a bit....

 

I am using AUD as my default currency, however I sell stock around the world at static prices in different currencies....

 

So something I sell in AUD for $8 I sell in USD for $6.60 and in GBP for $4.25 etc... these values stay the same ...

 

I have set this up with  the separate price per customer addon, and have modified my code so that the prices for the different currencies are not affected by the currency conversion ... however I now need to convert the static price (say USD$6.60 to AUD)...

 

to use this example if I have the default currency as AUD and convert the price using the current conversion rate 0.94030 I get a value of AUD $6.21 what I need to do is convert it using the inverse value (essentially converting Aussie dollars to US dollars) of 1.06394 to get a value of AUD $7.02

 

I need however to convert 4 different currencies to AUD for this all to work .. so I cannot set my default to USD (which would make the above example work)

 

Hopefully that makes sense????

- to clarify things a bit more ... if you look at this link on XE  http://www.xe.com/currencyconverter/convert/?Amount=1&From=AUD&To=USD&r=#rates
you will see that in the list they have 1AUD = USD 0.94030 and the inverse value of that is 1.06394.

 

I want the inverse value...

Share this post


Link to post
Share on other sites

Thanks, I understand now. There's nothing written for that that I am aware of. You could try editing the admin/includes/functions/localization.php file and change

function quote_xe_currency($to, $from = DEFAULT_CURRENCY) {
to
function quote_xe_currency($from = DEFAULT_CURRENCY, $to) {
I haven't tried it but it would be my first guess. If it works, you would also have to change the function for oanda. If that doesn't work, then the code in the update section of currencies.php could be altered to figure out the exchange rate, once retrieved, and then alter the calculation so it uses the inverse. Good luck. :)

Share this post


Link to post
Share on other sites

Is there any way to remove the HOURS_BETWEEN_UPDATES delay so that the Auto_update_currencies thing works instantaneously, I just want to get rid of it while I'm playing around with the code a bit so that I can test if it is working or not.

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

×