I have been trying to do something related (I think) but slightly different. In the shop I'm working on, some of the products are associated, and need to be bought as a 'bundle'. I also need the products to be removed from the cart as a bundle, so that if the shopper removes any one item of a bundle, it removes all associated items of that bundle. I believe it has to be this way, since I wish to keep stock level of the components of each 'bundle'.
I aim to achieve this by adding a custom cart action bundles.php in /includes/extra_cart_actions/ with the following effects
1) When adding bundles to the cart, the extra cart actions will generate a unique bundleId and write this id into a text attribute (bundleId) for each product in the bundle, thereby making it possible to identify which products belong to which bundle.
2) When removing an item from the cart, the extra cart actions will search the attributes of each product in the cart, and remove those products which have the same bundleId.
3)When modifying the quantity of an item in the cart, the extra cart actions will search the attributes of each product in the cart, and make the same quantity modification for each item with a matching bundleId attribute.
Bundles are being added to the cart perfectly well, however I am having no luck at all trying to set and get attributes of the cart contents form within the extra_cart_actions/bundles.php. My plan hinges on this, and I'm totally stumped.
I've been trying all sorts of variations on :-
$_SESSION['cart']->contents['$productId']['attributes_values']['bundleId'] = 'someId';
None of which actually seem to affect the bundleId attribute value.
Pehaps I'm barking up the wrong tree
Any ideas would be much appreciated.
John