Jump to content
Jack_mcs

Auto Update Currencies

Recommended Posts

Hi Jack

 

I've made the code change you suggested (return $nhours; instead of return $ndays;). I have 'HOURS_BETWEEN_UPDATES' , '12' and the Cron job set to 4 hours. It still seems to be unreliable in updating currencies. Sometimes updating and other times claiming it was updated within the specified period when I know it was not.

 

Ken

Share this post


Link to post
Share on other sites

The only way for the code to update the currency is if it gets a valid response from one of the two currency converter sites it uses. There is no way to control if they respond or not. But if you are saying that the script says they were updated and they actually weren't, how are you determining that?

 

Jack

Share this post


Link to post
Share on other sites
The only way for the code to update the currency is if it gets a valid response from one of the two currency converter sites it uses. There is no way to control if they respond or not. But if you are saying that the script says they were updated and they actually weren't, how are you determining that?

 

Jack

 

It seems odd that I have three currencies to be updated. Sometimes the script says that two have been updated and one has not because it has been updated within the last time period. Since all three are subject to the same cron and script they should all either be updated or all stamped as updated at the same time shouldn't they?

 

Ken

Share this post


Link to post
Share on other sites

They are all attempted at the same time initially but if the currency converter sites don't return a new rate for all of them, which they won't each time, then the next time the script is ran, only some of them will need to be updated.

 

Jack

Share this post


Link to post
Share on other sites
They are all attempted at the same time initially but if the currency converter sites don't return a new rate for all of them, which they won't each time, then the next time the script is ran, only some of them will need to be updated.

 

Jack

 

Ah, fairy nuff.

Share this post


Link to post
Share on other sites

Hello all,

 

I am trying to use this contribution, but I don't understand the CRON job part.

 

Step 2: Add a cron job. The following syntax may not be correct for your server

(be sure to replace username). If not, you will need to contact your

host to get the correct syntax.

 

php /home/username/public_html/catalog/admin/auto_update_currencies.php

 

I never added a cron job, so I need a bit of more explanation. What do I do exactly? Do I fill this in into the address bar of my browser? php /home/username/public_html/catalog/admin/auto_update_currencies.php

 

My site is on a Apache server. The url is www.willy-condoms.com.

 

Hope someone can help!

 

Thanks in advance!

 

Regards,

Marleen

Share this post


Link to post
Share on other sites

I did a test with the script, and I came the following message appears to be an error, ie, the coins have not been updated.

 

Anyone know tell me how to fix the problem?

 

 

 

 

Telecartofilia Cards Digers

 

Currencies Update Report

 

Currencies for Telecartofilia Cards Digers updated on Fri Aug 14 3:00:17 2009

 

The exchange rate for Real WAS NOT successfully updated. It was last updated on

The exchange rate for U.S.Dollar WAS NOT successfully updated. It was last updated on

The exchange rate for Euro WAS NOT successfully updated. It was last updated on

The exchange rate for British Pound WAS NOT successfully updated. It was last updated on

Share this post


Link to post
Share on other sites

Try clicking on the Update Currencies button in admin->Localization->Currencies. If that doesn't work, the problem is with your server.

 

Jack

Share this post


Link to post
Share on other sites

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

 

Hi Jack,

 

I installed currency update, but I keep on receiving emails saying:

 

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.

 

Why is that? It has never worked.

 

Thanks,

Marleen

Share this post


Link to post
Share on other sites

Try changing this code

    $nhours = round($nseconds / 3600); // One hour has 3600 seconds

to this

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

Edited by Jack_mcs

Share this post


Link to post
Share on other sites

Hi Jack,

 

Thanks for all your useful contribs. I having trouble [server side] that doesn't allow the Auto Update Currencies to work properly. Neither, when one clicks update currencies button from the adim section. I had to resolve this issue by altering the localization.php so that the admin/update currencies button, funtions as per following:-

 

<?php  
function quote_oanda_currency($code, $base = DEFAULT_CURRENCY) {

$alte_url = "http://www.oanda.com/convert/fxdaily";
$alte_params = 'value=1&redirected=1&exch=' . $code .  '&format=CSV&dest=Get+Table&sel_list=' . $base;
$alte_user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";

$alte_ch = curl_init();
curl_setopt($alte_ch, CURLOPT_POST,1);   
curl_setopt($alte_ch, CURLOPT_POSTFIELDS,$alte_params);   
curl_setopt($alte_ch, CURLOPT_URL,$alte_url);   
curl_setopt($alte_ch, CURLOPT_SSL_VERIFYHOST, 2);   
curl_setopt($alte_ch, CURLOPT_USERAGENT, $alte_user_agent);   
curl_setopt($alte_ch, CURLOPT_RETURNTRANSFER,1);   
curl_setopt($alte_ch, CURLOPT_SSL_VERIFYPEER, FALSE);

$alte_page=curl_exec ($alte_ch);   
curl_close ($alte_ch);

$page = explode("\n",$alte_page);

	$match = array();        
	preg_match('/(.+),(\w{3}),([0-9.]+),([0-9.]+)/i', implode('', $page), $match);

	if (sizeof($match) > 0) {
	  return $match[3];
	} else {
	  return false;
	}
}

function quote_xe_currency($to, $from = DEFAULT_CURRENCY) {

$alte_url = "http://www.xe.net/ucc/convert.cgi";
$alte_params = 'Amount=1&From=' . $from . '&To=' . $to;
$alte_user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";

$alte_ch = curl_init();
curl_setopt($alte_ch, CURLOPT_POST,1);
curl_setopt($alte_ch, CURLOPT_POSTFIELDS,$alte_params);
curl_setopt($alte_ch, CURLOPT_URL,$alte_url);
curl_setopt($alte_ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($alte_ch, CURLOPT_USERAGENT, $alte_user_agent);
curl_setopt($alte_ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($alte_ch, CURLOPT_SSL_VERIFYPEER, FALSE);

$alte_page=curl_exec ($alte_ch);
curl_close ($alte_ch);

$page = explode("\n",$alte_page);

	$match = array();

	preg_match('/[0-9.]+\s*' . $from . '\s*=\s*([0-9.]+)\s*' . $to . '/', implode('', $page), $match);

	if (sizeof($match) > 0) {
	return $match[1];
	} else {
	return false;
	}
}
?>

 

This works very fine.

 

Could you instruct me how to amaned your contrib so that it could run as well, basis on the tips from the attached localization.php script.

 

With best regards

 

Proimage

Share this post


Link to post
Share on other sites

This contribution uses the localization.php so it should work with your changes.

Share this post


Link to post
Share on other sites

Hi Jack,

 

Thanks for your reply.

 

I always get this error, by email.

 

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.

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

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

United Kingdom Pound was not updated since it has been updated in the last 24 hours.

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

 

Then I have to resolve to update the currencies manually by clicking the admin, localization currencies, update button and see that the rates did change.

 

Still troubling... wish I could have it working.

 

Regs Proimage

Share this post


Link to post
Share on other sites

Try replacing these lines

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

   return $ndays;

with these

    $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;

Share this post


Link to post
Share on other sites

The only other thing I can think of is to try changing the HOURS_BETWEEN_UPDATES setting is set to 1.

Share this post


Link to post
Share on other sites

Is this still being updated?

 

I do not offer products for sale in difference currencies. I only sell in USD however the item I am selling needs to go up and down based on the rate of the euro. How could I have it do this and estable a basline price and have it move up and down from there in USD?

 

thanks

Share this post


Link to post
Share on other sites

Yes, it is still supported but your need does not fall within that support. Since it is chaning the price of a product, it doesn't really have anything to do with this contribution at all. What you want can be done but would require special coding since, I don't think, such a contribution exists.

Share this post


Link to post
Share on other sites

hi all

 

i just added the auto_update_currencies.php file to system and dont really understand what the cron stuff is

 

i have access to server etc but bit stuck re whats next

 

so on the install guide it say

 

Step 3: (optional) - If you can't get the cron job to run, or don't want to

use cron, insert the following at the very bottom of the admin/index.php

file:

 

<?php

include('auto_update_currencies.php');

?>

 

i have done this, does this mean the currancies will now update automatically or do i have to do anything else

 

mark

Share this post


Link to post
Share on other sites

hi all

 

i just added the auto_update_currencies.php file to system and dont really understand what the cron stuff is

 

i have access to server etc but bit stuck re whats next

 

so on the install guide it say

 

Step 3: (optional) - If you can't get the cron job to run, or don't want to

use cron, insert the following at the very bottom of the admin/index.php

file:

 

<?php

include('auto_update_currencies.php');

?>

 

i have done this, does this mean the currancies will now update automatically or do i have to do anything else

 

mark

Using that method, the script will run each time you go to the index page of admin, which is usually only when you login. If the currencies need updating at that time, it will do so.

Share this post


Link to post
Share on other sites

hi

 

thanks for your answer - i actually want the script to run everytime a customer is on site

 

what if i put the code in the root index file, would this update currancies everytime the website is reloaded

 

Mark

Share this post


Link to post
Share on other sites

thanks for your answer - i actually want the script to run everytime a customer is on site

 

what if i put the code in the root index file, would this update currancies everytime the website is reloaded

Oh, that is not a good idea. If you get one visitor a day it wouldn't make any difference. But if you get 50 an hour, that could cause your site to be so slow it would not be usable. not to mention the companies that provide the conversions would probably block your site. I realize rates change many times a day but updatnig more than once an hour is probably overkill. The best approach would be to use cron, since that is really what it is meant for. But if you want to put it on your shops side, it would need to go in the includes/application_top.php file and there should be some code added to store the last value and to check the elapsed time so calls to the conversion sits are limited and your site is not slowed down too much.

Share this post


Link to post
Share on other sites

Thanks

 

good point

 

then cron it is for daily update

 

in the instructions it says

 

--------------------------------------------------------------------------

Step 2: Add a cron job. The following syntax may not be correct for your server

(be sure to replace username). If not, you will need to contact your

host to get the correct syntax.

 

php /home/username/public_html/catalog/admin/auto_update_currencies.php

 

so - how do i actually do this as i have never added a cron job before - it is just uploaded a file??

 

i have full ftp access to the site and can log on to hosting site control panel

 

mark

Share this post


Link to post
Share on other sites

Thanks

 

good point

 

then cron it is for daily update

 

in the instructions it says

 

so - how do i actually do this as i have never added a cron job before - it is just uploaded a file??

 

i have full ftp access to the site and can log on to hosting site control panel

It varies with the host so I can't be specific. But, first, cron has to be installed and enabled on your server. If it is, there should be a way to reach it in your control panel. Once you reach it, you enter in the correct syntax and set the time for it to run. The file it is to run is already on your server, if you installed this contribution correctly. If you can't find cron in your control panel of can but can't figure out how to use it, you will need to contact your host for instructions.

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

×