timcross
(Tim Cross)
April 20, 2016, 7:52pm
#1
Hi Mark
Thanks for all your feedback so far.
I would like to know if it possible to add an additional product to the cart from the product details page?
So, for example, a product has accessories and you can chose to add one from a drop down menu, and then press the the main add to cart button. This would add both products to the cart.
Thanks
Tim
mhamstra
(Mark Hamstra)
April 21, 2016, 12:02pm
#2
Yeah, that is possible though there doesn’t seem to be specific docs for it yet, and you do need to make some changes to your templates.
Normally your add to cart form looks something like this:
<form action="[[~[[*id]]]]" method="post">
<div>
<input type="text" name="quantity" value="1" />
<input type="submit" name="addcart" value="Add to Cart" />
</div>
</form>
but to add multiple products in one go you’ll need something like this:
<form action="[[~[[*id]]]]" method="post">
<div>
<input type="hidden" name="products[0][productid]" value="[[*id]]" />
<input type="text" name="products[0][quantity]" value="1" />
<input type="hidden" name="products[1][productid]" value="other_resource_id" />
<input type="text" name="products[1][quantity]" value="1" />
<input type="submit" name="addcart" value="Add to Cart" />
</div>
</form>
timcross
(Tim Cross)
April 21, 2016, 2:19pm
#3
Ok, thats great, thanks Mark
How would I go about adding a product option in a select menu to this?
So, the extra product I want to add has colour options, and these need to be selected as well from a select menu?
Is that possible?
Thanks!
Tim
timcross
(Tim Cross)
April 21, 2016, 2:26pm
#4
actually, just worked that out.
I put :
products[1][simplecart_option_3]
as the name of the select menu and this worked!
Do you know if there is anyway to stop the product getting added to basket is nothing is selected? Or would this have to be done with javascript?
Thanks again
Tim
mhamstra
(Mark Hamstra)
April 25, 2016, 11:43am
#5
Yeah you’ll probably need to do something with dynamically generating those inputs.
Could also see if setting the quantity to 0 ignores it, I think it should.