cancel
Showing results for 
Search instead for 
Did you mean: 

How to add multiple products to cart programmatically based on customer preference?

How to add multiple products to cart programmatically based on customer preference?

I'm in the process of trying to create a "Configure your own system" page where the customer chooses several items they want from different categories.

 

I've successfully built the page structure and loaded all of the options, but I need to find a way to add the customer's selection to the cart.

 

How can I add these multiple products to the cart all at once? I'm struggling with this since normally, Magento adds to cart via URL or via PHP, neither of which can do what I'm asking (as far as I know).

 

Does anyone have a suggestion on how I could achieve this goal? I've seen this type of thing implemented in other Magento stores, but I'm not sure how it was executed.

 

Any help would be appreciated. Thanks.

3 REPLIES 3

Re: How to add multiple products to cart programmatically based on customer preference?

I think that I'm going to need to set up an AJAX request to pass the desired product IDs to a PHP POST script.

 

I've successfully loaded all checked product IDs into a JS variable.

 

How do I set up a POST script to handle this information (it's an array of product IDs)?

Re: How to add multiple products to cart programmatically based on customer preference?

You need to create a separate controller to add multiple products via post or ajax.

Re: How to add multiple products to cart programmatically based on customer preference?

Travisw,

There are a couple of ways to do this..

 

Magento already has in-built functionality for this since you can add related products to the cart using the related_product hidden form parameter.

 

If you're after a code solution (if you want configurable support etc..) then another option would be to override the cart controller; more specifically the addAction and loop over your products in there..

 

e.g. very over-simplified code below...

foreach($items as $itemParams) {
    $cart->addProduct($product, $itemParams);
}
Problem solved? Click Accept as Solution!
Magento Certified Developer Plus | www.iwebsolutions.co.uk | Magento Small Business Partner