Adding additional products to cart at the same time

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

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>

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

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

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.