Page 1 of 3 123 LastLast
Results 1 to 10 of 24
  1. #1
    Join Date
    Feb 2010
    Posts
    23
    Plugin Contributions
    0

    Default Notifier/Observer problem editing Real World Example 1

    Hi, i am having problem understanding the wiki developer's api tutorial. i followed the first real world example and it works perfectly fine. what i don't understand is "$this->attach($this, array('NOTIFIER_CART_ADD_CART_END'))" why is that the "$this" is attached to the event and in the real world example 1 is attached in a $_SESSION['class']. can anyone explain to me why. and also i have experimented in the real world example 1. i removed the condition "if ($_SESSION['cart']->show_total() >= $this->freeAmount && !$_SESSION['cart']->in_cart($this->freeProductID) )
    {

    }" and when i tried to add a product in the cart an error occur. the error is INTERNAL SERVER ERROR 500. can anyone tell me why is that happening it is just a statement why is an error comes up.

  2. #2
    Join Date
    Feb 2010
    Posts
    23
    Plugin Contributions
    0

    Default Re: Wiki Developer's API problem

    Anyone i haven't found a solution to this problem for over a month now

  3. #3
    Join Date
    Feb 2010
    Posts
    23
    Plugin Contributions
    0

    Default Re: Wiki - Developer's API problem

    any help would be appreciated
    Last edited by dale88; 20 Feb 2010 at 03:24 AM.

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,873
    Plugin Contributions
    96

    Default Re: Wiki - Developer's API problem

    I've seen 500-errors when my changes caused an infinite loop.

  5. #5
    Join Date
    Feb 2010
    Posts
    23
    Plugin Contributions
    0

    Default Re: Wiki - Developer's API problem

    i don't think its a looping issue cause i can't find any infinite loop in the code

  6. #6
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Wiki - Developer's API problem

    Best I can tell you is the line in the real world is calling the other one ...

    You could be addressing a class at the wrong point or something ...

    There is not enough information on what you are trying to do here ...

    Perhaps later, when wilt or DrByte are free and handy they can help you further on that ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  7. #7
    Join Date
    Feb 2010
    Posts
    23
    Plugin Contributions
    0

    Default Re: Wiki - Developer's API problem

    PHP Code:
    <?php
    /**
     * Observer class used to add a free product to the cart if the user spends more than $x
     *
     */
    class freeProduct extends base {
      
    /**
       * The threshold amount the customer needs to spend.
       * 
       * Note this is defined in the shops base currency, and so works with multi currency shops
       *
       * @var decimal
       */
      
    var $freeAmount 50;
      
    /**
       * The id of the free product.
       * 
       * Note. This must be a true free product. e.g. price = 0 Also make sure that if you don't want the customer
       * to be charged shipping on this, that you have it set correctly.
       *
       * @var integer
       */
      
    var $freeProductID 57;
      
    /**
       * constructor method
       * 
       * Attaches our class to the $_SESSION['cart'] class and watches for 2 notifier events.
       */
      
    function freeProduct() {
        
    $_SESSION['cart']->attach($this, array('NOTIFIER_CART_ADD_CART_END''NOTIFIER_CART_REMOVE_END'));
      }
      
    /**
       * Update Method
       * 
       * Called by observed class when any of our notifiable events occur
       *
       * @param object $class
       * @param string $eventID
       */
      
    function update(&$class$eventID$paramsArray = array()) {
      
        if (
    $eventID == 'NOTIFIER_CART_REMOVE_END' && (isset($_SESSION['freeProductInCart']) && $_SESSION['freeProductInCart'] == TRUE ))
      {
        if (!
    $_SESSION['cart']->in_cart($this->freeProductID))
        {
          
    $_SESSION['userRemovedFreeProduct'] = TRUE;
        }
      }

      if (!isset(
    $_SESSION['userRemovedFreeProduct']) || $_SESSION['userRemovedFreeProduct'] != TRUE
      {
        if (
    $_SESSION['cart']->show_total() >= $this->freeAmount && !$_SESSION['cart']->in_cart($this->freeProductID) ) // when this statement is removed i get an error  
        
    {    
          
          
    $_SESSION['cart']->add_cart($this->freeProductID);
          
    $_SESSION['freeProductInCart'] = TRUE;  
        }
      }
     
      if (
    $_SESSION['cart']->show_total() < $this->freeAmount && $_SESSION['cart']->in_cart($this->freeProductID) ) 
      {
        
    $_SESSION['cart']->remove($this->freeProductID);
      }

     
      if (
    $_SESSION['cart']->in_cart($this->freeProductID)) 
      {
        
    $_SESSION['cart']->contents[$this->freeProductID]['qty'] = 1;
      }
       
      }  
    }

    ?>
    thanks man. that is the code on wiki. "if ($_SESSION['cart']->show_total() >= $this->freeAmount && !$_SESSION['cart']->in_cart($this->freeProductID) ) " when that statement is remove i get an error the page wont load properly.
    Last edited by dale88; 21 Feb 2010 at 07:46 AM.

  8. #8
    Join Date
    Feb 2010
    Posts
    23
    Plugin Contributions
    0

    Default Re: Wiki - Developer's API problem

    can you tell me what does it mean when I attach an event to a class just like $_SESSION['cart']->attach($this, array('NOTIFIER_CART_ADD_CART_END', 'NOTIFIER_CART_REMOVE_END'));. Is it like I will include that script to that function?? that is why I can't easily use an add_cart method because other function is using that method?

  9. #9
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,927
    Plugin Contributions
    4

    Default Re: Wiki - Developer's API problem

    Hi,

    When you do

    $_SESSION['cart']->attach($this, array('NOTIFIER_CART_ADD_CART_END', 'NOTIFIER_CART_REMOVE_END'));

    you are telling the observer/notifier system(ONS) that you want to watch for 2 events 'NOTIFIER_CART_ADD_CART_END', 'NOTIFIER_CART_REMOVE_END'

    Whenever those events happen, the ONS will call the update method of the class you passed a reference for($this, which in the example is the freeProduct class)

    the update method for the freeProduct class will be called twice. Once when the NOTIFIER_CART_ADD_CART_END happens and again when the 'NOTIFIER_CART_REMOVE_END event happens.

    When the update method is called it receives a copy of the class that called it(In the example the $_SESSION['cart'] class, and details of the notifier that caused the event to happen. (ie either NOTIFIER_CART_ADD_CART_END or NOTIFIER_CART_REMOVE_END

    HTH

    Ian

  10. #10
    Join Date
    Feb 2010
    Posts
    23
    Plugin Contributions
    0

    Default Re: Wiki - Developer's API problem

    Thank you very much for the explanation, i kind of get it now how it works.

 

 
Page 1 of 3 123 LastLast

Similar Threads

  1. v151 Multiple Observer Classes for Same Notifier Event
    By Dave224 in forum General Questions
    Replies: 6
    Last Post: 8 Jul 2013, 11:07 PM
  2. Observer Notifier NOTIFIER_CART_GET_PRODUCTS_END Help
    By Celtic in forum General Questions
    Replies: 2
    Last Post: 9 Jun 2011, 11:22 PM
  3. Developers API Tutorial - A Real World Example
    By LissaE in forum General Questions
    Replies: 27
    Last Post: 11 Oct 2010, 02:57 PM
  4. observer/notifier the "base" class
    By David Bo in forum Basic Configuration
    Replies: 1
    Last Post: 3 Apr 2007, 02:23 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

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