Page 3 of 3 FirstFirst 123
Results 21 to 28 of 28
  1. #21
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: Developers API Tutorial - A Real World Example

    You can get the IDs from the Option Name Manager and Option Value Manager pages. They're in the left hand column of the table towards the top of the page.
    Kuroi Web Design and Development | Twitter

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

  2. #22
    Join Date
    Jun 2007
    Location
    Posadas, Misiones, Argentina
    Posts
    220
    Plugin Contributions
    0

    Default Re: Developers API Tutorial - A Real World Example

    ok... i check option name manager...

    ID=1 for download 01

    option value manager...

    ID=1 for download 01

    you think my code is ok?

    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 = 1;
     /**
      * 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 = 4660;
     /**
      * 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) ) {
      $productId = 4660;
      $attributeIds[1] = 1;
      $_SESSION['cart']->add_cart($productId, 1, $attributeIds);
      }
      if ($_SESSION['cart']->show_total() < $this->freeAmount && $_SESSION['cart']->in_cart($this->freeProductID) ) {
      $productId = 4660;
      $attributeIds[1] = 1;
      $_SESSION['cart']->remove($productId, 1, $attributeIds);
      }
      if ($_SESSION['cart']->in_cart($this->freeProductID)) {
       $_SESSION['cart']->contents[$this->freeProductID]['qty'] = 1;
      }
     }
    }
    ?>
    because when I try to add to cart a product, I get error 500 Internal Server Error
    Last edited by mipavluk; 26 Sep 2009 at 09:47 PM.
    URL: http://www.littledreamswarehouse.com/shop
    Zen Version: 1.3.89h
    Zen Template: orange modified

  3. #23
    Join Date
    Jun 2007
    Location
    Posadas, Misiones, Argentina
    Posts
    220
    Plugin Contributions
    0

    Default Re: Developers API Tutorial - A Real World Example

    please... I need just a bit more help here!
    thanks in advance...
    URL: http://www.littledreamswarehouse.com/shop
    Zen Version: 1.3.89h
    Zen Template: orange modified

  4. #24
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,831
    Plugin Contributions
    31

    Default not working in Firefox on local Xampp

    The wiki code works ok for me on a local server (Xampp 173, php5.3) with ie8 and chrome but not Firefox.
    No debug messages: it simply does not add the free product to the cart.
    It works (with Firefox) when uploaded to the my hosting.

    While evidently this is not a real problem, I would still like to know why,
    any ideas?

    thanks
    Steve

  5. #25
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,831
    Plugin Contributions
    31

    Default Re: Developers API Tutorial - A Real World Example

    now it is consistently not working in ie8 and Ffox locally, Chrome still works ok. I have not changed any code.

  6. #26
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,831
    Plugin Contributions
    31

    Default not working more than once

    ok, it seems that across all three browsers and local/remote, it works once.
    Then, when the product is removed from the cart (leaving it empty), subsequent additions do not trigger the free item addition again.
    Manually deleting the entry in the session table allows it to work again - once.

  7. #27
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,831
    Plugin Contributions
    31

    Default Re: Developers API Tutorial - A Real World Example

    Can someone confirm the fact that
    a) this works only once is wrong, and
    b) the code in the wiki should work repeatedly, and
    c) maybe how I would go about finding out the error?

    I would like to to auto-add a product conditional on other factors based on this method, so some help would be gratefully received,
    thanks
    Steve

  8. #28
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,831
    Plugin Contributions
    31

    Default Re: Developers API Tutorial - A Real World Example

    continuing my monologue..

    I can only get the example to work (ie add and remove the freeproduct every time the threshold is passed) if I change
    PHP Code:
      if ($_SESSION['cart']->show_total() < $this->freeAmount && $_SESSION['cart']->in_cart($this->freeProductID) ) 
      {
        
    $_SESSION['cart']->remove($this->freeProductID);
      } 
    to

    PHP Code:
      if ($_SESSION['cart']->show_total() < $this->freeAmount && $_SESSION['cart']->in_cart($this->freeProductID) )
      {
        
    $_SESSION['cart']->remove($this->freeProductID);
        
    $_SESSION['userRemovedFreeProduct'] = FALSE;
        
    $_SESSION['freeProductInCart'] = FALSE
      } 
    I'm not suggesting the example is missing something but can anyone comment on this who has used it successfully??

 

 
Page 3 of 3 FirstFirst 123

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