Using Drupal 7 Ubercart 3 (7.x-3.6).
Synopsis: I have a product type (We'll call it 'Design') which has two other products attached to it ('text' and 'embellishment'). One 'design' can have multiple variations of 'text' or 'embellishment' associated with it, and they are grouped with a 'design id'.
Issue: When a customer updates the quantity of 'Design' in the cart form view, I want to update any associated 'text' or 'embellishment' quantity as well. I have utilized hook_uc_cart_item_update to accomplish this, and it actually works - but only the first time you change the quantity of 'design'. After the first update, any subsequent updates to the quantity of 'design' only updates the 'design' quantity. I ended up taking the matching products, sticking them in an array, removing them from the cart, then adding them back in with the quantity from the updated 'design' product.
function hook_uc_cart_item_update($entity) {
// The Design nid
if ($entity->nid == 512) {
$dcID = $entity->data['attributes'][22];
$itemQty = $entity->qty;
settype($itemQty, "integer");
$cartID = $entity->cart_id;
$items = uc_cart_get_contents();
$pArray = array();
foreach ($items as $n => $item) {
// The nids of text and embellishment
if ($item->nid == 35 || $item->nid == 3) {
// We have a matching design id
if ($item->data['attributes']['22'] == $dcID) {
$p = array('nid' => $item->nid, 'qty' => $itemQty, 'data' => array('attributes' => $item->data['attributes']));
array_push($pArray, $p);
uc_cart_remove_item($item->nid, $item->cart_id, $item->data);
}
}
}
foreach ($pArray as $n => $item) {
uc_cart_add_item($item['nid'], $item['qty'], $item['data'], $cartID, NULL, FALSE, FALSE);
}
}
}
I don't understand why the quantity value only works the first time. Devel shows the values being passed are correct. Also, if there is a simpler way to accomplish this, I'm open to suggestions.