Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2012
    Posts
    450
    Plugin Contributions
    0

    Default Detach Notifier Won't Work

    I have an observer triggered by multiple notifiers. I want to process one of the notifiers only the first time it triggers the observer. I have used the following code in the observer:
    Code:
    $this->detach($this, ['the notifier']);
    where 'the notifier' is the same value as in attach in the constructor. But it doesn't detach the observer. What's wrong?

    If it makes any difference, the observer processes multiple notifiers in a switch block in the update function, each notifier in a case - break block. The detach code is in only one notifier case block, just before the break statement.

    Dave
    zc1.5.8a, OPC 2.5.2, Bootstrap 3.7.1, SBA, zx_point-of-sale 2.5

  2. #2
    Join Date
    Jul 2012
    Posts
    16,797
    Plugin Contributions
    17

    Default Re: Detach Notifier Won't Work

    Did this code work in a previous Zen Cart version?
    Is there an escape of some sort prior to the detach call such as a return to exit the area?
    What assurance is there that the detach method was called?

    Mentioned that all processing is being done under the old class method of just update. Does an observer class method name camel cased exist or one that is the observer name in all lower case exist? (Guess repeating a previous question about how sure the detach method was called. )

    Going to go look at the ZC code for detach to see what other possibilities might exist. The fact that not reporting some firm of execution error like that the detach method doesn't exist seems to indicate the observer class has proper class extension.

    Mentioned though that using Zen Cart 1.5.8. What sub version? I remember there was a version released that had some observer related issues, but don't remember which at the moment and may be unrelated.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

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

    Default Re: Detach Notifier Won't Work

    Quote Originally Posted by mc12345678 View Post
    Did this code work in a previous Zen Cart version?
    Is there an escape of some sort prior to the detach call such as a return to exit the area?
    What assurance is there that the detach method was called?

    Mentioned that all processing is being done under the old class method of just update. Does an observer class method name camel cased exist or one that is the observer name in all lower case exist? (Guess repeating a previous question about how sure the detach method was called. )

    Going to go look at the ZC code for detach to see what other possibilities might exist. The fact that not reporting some firm of execution error like that the detach method doesn't exist seems to indicate the observer class has proper class extension.

    Mentioned though that using Zen Cart 1.5.8. What sub version? I remember there was a version released that had some observer related issues, but don't remember which at the moment and may be unrelated.
    mc12345678,
    • This is new code and the first time I have used the detach method.
    • There is no escape or return in the observer for the notifier in question.
    • A trigger_error in method detach indicates that the method is being called multiple times.
    • The observer class name is zcObserver immediately followed by camel case name, e.g., zcObserverMyClassName, with the file name of auto.my_class_name.php. The switch statement is based on $eventID, and the case statement is for the specific notifier.
    • No error is being reported.
    • zencart version is 1.5.8a.

    The fact that the detach method is called indicates to me that the arguments in the call are wrong, hence the inclusion of the code in my original post. There are examples by another developer of using the detach method that look exactly like what I used (but I can not state that they work).

    The attach method is in the same form as the detach form in the original post.

    I believe I have followed the guidance in the developer docs for the observer/notifier system.

    Hope this helps.

    Dave

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,337
    Plugin Contributions
    94

    Default Re: Detach Notifier Won't Work

    Dave, it sounds like you're mixing the CamelCased and update (with switch) methods of 'observing'. You could either post your code here or shoot it to me via direct email.

  5. #5
    Join Date
    Jun 2012
    Posts
    450
    Plugin Contributions
    0

    Default Re: Detach Notifier Won't Work

    Quote Originally Posted by lat9 View Post
    Dave, it sounds like you're mixing the CamelCased and update (with switch) methods of 'observing'. You could either post your code here or shoot it to me via direct email.
    I changed the observer to manually loaded with update method and switch and got the same results. Detach is still not working.

    I could find nothing in the docs that said don't use update with auto-loaded observers, but I could have missed it. For what it's worth, I've been using auto loaded observers with update method and switch in zencart 157c for years. Should the docs be updated on this point?

    Dave

  6. #6
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,337
    Plugin Contributions
    94

    Default Re: Detach Notifier Won't Work

    Quote Originally Posted by Dave224 View Post
    I changed the observer to manually loaded with update method and switch and got the same results. Detach is still not working.

    I could find nothing in the docs that said don't use update with auto-loaded observers, but I could have missed it. For what it's worth, I've been using auto loaded observers with update method and switch in zencart 157c for years. Should the docs be updated on this point?

    Dave
    My bad, I thought you were referring to the 'update' vs camelCased function names within the observer.

    FWIW, I've had no issues using $this->detach in various observers zc157+.

  7. #7
    Join Date
    Jun 2012
    Posts
    450
    Plugin Contributions
    0

    Default Re: Detach Notifier Won't Work

    Quote Originally Posted by lat9 View Post
    My bad, I thought you were referring to the 'update' vs camelCased function names within the observer.

    FWIW, I've had no issues using $this->detach in various observers zc157+.
    My bad too. My expectations of the detach method were all wrong. Thanks to lat9, I now understand that the detach method detaches the notifier for the remainder of the current page load, not for the remainder of the session (which is what I wanted). If I had thought about how a browser and server interact, the correct expectation of detach would be obvious. So back to setting a $_SESSION variable and testing it in the observer.

    Dave

 

 

Similar Threads

  1. background won't work
    By chrissiemags in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 22 Sep 2008, 04:44 PM
  2. My EZ Pages Won't Work
    By srturner47 in forum General Questions
    Replies: 2
    Last Post: 1 Dec 2007, 02:57 AM
  3. contact us won't work
    By mex in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 23 Mar 2007, 11:30 PM
  4. /admin won't work
    By evolive in forum General Questions
    Replies: 1
    Last Post: 2 Nov 2006, 10:31 AM

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