--- uc_restrict_qty.module.orig Fri Aug 13 23:38:05 2010 +++ uc_restrict_qty.module Thu Sep 16 19:10:38 2010 @@ -82,6 +82,12 @@ * Implementation of hook_add_to_cart(). */ function uc_restrict_qty_add_to_cart($nid, $qty, $data) { + + // add restrict_qty to a product kit's data because it doesn't get added in hook_add_to_cart_data + if ($data['products']) { + $data['restrict_qty'] = uc_restrict_qty_count($nid); + } + $limit = variable_get('uc_restrict_qty_global', 0); // If a global restriction on the number of items has been made. @@ -126,6 +132,32 @@ function uc_restrict_qty_form_alter(&$form, &$form_state, $form_id) { // Disable the appropriate Qty. fields on the cart view form. if ($form_id == 'uc_cart_view_form') { + if (!empty($form['items'])) { + // Iterate through all form items looking for product kits + while (list($key,$value) = each($form['items'])) { + if (is_array($value)) { + while (list($type,$val) = each($value)) { + if($type == 'data') { + // This will be the data of component products in a product kit + $data = unserialize($val['#value']); + if ($data) { + foreach($data as $item) { + // Look for product kit nid + if (isset($item->{'data'}['kit_id']) && isset($item->{'data'}['restrict_qty'])) { + // Check if component product or product kit has restricted quantity + if (($item->{'data'}['restrict_qty'] > 0) || uc_restrict_qty_count($item->{'data'}['kit_id'])) { + $form['items'][$key]['qty']['#type'] = 'value'; + $form['items'][$key]['qty']['#theme'] = 'restrict_qty_field'; + } + } + } + } + } + } + } + } + } + for ($i = 0, $j = count(uc_cart_get_contents()); $i < $j; $i++) { $data = unserialize($form['items'][$i]['data']['#value']);