How to Add Multiple Products to Magento Cart from External Source

cartexternalmagento-1.7magento-1.8shopping-cart

I have to add multiple items into magento cart from out side of magento (external website), through /path/to/app/checkout/cart/add?product=[id]&qty=[qty] this method I can add one product to the cart.

Can anyone suggest how to do it?

Best Answer

There is a way, but you cannot add quantities to the rest of the products. They will be added in minimum qty. (most probably 1).

/checkout/cart/add/?product=[id]&qty=[qty]&related_product=[id2],[id3],...,[idN]

It works even if products with ids id2, .., idN are not actually related products to the main product.
Click this for demo:http://demo.magentocommerce.com/checkout/cart/add/?product=51&qty=2&related_product=17,18.

But be careful. In ce1.8 this doesn't work. Actually just adding a simple product to the cart doesn't work anymore (I mean this checkout/cart/add?product=[id]&qty=[qty]). Starting with this version the form_key is required when adding something to the cart.
Since this form_key depends on the session you may want to create your own controller and action that receives the products to be added to the cart and redirects to checkout/cart/add?product=[id]&qty=[qty]&form_key=FORM_KEY_HERE

Related Topic