Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Jun 2007
    Posts
    80
    Plugin Contributions
    0

    Default Determine if a certain product is in the cart

    I want to include a message flag when certain items are in the shopping cart on tpl_shopping_cart_default.php.

    The logic is basically, if the cart contains product id 142, then show some html code. I played with the Zen Cart functions, but I just couldn't figure out how to create this statement.

  2. #2
    Join Date
    Sep 2007
    Location
    Dublin, Ireland
    Posts
    1,288
    Plugin Contributions
    8

    Default Re: Determine if a certain product is in the cart

    Do you want to hardwire it or write it as an SQL query??? Where do you want the message to appear??? On the main page, underneath the shopping cart, in its own side box????
    Andrew

    Andrew Moore
    Omnicia Agile Development
    www.omnicia.com

  3. #3
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Determine if a certain product is in the cart

    The cart content is store in $_SESSION, you can retrieve it anywhere.
    Try print_r($_SESSION) to learn the structure of the data.
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Determine if a certain product is in the cart

    Just use the built-in function:
    Code:
    $_SESSION['cart']->in_cart($products_id)
    It returns true if the $products_id (an integer) is in the cart, and false if not.
    .

    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.

  5. #5
    Join Date
    Sep 2007
    Location
    Dublin, Ireland
    Posts
    1,288
    Plugin Contributions
    8

    Default Re: Determine if a certain product is in the cart

    Quote Originally Posted by DrByte View Post
    Just use the built-in function:
    Code:
    $_SESSION['cart']->in_cart($products_id)
    It returns true if the $products_id (an integer) is in the cart, and false if not.
    So you can just add:

    PHP Code:
      $alert_id=142;
      if(
    $_SESSION['cart']->in_cart($alert_id))
      {
        
    $content.="<strong>Insert your custom HTML here for display when products_id 142 is found in your shopping cart</strong>";
      } 
    to your tpl_shopping_cart.php, near the end of the file, right before $content .= '</div>'; (see attached).
    Last edited by hem; 5 May 2009 at 10:32 AM.
    Andrew

    Andrew Moore
    Omnicia Agile Development
    www.omnicia.com

  6. #6
    Join Date
    May 2007
    Location
    SW Florida
    Posts
    1,051
    Plugin Contributions
    2

    Default Re: Determine if a certain product is in the cart

    Why not use one of the "Cross Sell Mods" in the dl section? Then you can set up your products from the admin.

    ???
    JOhn ><>
    Newest Site: ChargerPros - Stuff4Toys

  7. #7
    Join Date
    Jun 2007
    Posts
    80
    Plugin Contributions
    0

    Default Re: Determine if a certain product is in the cart

    Sorry for the delay in responding... been having a terrible time getting it to work. It's not working with the particular product ID I'm looking for, and I'm wondering if it has anything to do with it having attributes. When I do a var_dump, I get the below.

    For some reason, the product_ID is being appended with what looks like a session token (186:da00eb308c52a23d5e6d9c1ce7270e44).

    object(shoppingCart)#4 (10) { ["contents"]=> array(1) { ["186:da00eb308c52a23d5e6d9c1ce7270e44"]=> array(2) { ["qty"]=> float(1) ["attributes"]=> array(2) { [18]=> string(2) "70" [2]=> string(2) "19" } } } ["total"]=> float(39.99) ["weight"]=> float(4) ["cartID"]=> string(5) "11075" ["content_type"]=> string(8) "physical" ["free_shipping_item"]=> int(0) ["free_shipping_weight"]=> int(0) ["free_shipping_price"]=> int(0) ["customers_group"]=> NULL ["observers"]=> array(0) { } }

    Thanks everyone for your help with this... you've been so kind!

  8. #8
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Determine if a certain product is in the cart

    Quote Originally Posted by MyGreyGoose View Post
    For some reason, the product_ID is being appended with what looks like a session token (186:da00eb308c52a23d5e6d9c1ce7270e44).
    That's not a session token. It's a unique identifier for that particular product in that particular cart with that particular combination of attributes assigned to it.

    To detect just the product, strip off the colon and the hash before passing it to the function.
    .

    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.

  9. #9
    Join Date
    Jun 2007
    Posts
    80
    Plugin Contributions
    0

    Default Re: Determine if a certain product is in the cart

    How do I strip off the colon and hash before passing it to the function? I've tried everything, but I don't understand how to truncate something from an array.

    This is the only code I'm using:


    PHP Code:
      $alert_id=180;
        
      if(
    $_SESSION['cart']->in_cart($alert_id))
      {
        
    $content .= "custom HTML here";
      } 

  10. #10
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Determine if a certain product is in the cart

    hmmm ... your case is backwards to how I had read it the first time round ... oops

    Try in_cart_mixed() instead of in_cart()
    .

    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. Determine if product is in a certain catagory
    By JoshS in forum General Questions
    Replies: 2
    Last Post: 15 Sep 2015, 05:38 PM
  2. v151 disallow certain product combinations (in cart)
    By lsb57 in forum Managing Customers and Orders
    Replies: 3
    Last Post: 24 Oct 2012, 05:43 AM
  3. Show comments field below shopping cart if cart contains certain product model
    By frank18 in forum Templates, Stylesheets, Page Layout
    Replies: 9
    Last Post: 9 Feb 2010, 11:37 AM
  4. Determine if someone Abdonded the Cart?
    By malice95 in forum Managing Customers and Orders
    Replies: 1
    Last Post: 22 Sep 2009, 11:12 AM
  5. Replies: 0
    Last Post: 16 Jan 2007, 09:32 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