2
votes

What's the easiest way to pre-fill a shopping cart in Magento?

There is the CartController on the Checkout route, which has an "add" method, allowing you to do stuff like:

http://<shopurl>/checkout/cart/add?product=1

But what to do when you need more items in the cart? There is an "addGroup" method, but that only takes into account previous order lines.

1
I was actually planning on answering this myself, but my reputation doesn't allow me yet :D If anyone answers with my own idea, I'll reward him/her ;)Grimace of Despair

1 Answers

2
votes

When digging into the Checkout/CartController/addAction, there appears to be an argument "related_product". It enables you to do this:

http://<shopurl>/checkout/cart/add?product=1&related_product=2,4

Downsides are you only get a message about the main product added, and for the related products you cannot specify quantities. Upside is, you can populate a cart like this with several items at once without even touching Magento code.

If you want to add more items of the same, just repeat the id in the array