Originally Posted by
nwjh
I have the same issues. I am trying to get the 'openexchangerates' plug-in to work and there are obviously changes coming in 1.5.5. Any clues for 1.5.4 for this, because there are plenty of currencies that ecb and boc don't seem to be interested to find.
I suggest using the code I posted here, along with the fix I just posted above, rather than using DrByte's code which appears to be specific to an unreleased version, despite saying in the downloads that it is for 1.5.3, 1.5.4 etc. There's no place in the admin to make the stated change to server.
Mine is working on 1.5.4.
So you just make a new file called currency_updater.php and put it in the root of your store's installation (ie. not inside your includes folder, but the same folder that your includes folder is in). Copy and paste this code into it (which is a combination of the one I linked to and the fix):
Code:
<?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
*
*/
$current_page_base = 'currency_updater';
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 . "'");
}
If you don't mind a WARNING in your log files every hour or day or whatever you set the cron to... then you can stop there. To get rid of the warning, you also need to do the change to your includes\functions\sessions.php file I described earlier.
Then go into your server's control panel or whatever you use and make a cron job that looks something like this:
Code:
20 * * * * php -f /home/whatever/public_html/test/currency_updater.php
(that runs at the 20th minute of every hour). Of course, you'll have to adjust the path to suit your web server.
Bookmarks