Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Jun 2005
    Location
    Kelowna, BC Canada
    Posts
    1,075
    Plugin Contributions
    6

    Default Cron job updating currencies is logging a warning... working, but warning

    I've used a currency updating script for ages without problems (I think I wrote it, but I don't recall for sure lol). Anyway, now that I'm finally updating to 1.5.4 I found the current rendition of automatic currency updating but I get a warning logged everytime the cron job runs. It looks like this:

    [26-Oct-2015 07:07:01 MST] PHP Warning: session_start(): Cannot send session cookie - headers already sent in /home/smartiep/public_html/test/includes/functions/sessions.php on line 107
    I think I get what's happening. The "new" way for the currency updating is to start the file with "require_once('includes/application_top.php');" and I think that tries to begin a session. Since nobody's home, no cookie can be set and it tries to output a "turn on your cookies" message but (again) nobody's home so the message can't output and it throws that warning. That's kind of a guess, but I'm thinking I'm close.

    So is calling application_top the wrong way to do it? Or is there a way to treat the cron 'session' as a bot so the cookies aren't tried?

    Or am I way off base?

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Cron job updating currencies is logging a warning... working, but warning

    When I wrote the cron script for v160 I started by setting the user agent, but then discovered it was better to simply set a new $loader_prefix to point to a dedicated auto_loader script which skipped starting any sessions.

    https://github.com/zencart/zencart/b...rency_cron.php
    https://github.com/zencart/zencart/b..._cron.core.php

    Actually most of the commits related to implementing this are summarized here: https://github.com/zencart/zencart/c...rency_cron.php
    .

    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.

  3. #3
    Join Date
    Jun 2005
    Location
    Kelowna, BC Canada
    Posts
    1,075
    Plugin Contributions
    6

    Default Re: Cron job updating currencies is logging a warning... working, but warning

    Is this going to be backward applicable to 1.5.4?

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Cron job updating currencies is logging a warning... working, but warning

    A variation of it has been backported into the upcoming v155.

    And so far it seems to work fine with this new plugin I made for openexchangerates, inspired from your post the other day: 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.

  5. #5
    Join Date
    Jun 2005
    Location
    Kelowna, BC Canada
    Posts
    1,075
    Plugin Contributions
    6

    Default Re: Cron job updating currencies is logging a warning... working, but warning

    Ah, well then... you're welcome :)

    Is 1.5.5 imminent?

  6. #6
    Join Date
    Jun 2005
    Location
    Kelowna, BC Canada
    Posts
    1,075
    Plugin Contributions
    6

    Default Re: Cron job updating currencies is logging a warning... working, but warning

    Btw, in the instructions for that you say "Login to your Admin, go to Admin->Configuration->My Store, and set the primary currency server to openexchangerates"... primary whatnow? No such setting exists.

    And I see you say it can easily be set with a cron in 1.5.5... but what about 1.5.4? The contrib suggests it is compatibel with 1.5.4
    Last edited by s_mack; 29 Oct 2015 at 05:53 AM.

  7. #7
    Join Date
    Jun 2005
    Location
    Kelowna, BC Canada
    Posts
    1,075
    Plugin Contributions
    6

    Default Re: Cron job updating currencies is logging a warning... working, but warning

    I ended up resolving the issue an ugly way after failed attempts at working with your 1.5.5/1.6.0 hints.

    I put this right above the call to application_top.php
    Code:
    $current_page_base = 'currency_updater';
    And then in includes\functions\sessions.php right after the function zen_session_start() line I added
    Code:
        global $current_page_base;
        if ($current_page_base == 'currency_updater') {
          return 0;
        }
    I hate modding core files for niggly little things like this so if you have a better solution that works in 1.5.4 I'd love to read it. I tried changing the user agent but that got me nowhere. I tried calling a custom core file but I'm not familiar enough and it wasn't working. I certianly couldn't just copy/paste your 1.5.5 one over.

  8. #8
    Join Date
    Oct 2015
    Location
    Alaska
    Posts
    10
    Plugin Contributions
    0

    Default Re: Cron job updating currencies is logging a warning... working, but warning

    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.

  9. #9
    Join Date
    Jun 2005
    Location
    Kelowna, BC Canada
    Posts
    1,075
    Plugin Contributions
    6

    Default Re: Cron job updating currencies is logging a warning... working, but warning

    Quote Originally Posted by nwjh View Post
    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.

  10. #10
    Join Date
    Oct 2015
    Location
    Alaska
    Posts
    10
    Plugin Contributions
    0

    Default Re: Cron job updating currencies is logging a warning... working, but warning

    Many thanks for that. I've followed the instructions, but added " >/dev/null 2>&1 " onto the cron job to skip the emails.

    Now to see how it works! Still building (and re-building) the site....

    Thanks and cheers,

    Bill.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v151 Cron Job
    By Cenkki in forum General Questions
    Replies: 19
    Last Post: 8 Sep 2014, 02:54 PM
  2. Logging In produces Security warning
    By kevinmc3 in forum General Questions
    Replies: 5
    Last Post: 14 Dec 2010, 04:41 AM
  3. Cron Job for Updating QTY
    By ryanb4614 in forum General Questions
    Replies: 2
    Last Post: 9 Aug 2010, 07:13 AM
  4. CRON job help
    By Jeff G in forum General Questions
    Replies: 10
    Last Post: 9 Oct 2008, 12:20 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