Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,690
    Plugin Contributions
    9

    Default observer notifier question/opinions...

    i am curious about opinions. in the past, i have stuck to the docs, with regards to updating values using an observer, ie $parm1 is read only and 2-9 are update-able. see:

    https://docs.zen-cart.com/dev/code/notifiers/#update

    so if one were to look at this observer:
    PHP Code:
    $zco_notifier->notify('NOTIFY_SEARCH_ORDERBY_STRING'$listing_sql); 
    the $listing_sql is NOT update-able as it is in $p1 position. however, if we were to add the $listing_sql to the global line in the update function, we can now change it, ie:

    PHP Code:
          public function update(&$class$eventID, &$p1, &$p2, &$p3, &$p4)
            {
                global 
    $listing_sql;
                switch (
    $eventID) {
                    case 
    'NOTIFY_SEARCH_ORDERBY_STRING':
                        
    $listing_sql 'whatever the bloody heck i like';
                        break;
                }
            } 
    i am curious what the downside may be on this approach as well as whether it is worthy of including in the docs.

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

  2. #2
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,694
    Plugin Contributions
    123

    Default Re: observer notifier question/opinions...

    The downside is the usual downside of using global variables; you create code that is much harder to debug and less self-documenting.

    If you feel that it's important to be able to change the first parameter, the better approach (which has been used in the past) is to simply update

    $zco_notifier->notify('NOTIFY_SEARCH_ORDERBY_STRING', $listing_sql);

    to

    $zco_notifier->notify('NOTIFY_SEARCH_ORDERBY_STRING', $listing_sql, $listing_sql);

    This is upwardly compatible and the intent is clear.
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

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

    Default Re: observer notifier question/opinions...

    Quote Originally Posted by swguy View Post
    The downside is the usual downside of using global variables; you create code that is much harder to debug and less self-documenting.

    If you feel that it's important to be able to change the first parameter, the better approach (which has been used in the past) is to simply update

    $zco_notifier->notify('NOTIFY_SEARCH_ORDERBY_STRING', $listing_sql);

    to

    $zco_notifier->notify('NOTIFY_SEARCH_ORDERBY_STRING', $listing_sql, $listing_sql);

    This is upwardly compatible and the intent is clear.
    i am not a fan of this idea. the whole point is to not modify core code. changing the core code, i might as well as change the listing sql on that section of the code.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  4. #4
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,694
    Plugin Contributions
    123

    Default Re: observer notifier question/opinions...

    I'm suggesting you do this as a PR for inclusion into a future release. Like I said, this has been done in the past by people who needed exactly what you need.

    Here's an example:

    Zen Cart 1.5.6:
    $zco_notifier->notify('NOTIFY_EMAIL_BEFORE_PROCESS_ATTACHMENTS', array('attachments'=>$attachments_list, 'module'=>$module));

    Zen Cart 1.5.7:
    $zco_notifier->notify('NOTIFY_EMAIL_BEFORE_PROCESS_ATTACHMENTS', array('attachments'=>$attachments_list, 'module'=>$module), $mail, $attachments_list);

    Someone needed to be able to modify $attachments_list.
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

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

    Default Re: observer notifier question/opinions...

    i misunderstood you.

    when and if PRs start getting merged again, perhaps i will create one.

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

 

 

Similar Threads

  1. Using Observer/Notifier System in order class
    By yesaul in forum Code Collaboration
    Replies: 5
    Last Post: 26 Sep 2016, 07:24 PM
  2. v151 Multiple Observer Classes for Same Notifier Event
    By Dave224 in forum General Questions
    Replies: 6
    Last Post: 8 Jul 2013, 11:07 PM
  3. Observer Notifier NOTIFIER_CART_GET_PRODUCTS_END Help
    By Celtic in forum General Questions
    Replies: 2
    Last Post: 9 Jun 2011, 11:22 PM
  4. 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
  5. 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