Results 1 to 10 of 13

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    282
    Plugin Contributions
    0

    Default question about in_cart() function,

    I'm trying to trouble shoot some code in my new observer class. this is my first time out using the observer class and i've gone thru the 2 tuts in the wiki.

    i'm trying to check for the presence of certain products (hazmat) in the cart. and if there, create a
    PHP Code:
    $_SESSION['hazMatOneInCart'] = TRUE 
    var.

    orig i have a var based on a specific product id -
    var $hazMatProdOne = 115;

    and then ran like below -

    PHP Code:
    function update(&$class$eventID$paramsArray = array()) {
         if(
    $_SESSION['cart']->in_cart($this->hazMatProdOne)) {
            
    //echo 'has HazMat One';
            
    $_SESSION['hazMatOneInCart'] = TRUE;
        } 

    didn't seem to be working, and then, for testing purposes when i switched out the var $hazMatProdOne to an integer, 115 (a product id) and got an error -
    PHP Code:
    function update(&$class$eventID$paramsArray = array()) {
         if(
    $_SESSION['cart']->in_cart($this->115)) {
            
    $_SESSION['hazMatOneInCart'] = TRUE;
        } 
        


  2. #2
    Join Date
    Oct 2012
    Posts
    282
    Plugin Contributions
    0

    Default Re: question about in_cart() function,

    never mind, i see the problem
    PHP Code:
    $this->155 
    is wrong,
    instead,
    PHP Code:
    $this->shouldBeAVar 

  3. #3
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: question about in_cart() function,

    Or just 115 instead of $this->115
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  4. #4
    Join Date
    Oct 2012
    Posts
    282
    Plugin Contributions
    0

    Default Re: question about in_cart() function,

    hey Dr.Byte, yes i caught after i posted, thanks

    for some reason i cannot get this in_cart() function to return true even though i have product 115 in the cart. not sure what to do?

    function update(&$class, $eventID, $paramsArray = array()) {
    if($_SESSION['cart']->in_cart(115)) {
    $_SESSION['hazMatOneInCart'] = TRUE;
    //echo 'has HazMat One';
    }
    } //doesn't return true

    however, below does work. meaning the other parts of the code not listed here are working. how can i trouble shoot this?

    function update(&$class, $eventID, $paramsArray = array()) {
    if(true) {
    $_SESSION['hazMatOneInCart'] = TRUE;
    //echo 'has HazMat One';
    }
    }

  5. #5
    Join Date
    Oct 2012
    Posts
    282
    Plugin Contributions
    0

    Default Re: question about in_cart() function,

    getting discouraged here. not sure how to get that to test as true,
    i'll include more code here in case that helps to clarify. the autoloaders are working.

    PHP Code:
    function hazMatProduct() {
        
    $_SESSION['cart']->attach($this, array('NOTIFIER_CART_ADD_CART_END''NOTIFIER_CART_REMOVE_END'));
    }

    function 
    update(&$class$eventID$paramsArray = array()) {
    global 
    $cart;
    if(
    $_SESSION['cart']->in_cart(115)) {
    //if(TRUE) {   //this works
            
    $_SESSION['hazMatOneInCart'] = TRUE;
        }
    }

    are there any more tuts available on using the observer class? i've done the two in the Developers WIKI -
    the prod id 115 is just for testing, will be changed to a variable once i figure out problem here

  6. #6
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,872
    Plugin Contributions
    96

    Default Re: question about in_cart() function,

    Quote Originally Posted by tcarden View Post
    thanks, unfortunately it doesn't do anything.

    getting discouraged here. not sure how to get that to test as true,
    i'll include more code here in case that helps to clarify. the autoloaders are working.

    PHP Code:
    function hazMatProduct() {
        
    $_SESSION['cart']->attach($this, array('NOTIFIER_CART_ADD_CART_END''NOTIFIER_CART_REMOVE_END'));
    }

    function 
    update(&$class$eventID$paramsArray = array()) {
    global 
    $cart;
    if(
    $_SESSION['cart']->in_cart(115)) {
    //if(TRUE) {   //this works
            
    $_SESSION['hazMatOneInCart'] = TRUE;
        }
    }

    are there any more tuts available on using the observer class? i've done the two in the Developers WIKI -
    the prod id 115 is just for testing, will be changed to a variable once i figure out problem here
    How about this:
    Code:
    function hazMatProduct() {
      $this->attach($this, array('NOTIFIER_CART_ADD_CART_END', 'NOTIFIER_CART_REMOVE_END', 'NOTIFIER_CART_UPDATE_QUANTITY_END'));
    }
    
    function update(&$class, $eventID, $paramsArray = array()) {
      $_SESSION['hazMatOneInCart'] = ($class->in_cart(115)) ? true : false;
    }

 

 

Similar Threads

  1. about contact us function
    By win8win in forum General Questions
    Replies: 9
    Last Post: 28 Jul 2016, 02:22 AM
  2. Basic question about the ONS update function, testing it out
    By tcarden in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 8 Feb 2013, 05:15 AM
  3. Question about location of payment modules ... getting a function error
    By sjohnstone in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 27 Nov 2008, 10:20 AM
  4. Replies: 1
    Last Post: 7 Nov 2006, 11:18 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