Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Notifier will not trigger update function

    I'm having difficulty getting an observer/notifier to work. I've looked at and tested this code for days and can't find anything wrong. Yet the update function is never called. The notifier statement in the core code is called based on a test echo statement just before the notifier. No errors are logged. Can anyone see what's wrong? Several other observer/notifier code I've written work great. Code follows for the includes/classes/observers and includes/auto_loaders files. Any other troubleshooting tips to find the problem?

    TIA

    Dave


    Code:
    <?php
    /**
     * observer class to set Membership Prices
     *
     * @package classes
     * @copyright Copyright 2003-2013 Zen Cart Development Team
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: class.set_Membership_Prices.php   $
     */
    class set_Membership_Prices extends base {
    
     /**  constructor method !
       *
       * Attach observer class to the global $zco_notifier and watch for a single notifier event.
       */
      function __construct() {
        $this->attach($this, array('NOTIFIER_CART_ADD_CART_START'));
      }
    
    
     /**   Actual Method that does the desired activity
       *
       * Called by observed class when any of the notifiable events occur
       *
       * @param object $class
       * @param string $eventID
       * @param array $paramsArray
       */
      function update(&$class, $eventID, $paramsArray = array()) {
    	echo "<pre>"; print_r($_POST); echo "</pre>";
      } // end of function update
    } // end of class

    Code:
    <?php
    /**
     * autoloader activation point for setting membership prices
     *
     * @package initSystem
     * @copyright Copyright 2003-2013 Zen Cart Development Team
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: config.set_Membership_Prices.php $
     */
    /**
     * Autoloader to instantiate observer class
     */
    $autoLoadConfig[190][] = array('autoType'=>'class',
                                  'loadFile'=>'observers/class.set_Membership_Prices.php');
    $autoLoadConfig[190][] = array('autoType'=>'classInstantiate',
                                  'className'=>'set_Membership_Prices',
                                  'objectName'=>'set_Membership_Prices');

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,976
    Plugin Contributions
    96

    Default Re: Notifier will not trigger update function

    Are you sure you copied the auto_loader file to your hosted configuration? Everything looks good, otherwise.

  3. #3
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Notifier will not trigger update function

    Yes, both files are in their proper locations. i put an echo in the __construct() function, and that worked, but I still can't get an echo to work in update. I changed the notifier to NOTIFIER_CART_ADD_CART_END and still got nothing. I'm at a loss on how to proceed. I think I'll set the notifier to one that currently works for other functions and see if that triggers the one I'm working with.
    Last edited by Dave224; 7 Nov 2013 at 11:15 PM.

  4. #4
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Notifier will not trigger update function

    Very interesting...I changed the notifier in my "echo" file to another one for which I had written an observer class and knew was working. And the update function for the "echo" file was triggered! Changed the notifier back to NOTIFIER_CART_ADD_CART_START and nothing again. Echo statements before and after the $this->notify('NOTIFIER_CART_ADD_CART_START') line in the add_cart method in includes/classes/shopping_cart.php demonstrated that the code was being executed, but somehow that notifier does not work.

    So I conclude that there's nothing wrong with my observer code, but the notifier is not working, at least for the notifier point I need.

  5. #5
    Join Date
    Aug 2005
    Location
    Vic, Oz
    Posts
    1,905
    Plugin Contributions
    5

    Default Re: Notifier will not trigger update function

    Try this...
    Code:
    <?php
    /**
     * autoloader activation point for setting membership prices
     *
     * @package initSystem
     * @copyright Copyright 2003-2013 Zen Cart Development Team
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: config.set_Membership_Prices.php $
     */
    /**
     * Autoloader to instantiate observer class
     */
    $autoLoadConfig[10][] = array('autoType'=>'class',
                                  'loadFile'=>'observers/class.set_Membership_Prices.php');
    $autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
                                  'className'=>'set_Membership_Prices',
                                  'objectName'=>'set_Membership_Prices');

  6. #6
    Join Date
    Jun 2012
    Posts
    481
    Plugin Contributions
    0

    Default Re: Notifier will not trigger update function

    Thanks gilby! That worked. But 10 and 190 did not. Please explain the rules for setting these two numbers. I've seen other posts stating to keep above 190. And my other observers have numbers above 190 and they work. What's going on???

    Dave

  7. #7
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: Notifier will not trigger update function

    Depends upon what you are observing. The observer needs to be loaded before the "event" occurs, otherwise it will not receive the "event".

    When possible, it is best to use the "highest" load point possible (180 is the highest I believe stock Zen Cart uses) to ensure all other required code has been loaded by the init system (and to avoid code which may interfere with any of the stock Zen Cart code being loaded).


    In your example code the "event" you want to "observe" is triggered by "init_cart_handler.php". The file "init_cart_handler.php" is loaded / run by the init system at "140". So in your case you could probably safely use "139" or "135". Leaving it at "90" should be okay, as your observer does not appear to load / call any code in the constructor only "registers" with Zen Cart to receive the "event"...
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

 

 

Similar Threads

  1. Privacy Policy will not update
    By wormgineer in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 29 Jun 2010, 07:51 PM
  2. backorder function will not turn on
    By cudaboy71 in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 16 Jun 2010, 08:34 PM
  3. download_maxdays will not update only on certain products
    By jeffmic in forum Setting Up Categories, Products, Attributes
    Replies: 5
    Last Post: 9 Nov 2009, 04:19 PM
  4. Shopping Cart will not update
    By Aderra in forum General Questions
    Replies: 3
    Last Post: 22 Oct 2009, 11:41 PM

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