Zen Cart Logo
Forums / General Questions / HELP! php code to add to cart

HELP! php code to add to cart

Locked

Views: 5,960

Results 1 to 4 of 4
This thread is locked. New replies are disabled.
5 Dec 2006, 7:31 PM
#1
utah_aviator avatar

utah_aviator

New Zenner

Join Date:
Dec 2006
Posts:
3
Plugin Contributions:
0

HELP! php code to add to 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...

5 Dec 2006, 9:12 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: HELP! php code to add to 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.

6 Dec 2006, 11:14 PM
#3
utah_aviator avatar

utah_aviator

New Zenner

Join Date:
Dec 2006
Posts:
3
Plugin Contributions:
0

Re: 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!!!

6 Dec 2006, 11:33 PM
#4
Kim avatar

Kim

Obaa-san

Join Date:
Jun 2003
Location:
West Coast, North America
Posts:
26,611
Plugin Contributions:
0

Re: HELP! php code to add to cart

*** Please keep the same topic in the same thread ***
(merged your 2 threads into one.)