0

I have a simple product with an ID of 2 and a grouped product with an ID of 1. The simple product is associated to the grouped product.

I can add the simple product to the cart with this URL:

Mage::helper('checkout/cart')->getAddUrl($simpleProduct);

However, when I want to add the simple product to the cart as an associated product of the grouped product, so that it will be linked to the grouped product in the cart, I am coming up short.

Here is what I've tried:

Mage::helper('checkout/cart')->getAddUrl($groupedProduct, array('super_group[2]' => 99));

This returns a seemingly working URL, but accessing it does not add anything to the cart, with the error "Please select a quantity":

checkout/cart/add/uenc/aHR0cDovL211ZWhsZG9yZmVyLmxvY2FsL3Rvb2xzL3Rlc3QucGhw/form_key/eiCAR1v74QWXeU05/super_group[2]/99/

I have also tried manually adding a

"?qty=10"

parameter to this URL without any change.

This does not work either:

Mage::helper('checkout/cart')->getAddUrl($groupedProduct, array('super_group' => array(2 => 99)));

This seems to completely ignore the second parameter.

Any ideas how I can create an URL that adds the simple product to the cart with the association to the grouped product?

  • Did you solve this? What are the params to add a parent product with associated child? – snh_nl Nov 8 '18 at 14:05
1

I know it is months later but who knows?

Since I am still flopping around the same kind of thing, this is what I ended up having to do - I wrote a mini module to create my own set of "addurls" but hopefully what I learned about the data structure might work for you

$cart = Mage::getModel('checkout/cart'); //Get cart object      
$cart->init();
$cartresponse = $cart->addProduct($productid, $params);

where for a grouped product the $params array is built as:

$params['product']= $groupedproductid;
$params['qty'] = 1
$params['super_group'] = array( $simpleproductid => $qty );

so the main difference is that besides the supergroup, I have the other parameters named 'product'=> id and 'qty'=>1 (ignored but seemed necessary).

So maybe for your getAddUrl passing a slightly more complete array might work?

something along the lines of

Mage::helper('checkout/cart')->getAddUrl($groupedProduct, array('product'=>1, 'qty'=>1,'super_group' => array(2 => 99)));

Please be aware that alas once the order is placed, the grouped product connection seems to evaporate and only the sku of the simple product remains.

This is good for statistics (as this is the real product) but for me it leads to broken links in "myaccount recently bought" and review requests :( which is really crippling my site at the moment. Not sure whether it is partly module caused

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.