Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2007
    Posts
    25
    Plugin Contributions
    0

    Default Observers and Session Objects - not getting notified

    I have a working notifier class that is getting called when it's a regular object created from the auto_init system. no problem.

    But I really want that object to be a session variable so I can hold some processing info through checkout. So I made it one like this:

    $autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
    'className'=>'hcRegistration',
    'objectName'=>'hcreg',
    'checkInstantiated'=>true,
    'classSession'=>true
    );

    and that does create the session variable....but now my observed events are not called!

    I saw that class creation only happens once, since it's then stored in a session, so I moved the observer 'attach' call to a function and call that late in the auto_init time:
    $autoLoadConfig[191][] = array('autoType'=>'objectMethod',
    'objectName'=>'hcreg',
    'methodName' => 'setNotifiers');

    This does set the observers...but they are never called.
    Does anyone know why you can't have a session object with observers? Or any other ideas what's happening?

    My workaround is to create two classes, one that's a session object and one that's not, that's only used for observer events.

    any thoughts?
    thanks much,
    ---avibodha

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

    Default Re: Observers and Session Objects - not getting notified

    I'm not sure why you're trying to make an observer be a session object.

    Perhaps you can explain in a lot more detail what you're trying to do and why?

    And also post your observer code.
    .

    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
    Nov 2007
    Posts
    25
    Plugin Contributions
    0

    Default Re: Observers and Session Objects - not getting notified

    Yes, it actually makes more sense to break it into two classes, one for events and one to hold special session info and processing.

    I'm holding some custom form data that gets attached to a product added to the cart and follows it through checkout, so that's in the session object. Needed to handle some events in the cart to keep the data updated (like if product is deleted or cart restored or emptied, etc)...first thought was to have one class....but makes more sense to separate events from data.

    Works fine once I separated them out...so no problem now.


    When they were together, my event handler was something like this:

    Code:
    class hcEvents extends base {
    
      function hcEvents() {
        
      }
    
      // setNotifiers call set up in 'config.hc_loader.php'
      // event 191 (after everything else already done)
      // must call after class set up in case it was already a session variable
      // there is no 'wake up' call to session objects (that I can find)
      function setNotifiers() {
        global $zco_notifier;
    
        $this->attach($this, array(
            'NOTIFIER_CART_ADD_CART_END',
            'NOTIFIER_CART_REMOVE_END',
            'NOTIFIER_CART_RESTORE_CONTENTS_START',
            'NOTIFIER_CART_INSTANTIATE_END',
            'NOTIFIER_CART_RESET_END'
            ));
    
        // procedural code overrides
        //$zco_notifier->attach($this, array('NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION'));
    
      }
    
      function update(&$class, $eventID) {
        // 'class' is object throwing event
        switch ($eventID) {
    
        case 'NOTIFIER_CART_INSTANTIATE_END':
        case 'NOTIFIER_CART_RESET_END':
          // reset
          break;
        case 'NOTIFIER_CART_ADD_CART_END':
        case 'NOTIFIER_CART_REMOVE_END':
          // NOTYET see if registration item in cart
          break;
        case 'NOTIFIER_CART_RESTORE_CONTENTS_START':
          // do not restore registration items
          // delete from customers basket, don't restore
          break;
        }
      }
    and here's the auto_init code:

    Code:
    // load hc observers code
    $autoLoadConfig[10][] = array('autoType'=>'class',
                                  'loadFile'=>'observers/hc_reg.php');
    // create, after cart object created
    // is stored in session
    $autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
                                  'className'=>'hcEvents',
                                  'objectName'=>'hcevt',
                                  'checkInstantiated'=>true,
                                  'classSession'=>true
                                  );
    
    // re-attach notifiers, hc_reg is in session, so restored
    // but notifiers are static and not restored, so set them each time
    // call function after auto_load
      $autoLoadConfig[191][] = array('autoType'=>'objectMethod',
                                    'objectName'=>'hcevt',
                                    'methodName' => 'setNotifiers');
    It seems like this should have worked since it restored the observers...but when I stepped through the code, the events either didn't find the observer or it did not call the object.

    Only a curiosity now, though...I think architecturally better to separate that functionality out anyway.

    thanks

 

 

Similar Threads

  1. Help!! admin not getting notified of new orders!
    By kevinjatMB in forum Managing Customers and Orders
    Replies: 15
    Last Post: 14 Jul 2011, 04:23 PM
  2. Observers and redirects
    By audleman in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 10 Sep 2008, 05:19 PM
  3. session objects in the observer class
    By wdrwc in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 18 Jul 2006, 06:48 PM
  4. session objects in the observer class
    By wdrwc in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 18 Jul 2006, 11:19 AM
  5. session and objects
    By Radik in forum General Questions
    Replies: 0
    Last Post: 10 Jun 2006, 09:33 PM

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