Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Observer not working

    I've been working all day trying to get an observer to work. I can't find anything wrong. Maybe a set of fresh eyes can spot the error.

    The notifier is in includes/functions/functions_osh_update.php, line 127:
    Code:
    $GLOBALS['zco_notifier']->notify('ZEN_UPDATE_ORDERS_HISTORY_SET_ORDER_UPDATE_MESSAGE', $orders_id, $email_order_message);
    The observer code is located in includes/classes/observers/auto.modify_order_status.php The code is:
    Code:
    <?php
    /**
     * observer class to modify customer order status email
     *
     * @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: auto.modify_order_status.php   $
     */
    class zcObserverModifyOrderStatus extends base {
    
     /**  constructor method !
       *
       * Attach observer class to the global $zco_notifier and watch for a single notifier event.
       */
      function __construct() {
        global $zco_notifier;
        $zco_notifier->attach($this, array('ZEN_UPDATE_ORDERS_HISTORY_SET_ORDER_UPDATE_MESSAGE'));
        // notifier located in includes/functions/functions_osh_update.php
      }
    
     /**   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()) {
        die("in observer");
      } // end of function update
    } // end of class
    The code before the notifier is executed from testing, but several tests in the observer, including die, show the observer isn't being executed. I've checked the documentation and can find no mistake in the code. There are no errors logged. I'm changing the order status from the admin order list and the status is changed correctly, and order status update emails are sent.

    Dave
    php7.3, zc157c
    Last edited by Dave224; 8 Sep 2021 at 09:54 PM.

  2. #2
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,690
    Plugin Contributions
    9

    Default Re: Observer not working

    dave,
    i think your code should work. i'll tell u why i do not think it works in a second.

    for whatever reason, i like and use the following format. i think the new version of array is much easier to read, and there is no need for the global $zco_notifier.

    PHP Code:
    <?php

        
    class zcObserverModifyOrderStatus extends base
        
    {
            public function 
    __construct()
            {
                
    $this->attach(
                    
    $this,
                    [
                        
    'ZEN_UPDATE_ORDERS_HISTORY_SET_ORDER_UPDATE_MESSAGE',
                    ]
                );
            }

            public function 
    update(&$class$eventID, &$p1, &$p2, &$p3, &$p4)
            {
                switch (
    $eventID) {
                    case 
    'ZEN_UPDATE_ORDERS_HISTORY_SET_ORDER_UPDATE_MESSAGE':
                        die(
    __FILE__ ':' __LINE__);
                        break;
                    default:
                        break;
                }
            }
        }
    i think your code is NOT working because you have it in the storefront and not in the admin.

    while the function may be the storefront, it's use is in the admin; therefore the observer needs to be in the admin.

    best.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

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

    Default Re: Observer not working

    You are indeed correct. Moving the observer file to admin solved my problem

    Thank you for the tip on the format you like. I thought you had to use the $zco_notifier for notifiers in procedural code, but I guess not anymore.

    Thanks again!

  4. #4
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,690
    Plugin Contributions
    9

    Default Re: Observer not working

    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

 

 

Similar Threads

  1. v157 [Done v157a] Observer code not always executed.
    By mc12345678 in forum Bug Reports
    Replies: 0
    Last Post: 3 Jul 2020, 11:20 PM
  2. Replies: 5
    Last Post: 12 Dec 2017, 01:48 PM
  3. v155 Custom observer class stopped working after upgrade to v1.5.5a
    By d9000 in forum General Questions
    Replies: 7
    Last Post: 9 Jun 2016, 03:30 PM
  4. add to cart not working...currency not working
    By pcdesigns in forum Templates, Stylesheets, Page Layout
    Replies: 9
    Last Post: 12 Jun 2008, 05:03 AM
  5. modifying shipping w/ observer
    By magichat in forum General Questions
    Replies: 0
    Last Post: 2 Nov 2006, 08:35 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