Forums / All Other Contributions/Addons / Currency Update (Automatic)

Currency Update (Automatic)

Views: 82,431

Results 81 to 100 of 298
18 Dec 2008, 3:29 AM
#81
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Currency Update (Automatic)

naturesartandgifts:

Any chance someone will come up with an updated version using CURL to access European Central Bank? My server has allow_url_fopen disabled for security purposes. Thank you all.

The built-in currency update button works with CURL, and the ECB option is now part of the v1.4.0 core with CURL support. Just one more good thing about the next version, due out soon :)

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

18 Dec 2008, 10:50 PM
#82
dayo avatar

dayo

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
1

Re: Currency Update (Automatic)

DrByte:

The built-in currency update button works with CURL, and the ECB option is now part of the v1.4.0 core with CURL support. Just one more good thing about the next version, due out soon :)

It is worth noting that unlike the Oanda and XE, the ECB based only publishes reference rates for a select set of currencies. If a user has a currency outside that set, the code sets the rate to 0 which can cause users some grief.

It is necessary to escape updating any currency that returns a null value and perhaps sending the site admin an email to inform of this issue.

18 Dec 2008, 11:26 PM
#83
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Currency Update (Automatic)

Agreed. And I certainly wouldn't recommend use of this mod for currencies not reported by the ECB. There's a link in the readme file bundled with the mod so that people can check what the currently reported currencies are.

That said, companies with access to the relevant foreign exchange information know that it is valuable and are generally trying to offer it at a price.

The ECB list was way ahead of the others that I could find that could be legitimately used in this way for this purpose. But if anybody knows of better, or even different, please do tell. Zen Cart's code is designed to support multiple provides of this information, so more sources could be added to fill in the gaps.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

19 Dec 2008, 6:16 AM
#84
dayo avatar

dayo

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
1

Re: Currency Update (Automatic)

Kuroi

Thanks for the work done. I only posted this because I read DrBytes' post that the mod was being included in the upcoming release.

You are correct that the ECB seems to actually encourage web developers to use them legally and I can't think of any other legit source.

Perhaps you can edit the mod to escape null rates. Something like below.

if ($rate != 0)
{
  $updateSql = "UPDATE " . TABLE_CURRENCIES . "
            SET value = '" . $rate . "',
            last_updated = now()
            WHERE currencies_id = '" . $currency['currencies_id']. "'";
  mysql_db_query(DB_DATABASE, $updateSql, $link);
}

Simply skipping such rates might be better than setting them to zero.

7 Jan 2009, 10:35 AM
#86
whitt avatar

whitt

New Zenner

Join Date:
Aug 2008
Posts:
29
Plugin Contributions:
0

Re: Currency Update (Automatic)

What are the improvements of this new curled version v3.1 over the previous v2.0.1

Is it worth me replacing my current one?

7 Jan 2009, 12:55 PM
#87
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Currency Update (Automatic)

whitt:

What are the improvements of this new curled version v3.1 over the previous v2.0.1

Is it worth me replacing my current one?It does away with screen scraping, is more future proof, is the apporach now built into Zen Cart 2.0 and is legal. But it has less currencies.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

7 Jan 2009, 8:07 PM
#88
whitt avatar

whitt

New Zenner

Join Date:
Aug 2008
Posts:
29
Plugin Contributions:
0

Re: Currency Update (Automatic)

Thanks. I found some info in the readme file also.

I copy pasted the script into my old one then changed location line 17 to my server root etc. ( i used the location from old script and place between the ' ' )

It seems to work Ok.

Thank you

23 Jan 2009, 8:05 AM
#89
goninja avatar

goninja

New Zenner

Join Date:
Jan 2009
Posts:
71
Plugin Contributions:
0

Re: Currency Update (Automatic)

Where can I adjust the spread?

(The difference between the actual rate and the one that is posted on the website?)

Thanks!

23 Jan 2009, 9:17 AM
#90
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Currency Update (Automatic)

GoNinja:

Where can I adjust the spread?Admin > Configuration > My Store > Currency Conversion Ratio

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

28 Jan 2009, 2:57 AM
#91
coolcarpartsonline avatar

coolcarpartsonline

Totally Zenned

Join Date:
Feb 2008
Posts:
1,386
Plugin Contributions:
0

Re: Currency Update (Automatic)

Hello Kuroi
I am trying to get this mod working on my site but I keep getting errors when I run the cron job.

I have a few websites on the same hosting package. Is it possible to get this to work with all the different website Knowing that they are all using Zen cart 1.38a?
At the moment I am trying to test the cron job on one website. but I keep getting an error in the cron job > Warning: require_once(/ohiospeedshop/includes/configure.php) [function.require-once]: failed to open stream: No such file or directory in /home/coolcarp/public_html/currency_update_curled.php on line 20

Fatal error: require_once() [function.require]: Failed opening required '/ohiospeedshop/includes/configure.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/coolcarp/public_html/currency_update_curled.php on line 20
I have the file in the root of the public html ( /public_html/currency_update_curled.php/) The website I am trying to install this mod on is an addon domain so the link to the site is /public_html/ohiospeedshop/
This is the code I am using on my site ```

<?php /** * Automatic Currency Update v3.0 * Originally by Richard Fink (masterblaster) based on Zen Cart manual currency update * updated by Kuroi to include Zen Cart's currency uplift ratio * further updated by Kuroi to use European Central Bank reference rates (adapted from ECB-supplied code) * * @package currencies * @copyright Copyright 2003-2006 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version $Id: currency_update.php 1 2008-12-16 12:47:23Z kuroi $ */ // This describes the path from the location where you install this file to the root directory of your Zen Cart // It is normally the only line that you will need to edit. See readme for guidance. DEFINE('PATH_TO_STORE_ROOT','/ohiospeedshop/'); // Get Zen Cart configuration data require_once(PATH_TO_STORE_ROOT . 'includes/configure.php'); require_once(PATH_TO_STORE_ROOT . 'includes/database_tables.php'); //connet to database $link = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die("Could not connect"); //get default currency $currency_default = mysql_db_query(DB_DATABASE, "select configuration_value from " . TABLE_CONFIGURATION . " WHERE configuration_key='DEFAULT_CURRENCY' LIMIT 1 ", $link); $currency_default= mysql_fetch_array($currency_default); define('DEFAULT_CURRENCY', $currency_default[0]); //get currency conversion ratio $currency_uplift_ratio = mysql_db_query(DB_DATABASE, "select configuration_value from " . TABLE_CONFIGURATION . " WHERE configuration_key='CURRENCY_UPLIFT_RATIO' LIMIT 1 ", $link); $currency_uplift_ratio= mysql_fetch_array($currency_uplift_ratio); define('CURRENCY_UPLIFT_RATIO', $currency_uplift_ratio[0]); // Define currency file $ECBFile = "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"; $XMLContent = @file($ECBFile); if (!is_array($XMLContent) && function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $ECBFile); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $XMLContent = explode("\n", curl_exec ($ch)); curl_close($ch); } $currencyArray['EUR'] = 1; foreach ($XMLContent as $line) { if (ereg("currency='([[:alpha:]]+)'",$line,$currencyCode)) { if (ereg("rate='([[:graph:]]+)'",$line,$rate)) { $currencyArray[$currencyCode[1]] = (float)$rate[1]; } } } if (sizeof($currencyArray) > 1) { $currencyQuery = mysql_db_query(DB_DATABASE, "select currencies_id, code from " . TABLE_CURRENCIES . "", $link); while ($currency = mysql_fetch_array($currencyQuery)) { if ($currency['code'] == DEFAULT_CURRENCY) { $rate = 1; } else { $rate = ($currencyArray[$currency['code']] / $currencyArray[DEFAULT_CURRENCY]) * CURRENCY_UPLIFT_RATIO; } $updateSql = "UPDATE " . TABLE_CURRENCIES . " SET value = '" . $rate . "', last_updated = now() WHERE currencies_id = '" . $currency['currencies_id']. "'"; mysql_db_query(DB_DATABASE, $updateSql, $link); } } mysql_close($link); ?>
I am sure I have something wrong somewhere maybe you can help?
28 Jan 2009, 7:09 AM
#92
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

Re: Currency Update (Automatic)

Glamorousshoe:

DEFINE('PATH_TO_STORE_ROOT','/ohiospeedshop/');


wouldn't the PATH_TO_STORE_ROOT need to be '/home/coolcarp/public_html/ohiospeedshop/'?

EDIT: I just checked mine and I have'./' for my root directory so you would need './ohiospeedshop/' but maybe I've always had it wrong and never noticed! :-)


Zen Cart and it's community are the best!!

2 Feb 2009, 2:31 AM
#93
tj1 avatar

tj1

Totally Zenned

Join Date:
Mar 2005
Location:
California
Posts:
628
Plugin Contributions:
0

Re: Currency Update (Automatic)

Hi, just a quick question, it is better to use the curled version by Nogal (post #85) than the one in the download area, correct?

2 Feb 2009, 8:58 AM
#94
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Currency Update (Automatic)

I haven't looked at the curled version, but if it works for you, go with it. It's less likely to stop working in the future as a result of upgrades by your host.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

8 Feb 2009, 3:46 AM
#95
electrobumps avatar

electrobumps

New Zenner

Join Date:
Feb 2009
Posts:
29
Plugin Contributions:
0

Re: Currency Update (Automatic)

Hi I have just uploaded currency_update_curled.php

I wrote on line 17 DEFINE('/public_html/magicmods','');

I created a a Cronjob

a Table shows

https://www.magicmods.com/images/Cron.tiff

It doesn't seem to work, I've put my email in but I'm not getting any error logs sent to me.

Are my paths correct?

Thanks
Iain

8 Feb 2009, 6:44 AM
#96
tj1 avatar

tj1

Totally Zenned

Join Date:
Mar 2005
Location:
California
Posts:
628
Plugin Contributions:
0

Re: Currency Update (Automatic)

I think you need to put the full path, something like
/home/username/public_html/magicmods

for the cronjob, again, you might need the full path plus might also need to define php.
Something like:
php /home/username/public_html/magicmods/currency_update_curled.php

8 Feb 2009, 11:09 AM
#97
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Currency Update (Automatic)

Electrobumps:

Hi I have just uploaded currency_update_curled.php

I wrote on line 17 DEFINE('/public_html/magicmods','');

I created a a Cronjob

a Table shows

https://www.magicmods.com/images/Cron.tiff

It doesn't seem to work, I've put my email in but I'm not getting any error logs sent to me.

Are my paths correct?

Thanks
IainTry

DEFINE('PATH_TO_STORE_ROOT','magicmods/');

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

18 Feb 2009, 6:46 AM
#98
goninja avatar

goninja

New Zenner

Join Date:
Jan 2009
Posts:
71
Plugin Contributions:
0

Re: Currency Update (Automatic)

Just to double check... the ECB site that the live currency add-on uses... only updates once per day??

So is there a faster way to test if it's actually working besides waiting until tommorow?

18 Feb 2009, 9:41 AM
#99
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Currency Update (Automatic)

Correct. For testing you could set the CRON to run more frequently and edit the rates manually in your database.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

21 Feb 2009, 12:33 AM
#100
goninja avatar

goninja

New Zenner

Join Date:
Jan 2009
Posts:
71
Plugin Contributions:
0

Re: Currency Update (Automatic)

It's not working... where do I start to debug?