Hmmm ... I think the problem is something in XAMP.
1. I just tested it on a Linux Ubuntu server running PHP 7.0.5. No errors. I also hacked the code to force it to run via curl, and got the exact same success results:
Code:
The exchange rate for US Dollar (USD) was updated successfully to 1 via ecb.
The exchange rate for Euro (EUR) was updated successfully to 0.91359958235448 via ecb.
The exchange rate for GB Pound (GBP) was updated successfully to 0.71487340120073 via ecb.
The exchange rate for Canadian Dollar (CAD) was updated successfully to 1.3144870790916 via ecb.
The exchange rate for Australian Dollar (AUD) was updated successfully to 1.3726833724876 via ecb.
So I think the "issues with PHP7" are actually issues with XAMP's implementation of PHP7.
2. But testing the BOC results yields the need for a few changes.
The code-change lat9 offered for divide-by-zero protection is incorrect. It's doing a protection against the origin amount, not the divisor.
Plus, BOC appears to have changed their currency code notations.
I recommend the following change in /admin/includes/functions/localization.php:
Code:
function quote_boc_currency($currencyCode = '', $base = DEFAULT_CURRENCY)
{
if ($currencyCode == $base) return 1;
static $CSVContent;
$requested = $currencyCode;
$url = 'http://www.bankofcanada.ca/stats/assets/csv/fx-seven-day.csv';
$currencyArray = array();
$currencyArray['CAD'] = 1;
if (!isset($CSVContent) || $CSVContent == '') {
$CSVContent = file($url);
if (! is_object($CSVContent) && function_exists('curl_init')) {
$CSVContent = doCurlCurrencyRequest('GET', $url);
$CSVContent = explode("\n", $CSVContent);
}
}
foreach ($CSVContent as $line) {
if (substr($line, 0, 1) == '#' || substr($line, 0, 4) == 'Date' || trim($line) == '') continue;
$data = explode(',', $line); // make an array, where each value is a separate column from the CSV
$curName = substr(trim($data[1]), 0, 3); // take only first 3 chars of currency code (ie: removes "_NOON" suffix, or whatever future suffix BOC adds)
$curRate = trim($data[sizeof($data)-1]); // grab the value from the last column
$currencyArray[trim($curName)] = (float)$curRate;
}
if (!isset($currencyArray[$requested])) return false; // requested not found
if ($currencyArray[$requested] == 0) return false; // can't divide by zero
$rate = (string)($currencyArray[DEFAULT_CURRENCY]/(float)$currencyArray[$requested]);
return $rate;
}
Also available here: https://github.com/zencart/zencart/pull/911/files
Bookmarks