Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  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,870
    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;
    }

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

    Default Re: question about in_cart() function,

    in_cart() works on the complete product-id value. And if you've got attributes on the product, the hash code after the main product number is also part of the in_cart() search.

    So, if the product-id assigned by the cart after selecting attribute combinations is 115:58203828a348f838e8f8d8c then testing in_cart(115) will fail.

    Instead, you'll need to get $_SESSION['cart']->get_products() into a variable, and then loop through the array of products dumped into that variable, and find a match on the number you're looking for, perhaps using (int) to force the removal of the hash when doing your comparison. (Can't use (int) on the parameters to in_cart() calls because that's going the opposite direction to what you're seeking.)
    .

    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.

  8. #8
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: question about in_cart() function,

    You could also try:
    Code:
    $_SESSION['cart']->in_cart_check('products_id','115')
    which will do all the extra code of looping through the results of the $_SESSION['cart']->get_products() without the check of attributes ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

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

    Default Re: question about in_cart() function,

    excellent, thanks!,
    extremely helpful..

    just call me Mr. HazMat

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

    Default Re: question about in_cart() function,

    Quote Originally Posted by Ajeh View Post
    You could also try:
    Code:
    $_SESSION['cart']->in_cart_check('products_id','115')
    which will do all the extra code of looping through the results of the $_SESSION['cart']->get_products() without the check of attributes ...
    Yup, that'll work too.
    .

    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.

 

 
Page 1 of 2 12 LastLast

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