Results 1 to 10 of 24

Hybrid View

  1. #1
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: Notifier/Observer problem editing Real World Example 1

    Quote Originally Posted by dale88 View Post
    I was experimenting on this code on WIKI API tutorial. i tried to remove this condition statement " if ($_SESSION['cart']->show_total() < $this->freeAmount && $_SESSION['cart']->in_cart($this->freeProductID) )
    {
    " that is when the error comes up when i'm trying to add a product in the cart. i scanned shopping cart class and still haven't figured why it has to have that statement for the class to work
    But ... an "if" clause which contains an opening brace { must also include a closing brace }
    And, if you only removed the "if" condition and its opening brace, then you've created an ugly PHP error situation.
    If you really want to remove that particular "if" clause, you need to remove the *whole* thing:
    Code:
      if ($_SESSION['cart']->show_total() < $this->freeAmount && $_SESSION['cart']->in_cart($this->freeProductID) ) 
      {
        $_SESSION['cart']->remove($this->freeProductID);
      }
    I recommend going back to the PHP website and studying the code syntax before adjusting further PHP code.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

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

    Default Re: Notifier/Observer problem editing Real World Example 1

    Yes i know it will cause php errors if you don't remove the closing bracket. i removed the condition including the closing bracket.

    so the script looks like this
    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 100;
      
    /**
       * 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 15;
      
    /**
       * 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
      {

          
    $_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;
      }
       
      }  
    }
    ?>

  3. #3
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: Notifier/Observer problem editing Real World Example 1

    Maybe because you're removing some critical logic which protects against re-adding the item to the cart if it's already there? perhaps thus causing an endless loop?

    I'm not sure why you would choose to remove that part of the logic in the first place.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

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

    Default Re: Notifier/Observer problem editing Real World Example 1

    I got you. i wanna know the details why is that statement important on the logic. I'm just experimenting the code for learning reasons. Can't seem to find out why is that statement caused errors when removed. all its do is check if amount is more than the free amount. for me, when that statement is removed it should automatically adds the free product on the cart regardless of the amount in the cart. that's what i think the program flow is.

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

    Default Re: Notifier/Observer problem editing Real World Example 1

    i looked at the add cart function on shopping cart class. there is an $this->in_cart statement there, so the product is also checked in there. and also i tried removing just the "$_SESSION['cart']->show_total() >= $this->freeAmount" and did not remove "!$_SESSION['cart']->in_cart($this->freeProductID" same error occurs. so the in_cart statement is not the issue here

  6. #6
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: Notifier/Observer problem editing Real World Example 1

    Feel free to enlighten us when you figure out why.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

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

    Default Re: Notifier/Observer problem editing Real World Example 1

    Sure but i was hoping if anyone could help me

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

    Default Re: Notifier/Observer problem editing Real World Example 1

    After scanning through the code. i guess the problem is a looping error. if statement is remove it will cause an infinite loop

 

 

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