Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Dec 2006
    Posts
    3
    Plugin Contributions
    0

    Default PHP Code to Add a Product to the Shopping Cart

    Hello,

    I need to be able to add a product with three attributes to the shopping cart manually. My products are custom designed in a Flash application that is running inside of ZenCart and contains it's own "Add to Cart" button. All of these product attributes are already defined and working in ZenCart. When the "Flash Add to Cart" button is pressed I want to pass the product_id and all three of the attribute values to Zen shopping cart in PHP code. (Note: I DO NOT NEED any help with Flash.)

    Has anyone written a short PHP module that sets up all the proper variables and arrays then calls the proper function that performs the same function as the ZenCart Add to Cart button? I assume that if I set the product_id, and $attributes array then call the add_cart function thru a $Sessions call, that it should work. Any tips? Hints? Solutions???

    Thanks...

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

    Default Re: PHP Code to Add a Product to the Shopping Cart

    If you look at the raw HTML from View Source of the page that displays your products with attributes selected, you'll see all the input fields that are POST'd when you click the add-to-cart button.

    Using that information, simply have your flash app post those same fields when the user clicks the Add button.
    .

    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.

  3. #3
    Join Date
    Dec 2006
    Posts
    3
    Plugin Contributions
    0

    Default HELP! php code to add to cart

    I've written the code below to add a custom made product with three attributes to the shopping cart. (This code will be generated from my custom designer program.) It does add the item with the three attributes to the shopping cart correctly. HOWEVER, there are two problems:

    1. The qty will not update if I add the same item twice. That is, if there is ONE item in the shopping cart and I add the exact same item again, I do not get a qty of 2 in the cart; only 1. It will however, always replace the existing qty with any new qty that I request to add.

    2. The other problem is that when I add these items to the shopping cart without being logged in, they are lost when I do log in instead of being added to my customer id cart (as opposed to the session id cart).

    Does anyone know what I'm missing?


    PHP CODE to Add Qty: 1 of Product '180' to cart with three attributes:

    $products_id = '180';
    $add_qty = 1;
    $attributes = array(21=>70, 22=>72, txt_20=>"JAMES");
    $_SESSION['cart']->add_cart($products_id, $_SESSION['cart']->get_quantity($products_id)+ $add_qty, $attributes, false);

    THANKS!!!

  4. #4
    Join Date
    Jun 2003
    Posts
    33,720
    Plugin Contributions
    0

    Default Re: HELP! php code to add to cart

    *** Please keep the same topic in the same thread ***
    (merged your 2 threads into one.)
    Please do not PM for support issues: a private solution doesn't benefit the community.

    Be careful with unsolicited advice via email or PM - Make sure the person you are talking to is a reliable source.

 

 

Similar Threads

  1. want to add php code in define_main_page.php
    By parin123 in forum General Questions
    Replies: 1
    Last Post: 2 Jul 2009, 04:27 PM
  2. Help! Blank Page & PHP Errors when trying to Checkout or Add to Cart!
    By nsweet in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 2 Aug 2008, 06:26 PM
  3. please help me fix this code, adding quantity box and add to cart button to xsell
    By lankeeyankee in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 7 Nov 2007, 03:24 AM
  4. anyone know the php code for the 'add to cart' button
    By what44 in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 2 Nov 2007, 05:00 PM
  5. Where is PHP code for Add-to-cart?
    By artcoder in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 27 Jul 2007, 05:36 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