Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    May 2013
    Location
    Brisbane, Australia
    Posts
    6
    Plugin Contributions
    0

    Default Updating Currencies

    Is anyone having issues with updating currencies in V155? I have set up 6 currencies for use in different locations and changed the default currency to Australian dollars. Clicking on the "Update Currencies" button under the list of currencies results in a list of warnings like "Warning: The primary exchange rate server (ecb) failed for Canadian Dollar (CAD) - trying the secondary exchange rate server." - one for each currency except for the default currency. If I copy the URL from the localisation.php file and paste it in a browser, the required rates are returned.

    This all worked fine in v154 but I can't see what I am doing wrong now.

    This is a clean install of v155 but I have made changes to Australian date format and timezone and added ckeditor. Also have set up zones and taxes, but nothing else. No further plugins added yet.

    I am running in XAMPP at the moment with PHP7.0.5 and Apache 2.4.18

    Debug log:
    [02-May-2016 16:48:54 Australia/Brisbane] Request URI: /store/crystalsadmin/currencies.php?page=1&cID=5&action=update_currencies, IP address: ::1
    #1 quote_boc_currency() called at [C:\xampp\htdocs\store\crystalsadmin\includes\functions\localization.php:37]
    #2 zen_update_currencies() called at [C:\xampp\htdocs\store\crystalsadmin\currencies.php:94]


    [02-May-2016 16:48:54 Australia/Brisbane] PHP Warning: Division by zero in C:\xampp\htdocs\store\crystalsadmin\includes\functions\localization.php on line 128

    [02-May-2016 16:48:54 Australia/Brisbane] Request URI: /store/crystalsadmin/currencies.php?page=1&cID=5&action=update_currencies, IP address: ::1
    #1 quote_boc_currency() called at [C:\xampp\htdocs\store\crystalsadmin\includes\functions\localization.php:37]
    #2 zen_update_currencies() called at [C:\xampp\htdocs\store\crystalsadmin\currencies.php:94]


    [02-May-2016 16:48:54 Australia/Brisbane] PHP Warning: Division by zero in C:\xampp\htdocs\store\crystalsadmin\includes\functions\localization.php on line 128

    [02-May-2016 16:48:54 Australia/Brisbane] Request URI: /store/crystalsadmin/currencies.php?page=1&cID=5&action=update_currencies, IP address: ::1
    #1 quote_boc_currency() called at [C:\xampp\htdocs\store\crystalsadmin\includes\functions\localization.php:37]
    #2 zen_update_currencies() called at [C:\xampp\htdocs\store\crystalsadmin\currencies.php:94]


    [02-May-2016 16:48:54 Australia/Brisbane] PHP Warning: Division by zero in C:\xampp\htdocs\store\crystalsadmin\includes\functions\localization.php on line 128

    [02-May-2016 16:48:54 Australia/Brisbane] Request URI: /store/crystalsadmin/currencies.php?page=1&cID=5&action=update_currencies, IP address: ::1
    #1 quote_boc_currency() called at [C:\xampp\htdocs\store\crystalsadmin\includes\functions\localization.php:37]
    #2 zen_update_currencies() called at [C:\xampp\htdocs\store\crystalsadmin\currencies.php:94]


    [02-May-2016 16:48:54 Australia/Brisbane] PHP Warning: Division by zero in C:\xampp\htdocs\store\crystalsadmin\includes\functions\localization.php on line 128

    [02-May-2016 16:48:54 Australia/Brisbane] Request URI: /store/crystalsadmin/currencies.php?page=1&cID=5&action=update_currencies, IP address: ::1
    #1 quote_boc_currency() called at [C:\xampp\htdocs\store\crystalsadmin\includes\functions\localization.php:37]
    #2 zen_update_currencies() called at [C:\xampp\htdocs\store\crystalsadmin\currencies.php:94]


    [02-May-2016 16:48:54 Australia/Brisbane] PHP Warning: Division by zero in C:\xampp\htdocs\store\crystalsadmin\includes\functions\localization.php on line 128

    Any help would be appreciated.

    Thanks
    Chris

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,401
    Plugin Contributions
    87

    bug Re: Updating Currencies

    Hmm, interesting. Running a vanilla ZC 1.5.5-2016-03-29 under XAMPP via PHP 5.4, the currency update occurs successfully. Changing to PHP 7.0.2, and only the USD currency (the default) is successfully processed via ECB (but that's a red herring).

    When I look at my /logs folder, the logs report the same information as you'd posted, with the exception of:
    Code:
    [02-May-2016 13:10:13 UTC] PHP Warning:  file(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in C:\xampp\htdocs\zc155\cAndy-iVH-SloaN\includes\functions\localization.php on line 115
    That log entry is the "tell". Apparently either PHP 7.x or that version of XAMPP has got allow_url_fopen set to Off. Having that set causes the currencies-updater to head down a CURL path to retrieve the information, but an invalid response is received from ecb; here's the var_export dump of the $XMLContent after the request:
    Code:
    [02-May-2016 13:20:39 UTC] array (
      0 => '<html lang="en"> <head> <title>European Central Bank</title> <style type="text/css"> body{ font-family: "Droid Sans", sans-serif; margin:0; padding:0; background-color: #9099ab; text-align: center; } h1{  font-size:38px; font-weight: normal; color:#003299; }  @media screen and (max-width: 480px) { h1{ font-size: 30px; } }  p { font-size: 15px; line-height: 20px; color: #333; margin-bottom: 20px; }  p.signature{ font-style: italic; color:#DF0101; }  .centredFrame { margin: 0 auto; text-align: center; width: 70%;   } .content{ margin-top:40px; padding:40px; background-color: #fff; border:1px solid #CDE3E0; -moz-border-radius: 20px; border-radius: 20px; } </style>',
      1 => '			   <link href="https://fonts.googleapis.com/css?family=Droid+Sans" rel="stylesheet" type="text/css">',
      2 => '			   </head> <body> <div class="centredFrame"> <div class="content"> <img src="https://www.ecb.europa.eu/pic_failover/ecb_logo_EN.png"> <h1>A problem occurred while trying to access this page</h1> <body>We apologize for any inconvenience this might have caused.</body> <p class="signature">Reference number:  #18.12b81cb8.1462195235.4fbb3617</p> <p class="signature">HTTP status code: 403</p> </div> </div> </body> </html>',
    )
    So, I went back to PHP 5.4 and commented-out the file-request to retrieve the ecb information (so that the code would go down the CURL path there as well) and re-ran the currency-update with ... no issue.

    That said, it looks like the ecb issue has to do with a curl-related change introduced somewhere in the PHP 5.5, 5.6 and 7.0 timeframe!

    The boc processing is going to run into the same issue, with the exception that its handling is missing the highlighted check (which is why the divide-by-0 is being issued):
    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);
        $curName = $data[1];
        $curRate = $data[sizeof($data)-1];
        $currencyArray[trim($curName)] = (float)$curRate;
      }
      if (!isset($currencyArray[DEFAULT_CURRENCY]) || 0 == $currencyArray[DEFAULT_CURRENCY]) return ''; // no valid value, so abort
      $rate = (string)($currencyArray[DEFAULT_CURRENCY]/(float)$currencyArray[$requested]);
      return $rate;
    }
    So, net-net there are two separate issues:
    1. The fact that the currency updates aren't happening under PHP 7.0. As a work-around, you could update your XAMPP installation's php.ini file to set allow_url_fopen=On while the ZC-dev CURL experts figure out what the root-cause is.
    2. The divide-by-0 coming from the boc currency handler; see suggested change above.
    Last edited by lat9; 2 May 2016 at 03:04 PM. Reason: Added "bug" icon.

  3. #3
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Updating Currencies

    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
    .

    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.

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,401
    Plugin Contributions
    87

    Default Re: Updating Currencies

    Thanks for the update, DrByte! That's what I get for copying and pasting without that required additional step (thinking)!

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,401
    Plugin Contributions
    87

    Default Re: Updating Currencies

    Could the XAMPP issue be that SSL isn't set up?

  6. #6
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Updating Currencies

    Quote Originally Posted by lat9 View Post
    Could the XAMPP issue be that SSL isn't set up?
    Given that the URLs being used to retrieve currency data aren't https, I don't think it's an SSL issue.
    .

    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.

  7. #7
    Join Date
    May 2013
    Location
    Brisbane, Australia
    Posts
    6
    Plugin Contributions
    0

    Default Re: Updating Currencies

    Thanks Lat9 and DrByte for your input on this. My next move this morning was to install a clean version on my web site host account to see if the issue was resolved but you have done that DrByte. I was doubting myself on this one because updating of currencies has been around forever.

    So now I will make the code changes that you have suggested for boc and check the host site vanilla install. As long as I know that ecb works on the host, then I am OK with it defaulting to boc on XAMPP.

    I really do appreciate your help folks.

  8. #8
    Join Date
    May 2013
    Location
    Brisbane, Australia
    Posts
    6
    Plugin Contributions
    0

    Default Re: Updating Currencies

    Hello again.
    Update on what has happened.
    Lat9, allow_url_fopen was already set to On in php.ini so no effect there.

    DrByte, code changes installed in localisation.php. Warning received from ecb for all updates, but all updates from boc were installed successfully on XAMPP.

    Thanks
    Chris

  9. #9
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Updating Currencies

    You could use a different server, such as OpenExchangeRates, as long as you register for a free API key from them: https://www.zen-cart.com/downloads.php?do=file&id=2035
    .

    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.

  10. #10
    Join Date
    May 2013
    Location
    Brisbane, Australia
    Posts
    6
    Plugin Contributions
    0

    Default Re: Updating Currencies

    Hi DrByte and Lat9
    Updating worked fine on my web host server with ecb.

    Thanks for all your help.
    Chris

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 10
    Last Post: 31 Oct 2015, 08:09 PM
  2. Replies: 1
    Last Post: 27 Sep 2015, 11:45 AM
  3. Replies: 1
    Last Post: 25 Sep 2015, 06:12 PM
  4. Currencies not updating with correct values
    By Twaddle in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 2
    Last Post: 4 Mar 2010, 03:41 PM
  5. Currency value (how is this defined/used?) and updating currencies
    By spidersilk in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 10 Jun 2006, 10:50 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR