Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2013
    Location
    Dorset, UK
    Posts
    121
    Plugin Contributions
    0

    Default Using class observers

    Hi,

    I am rebuilding my old site from zen v1.54 to 1.5.5f. My php is v5.6.32 (unchanged from v1.54).

    I used to use the "real world example" in the wiki here. I have simply copied the files from my old installation to the new. Unfortunately that didn't work! Now, when I add anything to the cart I get a blank page, if I restore the session the item wasn't added and no free gift!

    Here is what I have had working well in v1.54

    File 1 - catalogue/includes/auto_loaders/config.freeProduct.php
    Code:
    <?php
    /**
     * Observer class used to add a free product to the cart if the user spends more than $x
     *
     */
    $autoLoadConfig[10][] = array('autoType'=>'class',
                                  'loadFile'=>'observers/class.freeProduct.php');
    $autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
                                  'className'=>'freeProduct',
                                  'objectName'=>'freeProduct');
    ?>
    File 2 - catalogue/includes/classes/observers/class.freeProduct.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 = 15.01; 
      /** 
       * 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 = 239; 
      /** 
       * 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')); 
        $_SESSION['cart']->attach($this, array('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) { 
    if ($_SESSION['cart']->show_total() >= $this->freeAmount && !$_SESSION['cart']->in_cart($this->freeProductID) )    
        { 
          $_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; 
      } 
      } 
     } 
    ?>
    What has changed in zen 1.55f? Anyone any clues what I have missed?

    Error log:
    Code:
    	[29-Jun-2018 04:01:51 Europe/London] Request URI: /dev/final/index.php?main_page=index&cPath=5&sort=20a&action=buy_now&products_id=18&zenid=cc7772d2edee84f77ab054932ac38a63, IP address: 84.84.84.84
    #1  session_start() called at [/home/#######/public_html/dev/final/includes/functions/sessions.php:107]
    #2  zen_session_start() called at [/home/#######/public_html/dev/final/includes/init_includes/init_sessions.php:86]
    #3  require(/home/#######/public_html/dev/final/includes/init_includes/init_sessions.php) called at [/home/#######/public_html/dev/final/includes/autoload_func.php:48]
    #4  require(/home/#######/public_html/dev/final/includes/autoload_func.php) called at [/home/#######/public_html/dev/final/includes/application_top.php:170]
    #5  require(/home/#######/public_html/dev/final/includes/application_top.php) called at [/home/#######/public_html/dev/final/index.php:26]
    
    [29-Jun-2018 04:01:51 Europe/London] PHP Warning:  session_start(): Cannot send session cookie - headers already sent by (output started at /home/#######/public_html/dev/final/includes/auto_loaders/config.freeProduct.php:11) in /home/#######/public_html/dev/final/includes/functions/sessions.php on line 107
    [29-Jun-2018 04:01:51 Europe/London] Request URI: /dev/final/index.php?main_page=index&cPath=5&sort=20a&action=buy_now&products_id=18&zenid=cc7772d2edee84f77ab054932ac38a63, IP address: 84.84.84.84
    #1  session_start() called at [/home/#######/public_html/dev/final/includes/functions/sessions.php:107]
    #2  zen_session_start() called at [/home/#######/public_html/dev/final/includes/init_includes/init_sessions.php:86]
    #3  require(/home/#######/public_html/dev/final/includes/init_includes/init_sessions.php) called at [/home/#######/public_html/dev/final/includes/autoload_func.php:48]
    #4  require(/home/#######/public_html/dev/final/includes/autoload_func.php) called at [/home/#######/public_html/dev/final/includes/application_top.php:170]
    #5  require(/home/#######/public_html/dev/final/includes/application_top.php) called at [/home/#######/public_html/dev/final/index.php:26]
    
    [29-Jun-2018 04:01:51 Europe/London] PHP Warning:  session_start(): Cannot send session cache limiter - headers already sent (output started at /home/#######/public_html/dev/final/includes/auto_loaders/config.freeProduct.php:11) in /home/#######/public_html/dev/final/includes/functions/sessions.php on line 107
    [29-Jun-2018 04:01:51 Europe/London] Request URI: /dev/final/index.php?main_page=index&cPath=5&sort=20a&action=buy_now&products_id=18&zenid=cc7772d2edee84f77ab054932ac38a63, IP address: 84.84.84.84
    #1  header() called at [/home/#######/public_html/dev/final/includes/init_includes/init_templates.php:78]
    #2  require(/home/#######/public_html/dev/final/includes/init_includes/init_templates.php) called at [/home/#######/public_html/dev/final/includes/autoload_func.php:48]
    #3  require(/home/#######/public_html/dev/final/includes/autoload_func.php) called at [/home/#######/public_html/dev/final/includes/application_top.php:170]
    #4  require(/home/#######/public_html/dev/final/includes/application_top.php) called at [/home/#######/public_html/dev/final/index.php:26]
    
    [29-Jun-2018 04:01:51 Europe/London] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/#######/public_html/dev/final/includes/auto_loaders/config.freeProduct.php:11) in /home/#######/public_html/dev/final/includes/init_includes/init_templates.php on line 78
    [29-Jun-2018 04:01:51 Europe/London] Request URI: /dev/final/index.php?main_page=index&cPath=5&sort=20a&action=buy_now&products_id=18&zenid=cc7772d2edee84f77ab054932ac38a63, IP address: 84.84.84.84
    #1  header() called at [/home/#######/public_html/dev/final/includes/functions/functions_general.php:46]
    #2  zen_redirect() called at [/home/#######/public_html/dev/final/includes/classes/shopping_cart.php:2030]
    #3  shoppingCart->actionBuyNow() called at [/home/#######/public_html/dev/final/includes/main_cart_actions.php:49]
    #4  require(/home/#######/public_html/dev/final/includes/main_cart_actions.php) called at [/home/#######/public_html/dev/final/includes/init_includes/init_cart_handler.php:44]
    #5  require(/home/#######/public_html/dev/final/includes/init_includes/init_cart_handler.php) called at [/home/#######/public_html/dev/final/includes/autoload_func.php:48]
    #6  require(/home/#######/public_html/dev/final/includes/autoload_func.php) called at [/home/#######/public_html/dev/final/includes/application_top.php:170]
    #7  require(/home/#######/public_html/dev/final/includes/application_top.php) called at [/home/#######/public_html/dev/final/index.php:26]
    
    [29-Jun-2018 04:01:51 Europe/London] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/#######/public_html/dev/final/includes/auto_loaders/config.freeProduct.php:11) in /home/#######/public_html/dev/final/includes/functions/functions_general.php on line 46
    Honestly, any suggestions appreciated.

    Oh yeah, if I remove the two files config.freeProduct.php & class.freeProduct.php the errors stops immediately!

  2. #2
    Join Date
    Nov 2013
    Location
    Dorset, UK
    Posts
    121
    Plugin Contributions
    0

    Default Re: Using class observers

    Solved..... After reading this post here it was all just an empty line in a copy and paste...….. Darn it 2 hours gone

 

 

Similar Threads

  1. Using observers to modify original function
    By necroside in forum General Questions
    Replies: 1
    Last Post: 11 Apr 2017, 05:18 AM
  2. Writing observers and the &$class parameter
    By audleman in forum Basic Configuration
    Replies: 2
    Last Post: 15 Oct 2008, 07:08 PM
  3. Observers and redirects
    By audleman in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 10 Sep 2008, 05:19 PM
  4. Using Observers instantiated from application-top.php?
    By enigmabomb in forum General Questions
    Replies: 7
    Last Post: 24 Jan 2008, 10:29 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