Add multiple products to the basket at a time

Support-billede
By Morten Vadskær
more than 2 weeks ago
Approx. 1-2 minutes

If you want the ability to add multiple products to the basket in one go, you can do so by adding an extra level to your regular form called add_to_basket, and let it be an array containing what you would normally POST for individual products.

You can use this very simple example from a landing page:

<form action="" method="post">
<{section name="i" loop=$products}>
<h3><{$products[i]->getName()|escape}><h3>

<{assign var="index" value=$smarty.section.i.index}>
<input type="hidden" name="add_to_basket[<{$index}>][product_id]" value="<{$products[i]->getProductId()}>"/>
<input type='hidden' name="add_to_basket[<{$index}>][amount]" value="1"/>
<{/section}>

<input type="submit" value="Add all to cart">
</form>

The important thing in the above is that add_to_basket[] has a unique id for each product. In the example, the index from the section that loops the products through is used.

This website uses cookies.

We use cookies to personalize content and ads, provide social media features, and analyze our web traffic.

Information about your use of our website is also shared with our partners within social media, advertising, and analysis, who may combine them with other data from your interactions with their services.

Read more about our cookies