Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2008
    Posts
    49
    Plugin Contributions
    0

    Default Whats wrong with my add_cart code?!

    Hi,

    I'm trying to write an observer, and it fails whenever I try to add an item to the cart. See below:

    PHP Code:
    <?php
    class platinum extends base 
    {
        var 
    $freeProductID 75837;

        function 
    platinum()
        {
            
    $_SESSION['cart']->attach($this,array('NOTIFIER_CART_ADD_CART_END'));
        }
        
        function 
    update(&$callingClass$notifier$paramsArray
        {
            global 
    $db;
            
    //die($_SESSION['customer_id']);
            
    $statement "SELECT `customers_group_pricing` FROM `ch_customers` WHERE `customers_id` = ".(int)$_SESSION['customer_id'];
            
    $check $db->Execute($statement);
            if(
    $check->RecordCount() == 1)
                if (
    $check->fields["customers_group_pricing"]==2)
                {
                    
    //$_SESSION['cart']->add_cart($this->freeProductID,1);
                    
    $_SESSION['cart']->add_cart("75837");            
                }
        }
    }
    ?>

  2. #2
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,896
    Blog Entries
    2
    Plugin Contributions
    2

    Default Re: Whats wrong with my add_cart code?!

    HI,

    did you create an autoload entry in includes/autoloaders
    and how did you define that.

    Also when testing this, are you testing as a logged in customer, One thing you should probably do is create another notify watcher for a person being logged in, as, based on your code, if a guest adds an item to their cart they will not get the free item, even when they do login.

  3. #3
    Join Date
    Jan 2008
    Posts
    49
    Plugin Contributions
    0

    Default Re: Whats wrong with my add_cart code?!

    Hi Wilt,

    Here is my include autoloader file named, config.platinum.php

    PHP Code:
    <?php
    $autoLoadConfig
    [90][] = array('autoType'=>'class',
                                  
    'loadFile'=>'observers/class.platinum.php');
    $autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
                                  
    'className'=>'platinum',
                                  
    'objectName'=>'platinum');

    ?>
    My code is attempting the following:

    If the person is in a certain group, whenever they add something to their cart, it checks to see if the cart contains a certain item. If not, add it. Then, whenever they try to remove something from their cart, it checks to see if they're removing the autmoatically loaded item. If they are, add it again.

    I don't want someone to be able to check out without buying item X. Item X is NOT free.

    Thanks for your help,

    Joshua

  4. #4
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,896
    Blog Entries
    2
    Plugin Contributions
    2

    Default Re: Whats wrong with my add_cart code?!

    k,

    Unforunately that is not what the code posted is doing.

    What your code is doing, is checking if the current customer is in a certain group, and if they have just added something to the cart then add the special cart item(75837) to the cart.

    Unfortunately this will not work for a couple of reasons.

    1) it only works once the customer is logged in (it will ignore anything the customer does before logging in. So if they add something as a guest, then login, and then checkout, they will not get the special item.

    2) it is not checking if the special item is already in the cart. so could add the special item multiple times.


    U would be better off choosing a different notifier, from the checkout stage.

    Its difficult to tell u which one to use, as this depends on how the special item would affect shipping costs. etc.

    For example u could use this modifier - NOTIFY_HEADER_START_CHECKOUT_SHIPPING

    U would then check the customers group status and if it matched what u want then check if the special item was in the cart
    using $_SESSION['cart']->in_cart(75837) and if it is not in the cart, add it to the cart.

    HTH

 

 

Similar Threads

  1. Whats wrong with the width of my website (internet explorer)?
    By Dramacydril in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 10 Apr 2012, 06:23 PM
  2. Guess whats wrong with this code.... (footer links)
    By customk1 in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 30 Mar 2009, 01:40 AM
  3. Whats wrong with my site?
    By buchanan in forum General Questions
    Replies: 3
    Last Post: 2 Apr 2007, 01:13 AM
  4. Whats wrong with this query? Fresh eyes needed ;)
    By Reesy in forum General Questions
    Replies: 9
    Last Post: 11 Sep 2006, 05:15 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