Page 1 of 3 123 LastLast
Results 1 to 10 of 28
  1. #1
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Developers API Tutorial - A Real World Example

    I am trying to get this working and I am going wrong somewhere LOL I wonder if someone with more knowledge than me can tell me where I am going wrong?

    http://www.zen-cart.com/wiki/index.p..._World_Example

    I have copied the following code into includes/auto_loaders in a file called config.freeProduct.php

    PHP Code:
    <?php

    $autoLoadConfig
    [90][] = array('autoType'=>'class',
                                  
    'loadFile'=>'observers/class.freeProduct.php');
    $autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
                                  
    'className'=>'freeProduct',
                                  
    'objectName'=>'freeProduct');

    ?>
    And then the code underneath in the tutorial (changing the product id to my free product id) into includes/classes/observers/class.freeProduct.php

    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 10;
      
    /**
       * 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 422;
      
    /**
       * 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) {
        if (
    $_SESSION['cart']->show_total() >= $this->freeAmount && !$_SESSION['cart']->in_cart($this->freeProductID) ) {
          
    $_SESSION['cart']->add_cart($this->freeProductID);
        }
        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;
        }
      }
    }
    ?>
    Uploaded them to the relevant directories...but when I added a product to cart I got a blank page, so I know I am missing something OR there is a mistake somewhere and any help would be appreciated to get this working because I really wanna LOL

    **edit...I took the files out and I am still getting blank page, so maybe it's not this at fault....more digging for me it seems LOL
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

  2. #2
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Re: Developers API Tutorial - A Real World Example

    Update...I needed to clear Firefox cache and reboot, this was the cause of the blank page....please help me see where I was going wrong if someone knows lol
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

  3. #3
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Re: Developers API Tutorial - A Real World Example

    I ran the debugging utility, I didn't get a chance to before LOL and it gave me three log files:

    1.

    Code:
    [07-Jan-2009 16:24:21] PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/christon/public_html/store/includes/auto_loaders/config.freeProduct.php:9) in /home/christon/public_html/store/includes/functions/sessions.php on line 108
    [07-Jan-2009 16:24:21] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/christon/public_html/store/includes/auto_loaders/config.freeProduct.php:9) in /home/christon/public_html/store/includes/init_includes/init_templates.php on line 78
    [07-Jan-2009 16:24:21] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/christon/public_html/store/includes/auto_loaders/config.freeProduct.php:9) in /home/christon/public_html/store/includes/functions/functions_general.php on line 44
    2.

    Code:
    [07-Jan-2009 16:24:14] PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/christon/public_html/store/includes/auto_loaders/config.freeProduct.php:9) in /home/christon/public_html/store/includes/functions/sessions.php on line 108
    [07-Jan-2009 16:24:14] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/christon/public_html/store/includes/auto_loaders/config.freeProduct.php:9) in /home/christon/public_html/store/includes/init_includes/init_templates.php on line 78
    3.

    Code:
    [07-Jan-2009 16:24:25] PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/christon/public_html/store/includes/auto_loaders/config.freeProduct.php:9) in /home/christon/public_html/store/includes/functions/sessions.php on line 108
    [07-Jan-2009 16:24:25] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home/christon/public_html/store/includes/auto_loaders/config.freeProduct.php:9) in /home/christon/public_html/store/includes/init_includes/init_templates.php on line 78
    Line 44 of functions_general.php:

    PHP Code:
        header('Location: ' $url); 
    Line 78 of init_templates.php:

    PHP Code:
      header("Content-Type: text/html; charset=" CHARSET); 
    Lines 108-110 of sessions.php:

    PHP Code:
        $temp session_start();
        if (!isset(
    $_SESSION['securityToken'])) {
          
    $_SESSION['securityToken'] = md5(uniqid(rand(), true));
        } 
    If anyone can point me in the right direction to what these mean and how to fix I would be very grateful lol
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

  4. #4
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Re: Developers API Tutorial - A Real World Example

    When adding these, do they need to have different numbers for the autoLoadConfig?

    Because I have reward points mod installed and it is $autoLoadConfig[90] as well, plus the config file is called config.reward_points.core.php and I am not sure if mine needs to have that .core bit added as well?
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

  5. #5
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Re: Developers API Tutorial - A Real World Example

    OH....MY....GOD I fixed it!! After MUCH forum searching I finally found that I had a space after the closing php tag in one of the files...happy to report that this is now working and working exactly the way I want!! LOL
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

  6. #6
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: Developers API Tutorial - A Real World Example

    Glad you found it.

    This is the reason why nowadays we leave the final php tag off the end of files. The php interpreter will insert it automatically without causing the difficult-to-find problem that you experienced.
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  7. #7
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Re: Developers API Tutorial - A Real World Example

    Thanx LOL that's what I get for just ccp'ing into Notepad, I usually use Notepad++ and would have noticed an extra space straight away if I had used that first lol

    Amazing how one tiny lil extra space can cause so much grief huh
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

  8. #8
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Re: Developers API Tutorial - A Real World Example

    Ok run into another problem LOL

    My store carries only downloadable products, I installed the hide categories mod so I could have the free gift hidden until it appears in the cart...and while the product is being added to the cart, the attribute is not added with it, ie it's not showing the download and when ppl go to checkout they are getting the message that we are not shipping to their region at this time, as if the product is appearing as a 'virtual' product, when in fact it's not, any ideas?

    I don't want this product appearing out in the public listings but I need it to add the attributes to cart as well lol
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

  9. #9
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Re: Developers API Tutorial - A Real World Example

    I don't understand this and I cannot figure it out, before the product is auto added to cart, the radio button for the download attribute is selected, but after it's added if I go back to the page the button is not selected and the download itself is not added to the cart with the product

    http://www.havendesignz.com/store/fr...ree-gift-p-423

    I make the category visible it does the same thing...how on earth do I get this to add the download attribute to cart as well? lol
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

  10. #10
    Join Date
    Oct 2007
    Location
    Australia
    Posts
    843
    Plugin Contributions
    0

    Default Re: Developers API Tutorial - A Real World Example

    Can someone who knows how to write this tell me if I need to add something into this code to get it to bring the attributes into the cart as well and exactly what I'd need to add? If I add the product physically, the atttributes come as well lol

    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 10;
      
    /**
       * 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 423;
      
    /**
       * 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) {
        if (
    $_SESSION['cart']->show_total() >= $this->freeAmount && !$_SESSION['cart']->in_cart($this->freeProductID) ) {
          
    $_SESSION['cart']->add_cart($this->freeProductID);
        }
        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;
        }
      }
    }
    ?>
    Sorry for 'talking to myself' LOL I am hoping someone who can help me stumbles across this LOL I am trying to figure it out on my own and getting exactly nowhere lol
    HunnyBee Design
    "A man's manners are a mirror in which he shows his portrait." ~ Johann Wolfgang von Goethe

 

 
Page 1 of 3 123 LastLast

Similar Threads

  1. Error 404 accessing example.com/store in xampp tutorial
    By mbielin in forum Installing on a Windows Server
    Replies: 6
    Last Post: 11 Nov 2010, 10:24 AM
  2. Notifier/Observer problem editing Real World Example 1
    By dale88 in forum Templates, Stylesheets, Page Layout
    Replies: 23
    Last Post: 12 Mar 2010, 02:03 AM
  3. Is the Wiki Dev/API tutorial the best way to learn Zencart structure ?
    By DogTags in forum Contribution-Writing Guidelines
    Replies: 2
    Last Post: 23 Dec 2009, 03:59 PM
  4. Developers API Tutorials question
    By mipavluk in forum General Questions
    Replies: 3
    Last Post: 25 Sep 2009, 04:55 AM

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