Zen Cart Logo
Forums / General Questions / Add multiple products with attributes to cart with single click

Add multiple products with attributes to cart with single click

Views: 1,371

Results 1 to 2 of 2
14 May 2013, 2:08 AM
#1
mark777 avatar

mark777

New Zenner

Join Date:
May 2013
Location:
Toronto
Posts:
2
Plugin Contributions:
0

Add multiple products with attributes to cart with single click

Hi,

I've been searching for solutions to my problem but couldn't find a way to implement what I'm trying to do or any detailed documentation about the zen cart 'multiple_products_cart_quantity / multiple_products_add_product' functions.

Basically what I'm currently doing is having a single product order page built with Javascript (to live calculate totals, validation etc) with a bunch of products and a quantity field per product to quickly build an order and then with a single click the order gets added to the cart (modified the cart slightly so the cart gets cleared, then populated, then skipped to the shipping page).

This works great, however I now have a problem that I need to include products with a single attribute (size) and I can't figure out how to format my form to make this work.

The form basically works like this:

<form name="multiple_products_cart_quantity" action="index.php?main_page=index&cPath=65&sort=20a&action=multiple_products_add_product" method="post" enctype="multipart/form-data"> <input type="hidden" name="securityToken" value="<?php echo $_SESSION['securityToken']; ?>" />

Product 1
<INPUT TYPE="Text" NAME="products_id[101]" VALUE="0">

Product 2
<INPUT TYPE="Text" NAME="products_id[102]" VALUE="0">

Product 3 with attributes
<select name="id[2]" id="attrib-2">

<option value="68" selected="selected">1 lbs (~2 quarts)</option> <option value="69">5 lbs (~10 quarts) ( +$75.00 )</option> <option value="70">10 lbs (~20 quarts) ( +$154.00 )</option> <option value="71">30 lbs (~60 quarts) ( +$444.00 )</option> <option value="72">50 lbs (~100 quarts) ( +$604.00 )</option> </select> <INPUT TYPE="Text" NAME="products_id[103]" VALUE="0">

Product 4
<INPUT TYPE="Text" NAME="products_id[104]" VALUE="0">

<input type="Submit" value="Proceed to checkout"> </form> ---

I've tried doing things like naming id[203:2], product_id[203:22e62e63fb8f092da731e8f12ebd81a9] (the key assigned when I add the product with value 69 to the cart from the individual product page - not sure where this originates - I presume from the attributes assigned).

So far all I get is either product 3 doesn't show up at all or it shows up with the default attribute (not the one I chose).

Anybody have any idea how I can accomplish this? I'm basically wanting to be able to add a mix of regular products and products with attributes in one step to the cart.

Thank you!

16 May 2013, 7:33 AM
#2
mark777 avatar

mark777

New Zenner

Join Date:
May 2013
Location:
Toronto
Posts:
2
Plugin Contributions:
0

Re: Add multiple products with attributes to cart with single click

Ok I figured it out...

basically it involves editing the \includes\classes\shopping_cart.php file and changing the 'actionMultipleAddProduct' function slightly...

around line 1855 I changed:
$this->add_cart($prodId, $this->get_quantity($prodId)+($new_qty));

to:
$real_ids = isset($_POST['id' . $prodId]) ? $_POST['id' . $prodId] : "";
$this->add_cart($prodId, $this->get_quantity(zen_get_uprid($prodId, $real_ids))+($new_qty), $real_ids);

the front-end looks like this:
Product 1
<INPUT TYPE="Text" NAME="products_id[101]" VALUE="0">

Product 2
<INPUT TYPE="Text" NAME="products_id[102]" VALUE="0">

Product 3 with attributes
<select name="id103[2]">

<option value="68" selected="selected">1 lbs (~2 quarts)</option> <option value="69">5 lbs (~10 quarts) ( +$75.00 )</option> <option value="70">10 lbs (~20 quarts) ( +$154.00 )</option> <option value="71">30 lbs (~60 quarts) ( +$444.00 )</option> <option value="72">50 lbs (~100 quarts) ( +$604.00 )</option> </select> <INPUT TYPE="Text" NAME="products_id[103]" VALUE="0">

Product 4
<INPUT TYPE="Text" NAME="products_id[104]" VALUE="0">

<input type="Submit" value="Proceed to checkout">

This is a pretty rough solution but it works for me so hopefully it can help someone else too!!

now I have to figure out how to read the attributes back out of the cart to pre-fill the order form... ;)