Results 1 to 10 of 38

Hybrid View

  1. #1
    Join Date
    Mar 2005
    Location
    London, Ontario
    Posts
    48
    Plugin Contributions
    0

    Default

    Ok, I'm beggining to get the picture here.

    Next challenge. I've written a class to modify the description before it is displayed. I've used the NOTIFY_MAIN_TEMPLATE_VARS_EXTRA_PRODUCT_INFO notifier to run my code after the database has been queried and before it is displayed.

    I can get the description by using the GET variable products_id. However then how would I modify the variable products_description?

    What I'm trying to do is parse through the description text looking for keywords I have in an array (from a glossary table). I want to make any matching terms into hyperlinks.

    Related to this, I'm a little sketchy on how to tell the notifier is in a class or not. I'm assuming the class declaration should be in the same file as the notifier? ie NOTIFY_MAIN_TEMPLATE_VARS_EXTRA_PRODUCT_INFO is not in a class.

    thanks, I'm liking this notifier system more and more! Any idea what phase will see all notifiers contained in classes?
    Jeremy Richardson
    www.justjerm.com

  2. #2
    Join Date
    Sep 2004
    Posts
    14
    Plugin Contributions
    0

    Default Re: Use Of Notifiers - How To

    I am trying to write the observer class attached to events during the checkout process. I need the session class with several variables storing values for session.
    But I can not properly initialize them and get them reinitialized several times during the checkout process. A a result I loose the values assigned to these variables on previous entry to the class. It looks like I do not understand how does the ONS work.

    For test purposes I wrote a stupid testclass attached to the same events. But it does not work at all. I would appreciate if someone could advice what is wrong.

    The file config.testclass.php in the includes/auto_loaders directory contains:
    Code:
    <?php
    /*
     * instantiate class.testclass at 180 - when
     * everything is initialized
     * in <root>/includes/auto_loaders
     */
    
    $autoLoadConfig[180][]= array('autoType' => 'class',
    				'loadFile' => 'observers/class.testclass.php');
    
    $autoLoadConfig[180][]= array('autoType' => 'classInstantiate',
    				'className' => 'testclass',
    				'objectName' => 'testClassObject',
            'checkInstantiated' => true,
            'classSession' => true );
    
    ?>
    and class.testclass.php in includes/classes/observers looks like this:
    Code:
    <?php
    
    class testclass extends base {
      var $initialized= false;
      var $field;
      /*constructor*/
      function testclass() {
        global $zco_notifier;
    
        $this->test_log($this->initialized ."\t=initialized at start constructor");
        $this->test_log($this->field ."\t=field at start constructor");
        $zco_notifier -> attach($this,
                                array('NOTIFY_HEADER_START_CHECKOUT_CONFIRMATION',
                                      'NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION',
                                      /*'NOTIFY_HEADER_END_CHECKOUT_SUCCESS',*/
                                      'NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS',
                                      'NOTIFY_HEADER_START_ACCOUNT_HISTORY_INFO'));
    
        if( !($this->initialized) ) {
          $this->initialized= true;
          $this->field= -10;
        }
        $this->test_log($this->initialized ."\t=initialized at end constructor");
        $this->test_log($this->field ."\t=field at end constructor");
      }
      
      /* update method */
      function update(&$callingClass, $eventID, $paramsArray) {
        if($eventID == 'NOTIFY_HEADER_START_CHECKOUT_CONFIRMATION') {
          $this->test_log($this->initialized ."\t=initialized at start " .$eventID);
          $this->test_log($this->field ."\t=field at start " .$eventID);
          $this->field= 200;
          $this->test_log($this->initialized ."\t=initialized at end " .$eventID);
          $this->test_log($this->field ."\t=field at end " .$eventID);
        } else if($eventID == 'NOTIFY_HEADER_END_CHECKOUT_CONFIRMATION') {
          $this->test_log($this->initialized ."\t=initialized at start " .$eventID);
          $this->test_log($this->field ."\t=field at start " .$eventID);
          $this->field= 300;
          $this->test_log($this->initialized ."\t=initialized at end " .$eventID);
          $this->test_log($this->field ."\t=field at end " .$eventID);
        } else if($eventID == 'NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS') {
          $this->test_log($this->initialized ."\t=initialized at start " .$eventID);
          $this->test_log($this->field ."\t=field at start " .$eventID);
          $this->field= 400;
          $this->test_log($this->initialized ."\t=initialized at end " .$eventID);
          $this->test_log($this->field ."\t=field at end " .$eventID);
        } else if($eventID == 'NOTIFY_HEADER_START_ACCOUNT_HISTORY_INFO') {
          $this->test_log($this->initialized ."\t=initialized at start " .$eventID);
          $this->test_log($this->field ."\t=field at start " .$eventID);
          $this->field= 500;
          $this->test_log($this->initialized ."\t=initialized at end " .$eventID);
          $this->test_log($this->field ."\t=field at end " .$eventID);
        }
      }
      
      /* write debug */
      function test_log($message) {
        $flog= fopen("/tmp/zc_log.txt","a");
        fwrite($flog,$message ."\n");
        fclose($flog);
      }
    } /* end testclass */
    ?>
    As you can see the class only changes the value of the $this->field and writes simple trace to the file. But the written zc_log.txt file contains only the output from the constructor method. It seems the update method is never called.
    What is wrong here?

 

 

Similar Threads

  1. Can I use notifiers to assist during product edits/updates?
    By vukan71 in forum General Questions
    Replies: 4
    Last Post: 6 Aug 2012, 04:59 PM
  2. How can I use Multiple mods that use same files?
    By sfklaas in forum General Questions
    Replies: 1
    Last Post: 8 May 2009, 10:27 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