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

Currency Update (Automatic)

Views: 82,431

Results 281 to 298 of 298
1 Jul 2014, 10:45 PM
#281
rocco_habit avatar

rocco_habit

New Zenner

Join Date:
May 2014
Location:
United States
Posts:
14
Plugin Contributions:
0

Currency Update (Automatic)

Hello, I have a question about this module.

To start, I used the info that GizmoTronic provided in post #270.
My store is based in the United States, so I changed the info in the php file that is uploaded to the server on lines 53 and 82 to USD.

I have it all setup correctly and it seems to be functioning to update the currencies. The problem I am running into is it is updating them to an incorrect dollar amount. If I push the button in Zen Cart for "Updating Currencies" it updates them to the correct and current amounts at that particular time of day. So the zen cart built in feature is working correctly.

But, when I have the Cron Job setup to process the auto currency updater, It is setting the currency values to a completely incorrect number. Here are the before and after rates.

Before:
AUD = 1.05778
CAD = 1.06567
EUR = .73056692
GBP = .583065
USD = 1.00000

After the Cron Job executes the Currency Updater the currencies come back as this:
AUD = 1.4479006
CAD = 1.4586994
EUR = .73056692
GBP = .79809999
USD = 1.0000000

The first thing I noticed was the Euro wasn't changed at all, and it remains the correct currency rate. All the other ones except the Euro and the USD were affected and gave back a completely incorrect currency rate.

Does anyone have any suggestions on what the issue could be with this?

I really appreciate anyone who has an input on solving this issue.
Thanks in advance!
Chris

2 Jul 2014, 1:12 AM
#282
rocco_habit avatar

rocco_habit

New Zenner

Join Date:
May 2014
Location:
United States
Posts:
14
Plugin Contributions:
0

Re: Currency Update (Automatic)

Well, To respond to my above question. I think I figured out a solution that will work. I don't know if it is correct, but it works.

So, Above I mentioned that I changed the .php file that you upload to your server. I put in USD in place of EUR. I figured it would be worth changing this around and see what happened. I put it back to EUR and still left my Zen Cart Default currency to USD and sure enough it is updating correctly now.

I manually changed all the currencies that I have in Zen Cart to very incorrect figures. (changed AUD from 1.05 to 1.55, ETC) I setup the Cron Jobs to perform the currency update a few minutes later and sure enough it updated all the currencies back to their correct amounts. I tried it two times and worked correctly both times. So I am going to setup the cron job to run every day at 7am and see what happens.

If anyone has any input though, I would be more than happy to hear what others have to say about this.

Thanks,
Chris

25 Oct 2015, 4:48 AM
#283
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Currency Update (Automatic)

This is listed as the official support thread for the Automatic Currency Updater.

I'm noticing TWD isn't being updated. I also notice that ECB doesn't have TWD, is that why? It is a PayPal currency and those, at the very least, should all be supported, no? Or am I just missing something? Thanks.

25 Oct 2015, 5:32 AM
#284
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Currency Update (Automatic)

s_mack,
You can add a new currency in your admin

Zen-Venom Get Bitten

25 Oct 2015, 6:17 AM
#285
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Currency Update (Automatic)

not my point... I DO have the currency in admin... it doesn't get updated. I've looked into it further and yes, it is because this mod and, in fact, the core files themselves, are reliant on a very limited set of data. They chose to use ECB which only provides data for about 30 currencies... there are over 160 in use in the world.

25 Oct 2015, 6:35 AM
#286
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Currency Update (Automatic)

For those interested in a more expanded set of currencies, here is my version. Note that you have to sign up (free) for an API key at openexchangerates.org and enter that in.

<?php
/*
 * Automatic Currency Update v6.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)
 * updated by Zen4All (design75) use Zen Cart standard coding
 *
 * Rework for PHP 5.3 compatibility (ereg and mysql_db_query functions deprecated in PHP 5.3.0)
 * switched to using SimpleXML and mysqli instead.
 * JeRo www.jero.co.nz 18/06/2010
 *
 * modified by s_mack to use openexchangerates instead of very limited ECB. Simplified some logic.
 * license: GNU Public License V2.0
 *
 */

require_once('includes/application_top.php');
//  Sign up for openechangerates.org API and enter your ID below
$openexhangeratesapi = "";
/*
 *  Get default currency.
 */
$defaultCurrency = $db->Execute("SELECT configuration_value
                                FROM " . TABLE_CONFIGURATION . "
                                WHERE configuration_key = 'DEFAULT_CURRENCY' LIMIT 1 ");

$defaultCurrency = $defaultCurrency->fields['configuration_value'];

/* 
 * Get currency conversion ratio.
 */
$currencyUpliftRatio = $db->Execute("SELECT configuration_value
                                     FROM " . TABLE_CONFIGURATION . "
                                     WHERE configuration_key = 'CURRENCY_UPLIFT_RATIO' LIMIT 1 ");

//grab the full dataset from openechangerates.org

$currency_data = file_get_contents('http://openexchangerates.org/api/latest.json?app_id=' . $openexhangeratesapi);
$currency_data = json_decode($currency_data, true);

//since USD is not represented in the dataset, lets push it in
$currency_data['USD'] = 1;


// extract your default currency's exchange rate.

$defaultRate = (float)$currency_data['rates'][$defaultCurrency];

// put each currency into the DB, adjusted with the currency uplift ratio

foreach ($currency_data['rates'] as $code => $rate) {
  $rate = ( $code == $defaultCurrency ? 1 : (float)$rate * $currencyUpliftRatio->fields['configuration_value'] / $defaultRate );
  $sql_data_array = array('value' => $rate,
                          'last_updated' => 'now()',
                          'code' => $code);
  zen_db_perform(TABLE_CURRENCIES, $sql_data_array, 'update', "code = '" . $code . "'");
}

You'll notice in the comments I took the liberty of calling this V6 and adding my name... I did rewrite a bit of the logic to clean it up, in my opinion, as it was sort of making redundant-ish calls. Not important. I'm not uploading it to the downloads section so use or don't.

4 Dec 2015, 12:47 AM
#287
vanhorn_s avatar

vanhorn_s

Zen Follower

Join Date:
Apr 2010
Posts:
283
Plugin Contributions:
0

Re: Currency Update (Automatic)

I just updated to 6.0 a couple of days ago, and the email I receive back from my host has errors in it:

/home2/redsauto/public_html/currency_update.php: line 1: ?php: No such file or directory
/home2/redsauto/public_html/currency_update.php: line 2: /0: Permission denied
/home2/redsauto/public_html/currency_update.php: line 3: access-logs: command not found
/home2/redsauto/public_html/currency_update.php: line 4: syntax error near unexpected token (' /home2/redsauto/public_html/currency_update.php: line 4: * Originally by Richard Fink (masterblaster) based on Zen Cart manual currency update'

This makes no sense whatsoever.

V6.0:

<?php
/*
 * Automatic Currency Update v5.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)
 * updated by Zen4All (design75) use Zen Cart standard coding
 *
 * Rework for PHP 5.3 compatibility (ereg and mysql_db_query functions deprecated in PHP 5.3.0)
 * switched to using SimpleXML and mysqli instead.
 * JeRo www.jero.co.nz 18/06/2010
 *
 * license: GNU Public License V2.0
 *
 */

require_once('includes/application_top.php');

V5.0:

#!/usr/bin/php
<?php

/**
 * Automatic Currency Update v4.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)
 *
 * Rework for PHP 5.3 compatibility (ereg and mysql_db_query functions deprecated in PHP 5.3.0)
 * switched to using SimpleXML and mysqli instead.
 * JeRo www.jero.co.nz 18/06/2010
 *
 * license: GNU Public License V2.0
 *
 **/

# Set this to the physical path of your installation.
# Make sure to include the trailing "/"
define('PATH_TO_STORE_ROOT','');

It looks like it is trying to execute the commented out section, and is not recognizing the <?php

4 Dec 2015, 2:08 AM
#288
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Currency Update (Automatic)

Looks to me like you simply didn't copy the very first character of the code

4 Dec 2015, 2:59 PM
#289
vanhorn_s avatar

vanhorn_s

Zen Follower

Join Date:
Apr 2010
Posts:
283
Plugin Contributions:
0

Re: Currency Update (Automatic)

s_mack:

Looks to me like you simply didn't copy the very first character of the code
Do you mean this:

#!/usr/bin/php

That's not in the newest version. How I posted it, is exactly like I downloaded it.
Also, I got the version numbers wrong in my previous post. The correct versions are in the code.

4 Dec 2015, 3:43 PM
#291
vanhorn_s avatar

vanhorn_s

Zen Follower

Join Date:
Apr 2010
Posts:
283
Plugin Contributions:
0

Re: Currency Update (Automatic)

Design75:

#!/usr/bin/php

> Was used in version 4 and presumably earlier. As of version 5 it is no longer in the currency_update.php file.

That's what I figured. Do you have any insight to thie error I am getting emailed?
> /home2/redsauto/public_html/currency_update.php: line 1: ?php: No such file or directory
> /home2/redsauto/public_html/currency_update.php: line 2: /0: Permission denied
> /home2/redsauto/public_html/currency_update.php: line 3: access-logs: command not found
> /home2/redsauto/public_html/currency_update.php: line 4: syntax error near unexpected token `('
> /home2/redsauto/public_html/currency_update.php: line 4: ` * Originally by Richard Fink (masterblaster) based on Zen Cart manual currency update'

It looks like the cron job isn't recognizing that it is a php file.
4 Dec 2015, 4:36 PM
#292
design75 avatar

design75

Totally Zenned

Join Date:
Dec 2009
Location:
Amersfoort, The Netherlands
Posts:
2,862
Plugin Contributions:
5

Re: Currency Update (Automatic)

vanhorn_s:

That's what I figured. Do you have any insight to thie error I am getting emailed?

It looks like the cron job isn't recognizing that it is a php file.

Can you past the contents of your currency_update.php? I suspect you are missing some characters at the start of the file

4 Dec 2015, 4:52 PM
#293
vanhorn_s avatar

vanhorn_s

Zen Follower

Join Date:
Apr 2010
Posts:
283
Plugin Contributions:
0

Re: Currency Update (Automatic)

Design75:

Can you past the contents of your currency_update.php? I suspect you are missing some characters at the start of the file

<?php
/*
 * Automatic Currency Update v5.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)
 * updated by Zen4All (design75) use Zen Cart standard coding
 *
 * Rework for PHP 5.3 compatibility (ereg and mysql_db_query functions deprecated in PHP 5.3.0)
 * switched to using SimpleXML and mysqli instead.
 * JeRo www.jero.co.nz 18/06/2010
 *
 * license: GNU Public License V2.0
 *
 */

require_once('includes/application_top.php');
/*
 *  Get default currency.
 */
$defaulCurrency = $db->Execute("SELECT configuration_value
                                FROM " . TABLE_CONFIGURATION . "
                                WHERE configuration_key = 'DEFAULT_CURRENCY' LIMIT 1 ");

/* 
 * Get currency conversion ratio.
 */
$currencyUpliftRatio = $db->Execute("SELECT configuration_value
                                     FROM " . TABLE_CONFIGURATION . "
                                     WHERE configuration_key = 'CURRENCY_UPLIFT_RATIO' LIMIT 1 ");

/*
 * Create new SimpleXML element from the Euro zone file
 * If your PHP configuration does not have allow_url_fopen, you may need to
 * write a script to pick it up using wget:
 * wget -O eurofxref-daily.xml www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml
 * and then uncomment/comment these next two lines:
 * $xml = new SimpleXMLElement(file_get_contents("eurofxref-daily.xml"));
 */
$xml = new SimpleXMLElement(file_get_contents("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"));

/*
 * extract your preferred currency's exchange rate.
 */
$nzd = $xml->xpath("//*[@currency='" . $defaulCurrency->fields['configuration_value'] . "']");
$base = (float)$nzd[0]['rate'];

# If our default currency is the Euro, it won't be in the XML,
# so set the base exchange rate to 1
if ($defaulCurrency->fields['configuration_value'] == 'EUR') {
  $base = (float)1;
}

/*
 * Get array of currency data from the XML file.
 */
$currencies = $xml->xpath("//*[@currency]");

/*
 *  Iterate over array, pulling out currency code and rate.
 * Convert into your preferred currency.
 * Pump it into the database.
 */
foreach ($currencies as $curr) {
  $cc = $curr[0]['currency'];
  $rr = (float)$curr[0]['rate'] * $currencyUpliftRatio->fields['configuration_value'];
  $new = $rr / $base;
/*
 * But don't uplift your default currency!
 */
  if ($cc != $defaulCurrency->fields['configuration_value']) {
    $sql_data_array = array('value' => $new,
                            'last_updated' => 'now()',
                            'code' => $cc);
    zen_db_perform(TABLE_CURRENCIES, $sql_data_array, 'update', "code = '" . $cc . "'");
  }
}

/*
 * Feed is based on the Euro, which is not included in the feed,
 * therefore we need to update it manually,
 * unless of course our preferred currency is the Euro
 */
$cc = 'EUR';
$rr = 1 / $base * CURRENCY_UPLIFT_RATIO;
if ($defaulCurrency->fields['configuration_value'] != $cc) {
  $sql_data_array = array('value' => $rr,
                          'last_updated' => 'now()',
                          'code' => $cc);
  zen_db_perform(TABLE_CURRENCIES, $sql_data_array, 'update', "code = '" . $cc . "'");
}
4 Dec 2015, 5:14 PM
#294
s_mack avatar

s_mack

Totally Zenned

Join Date:
Jun 2005
Location:
Kelowna, BC Canada
Posts:
1,033
Plugin Contributions:
4

Re: Currency Update (Automatic)

The error YOU yourself postd:

/home2/redsauto/public_html/currency_update.php: line 1: ?php: No such file or directory

Seemingly indicates that line 1 is missing the very first character... the "<" before "?php".

You said you upgraded to V6 (my code) but you just posted code from V5.

I think what you did was copy all but the first character from my code.

4 Dec 2015, 5:54 PM
#295
vanhorn_s avatar

vanhorn_s

Zen Follower

Join Date:
Apr 2010
Posts:
283
Plugin Contributions:
0

Re: Currency Update (Automatic)

s_mack:

The error YOU yourself postd:

/home2/redsauto/public_html/currency_update.php: line 1: ?php: No such file or directory

> 
> Seemingly indicates that line 1 is missing the very first character... the "<" before "?php".
> 
> You said you upgraded to V6 (my code) but you just posted code from V5.
> 
> I *think* what you did was copy all but the first character from my code.

The v6 was a typo. I meant v5. I downloaded the latest one last week from here: <https://www.zen-cart.com/downloads.php?do=file&id=286>
I did not edit it, I only uploaded the file as I downloaded it. What I posted above, is the contents of that file.
9 Sep 2021, 8:32 AM
#296
gprit avatar

gprit

Zen Follower

Join Date:
Mar 2009
Posts:
176
Plugin Contributions:
0

Re: Currency Update (Automatic)

Should this work with Zencart v 1.5.6 and PHP v8.0?

I ran it through a PHP tester and got the following:
Warning: require_once(): open_basedir restriction in effect. File(includes/application_top.php) is not within the allowed path(s): (/var/tmp/) in /tmp/31yrgpkae1ktco5pkq/tester.php on line 17 Warning: require_once(includes/application_top.php): Failed to open stream: Operation not permitted in /tmp/31yrgpkae1ktco5pkq/tester.php on line 17 Fatal error: Uncaught Error: Failed opening required 'includes/application_top.php' (include_path='.:') in /tmp/31yrgpkae1ktco5pkq/tester.php:17 Stack trace: #0 {main} thrown in /tmp/31yrgpkae1ktco5pkq/tester.php on line 17

8 Apr 2023, 5:02 AM
#297
jtlswan avatar

jtlswan

New Zenner

Join Date:
May 2006
Location:
Orangeburg, SC
Posts:
72
Plugin Contributions:
0

Re: Currency Update (Automatic)

Anyone have an updated version for 1.5.8 (1.5.8a)? or will this current version 5.0 work with it?

10 Apr 2023, 8:38 AM
#298
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,875
Plugin Contributions:
7

Re: Currency Update (Automatic)

As mentioned on the plugin page, this is now built-in:

NOTE: In Zen Cart 1.5.5 and above, the admin/currency_cron.php facility can be used.

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...