Results 1 to 10 of 24

Threaded View

  1. #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.

 

 

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