Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2011
    Location
    Espoo, Finland
    Posts
    49
    Plugin Contributions
    0

    Default Using Observer/Notifier System in order class

    Hello,

    I'd like to change information, which is being prepared for sending by E-mail while placing the order.

    (In another words: I'd like to replace $email_order string and $html_msg array, which are being built in send_order_email method of order class)

    It seem's I should use one notifiers, provided in send_order_email method (v 1.5.5a), for example:
    PHP Code:
    $this->notify('NOTIFY_ORDER_EMAIL_BEFORE_PRODUCTS', array(), $email_order$html_msg); 
    (line ~1018 in includes/classes/order.php file)

    I know, how to build additional observer class, but I cannot understand, how to transfer back the updated $email_order and $html_msg from this observer back to send_order_email method (as $email_order and $html_msg aren't declared as global in send_order_email method)

    Could somebody please give me any advise?

    I have a strong feeling, I can not comprehend something and the solution should be very simply, otherwise I don't understand, for which purpose the mentioned notifer could be used.

    Many thanks in advance.


    BR, AR

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,491
    Plugin Contributions
    88

    Default Re: Using Observer/Notifier System in order class

    An observer-class solution is the way to go.

    You'll use the basic observer elements:
    Code:
    class my_class extends base
    {
        public __construct ()
        {
            $this->attach ('NOTIFY_ORDER_EMAIL_BEFORE_PRODUCTS');
        }
    
        public update (&$class, $event, $roParm1, &$rwParm2, &$rwParm3, &$rwParm4)  // Up to &$rwParm9, depending on the notifier
        {
             <insert your processing here>
        }
    }
    For the notifier you're interested in, when your update function receives control:
    $class ....... contains a reference to the $order object, so you've got full R/W access to the order's elements
    $event ...... contains 'NOTIFY_ORDER_EMAIL_BEFORE_PRODUCTS', in case your observer handles multiple events
    $roParm1 ... contains an empty array
    $rwParm2 ... contains a reference to the order-class' $email_order variable
    $rwParm3 ... contains a reference to the order-class' $html_msg variable

    That said, upon receipt of that "notification" you have r/w access to the entire $order object (some information might not be all there, depending on the point at which the notification was raised) and to $rwParm2 and $rwParm3 (up to $rwParm9). Making a change to $rwParm2 results in a change to $email_order, for example.

  3. #3
    Join Date
    Apr 2011
    Location
    Espoo, Finland
    Posts
    49
    Plugin Contributions
    0

    Default Re: Using Observer/Notifier System in order class

    Hello,

    Many thanks for your reply!

    I was exactly writing an additional message displaying the observer's code, which I've used for tests, when I got your reply.

    It seems, my code is very similar to yours:

    Code:
    <?php // class.ordersTokenHandling.php
    
    class ordersTokenHandling extends base {
    
      public function __construct() {
        $this->attach($this, array('NOTIFY_ORDER_EMAIL_BEFORE_PRODUCTS'));
      }
    
      public function update(&$class, $eventID, $paramsArray = array(), $param1, $param2 = array())
      {
    	  // echo "Old msg:" . $param2['ORDER_COMMENTS'] . "<br />";
    	  
          $param2['ORDER_COMMENTS'] = 'Modified in observer'; 	
    	
      }
    }
    // EOF
    ...But $html_msg['ORDER_COMMENTS'] is remains unchanged in send_order_email method... Where is my mistake?

    I'd be very thankful for your advice.

    BR, AR

    PS I checked - my observer class is being called from mentioned method
    PPS I have implemented my test on 'straight-from-the-box' Zen_cart v.1.5.5a...
    Last edited by yesaul; 26 Sep 2016 at 02:07 PM.

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,491
    Plugin Contributions
    88

    Default Re: Using Observer/Notifier System in order class

    You're missing the "reference" designation on your observer's update function (and you really don't want those default values, either):
    Code:
    <?php // class.ordersTokenHandling.php
    
    class ordersTokenHandling extends base {
    
      public function __construct() {
        $this->attach($this, array('NOTIFY_ORDER_EMAIL_BEFORE_PRODUCTS'));
      }
    
      public function update(&$class, $eventID, $paramsArray, &$param1, &$param2)
      {
    	  // echo "Old msg:" . $param2['ORDER_COMMENTS'] . "<br />";
    	  
          $param2['ORDER_COMMENTS'] = 'Modified in observer'; 	
    	
      }
    }
    // EOF

  5. #5
    Join Date
    Apr 2011
    Location
    Espoo, Finland
    Posts
    49
    Plugin Contributions
    0

    Default Re: Using Observer/Notifier System in order class

    Hello,

    Many thanks for your advice! Everything is running smooth now!

    (Anyway there was one thing I correctly assumedy: the solution is really simply :-) )

    Thank you again and best regards,

    AR

  6. #6
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,491
    Plugin Contributions
    88

    Default Re: Using Observer/Notifier System in order class

    Woo-hoo! I'm happy to have helped.

 

 

Similar Threads

  1. Observer Notifier NOTIFIER_CART_GET_PRODUCTS_END Help
    By Celtic in forum General Questions
    Replies: 2
    Last Post: 9 Jun 2011, 11:22 PM
  2. Notifier/Observer problem editing Real World Example 1
    By dale88 in forum Templates, Stylesheets, Page Layout
    Replies: 23
    Last Post: 12 Mar 2010, 02:03 AM
  3. observer/notifier the "base" class
    By David Bo in forum Basic Configuration
    Replies: 1
    Last Post: 3 Apr 2007, 02:23 AM
  4. Is notifier/observer system good for this?
    By s_p_ike in forum General Questions
    Replies: 5
    Last Post: 7 Aug 2006, 10:16 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