=== modified file 'uc_product_kit/uc_product_kit.module'
--- uc_product_kit/uc_product_kit.module	2009-09-23 15:38:25 +0000
+++ uc_product_kit/uc_product_kit.module	2009-09-28 20:47:08 +0000
@@ -98,6 +98,21 @@
   }
 }
 
+function uc_product_kit_form_alter(&$form, &$form_state, $form_id) {
+  if ($form_id == 'node_delete_confirm' && uc_product_is_product((integer)$form['nid']['#value'])) {
+    $kits = 0;
+    $result = db_query("SELECT k.nid FROM {node} AS n JOIN {uc_product_kits} AS k ON n.vid = k.vid WHERE k.vid IN (SELECT DISTINCT vid FROM {uc_product_kits} WHERE product_id = %d) GROUP BY k.nid HAVING COUNT(product_id) = 1", $form['nid']['#value']);
+    while ($k = db_fetch_object($result)) {
+      $kits++;
+    }
+
+    if ($kits) {
+      $description = $form['description']['#value'];
+      $form['description']['#value'] = format_plural($kits, 'There is 1 product kit that consists of only this product. It will be deleted as well.', 'There are @count product kits that consist of only this products. They will be deleted as well.') .' '. $description;
+    }
+  }
+}
+
 /**
  * Implementation of hook_uc_form_alter().
  *
@@ -402,6 +417,24 @@
         drupal_execute('product_kit_node_form', $form_state, $kit);
       }
     break;
+    case 'delete':
+      $result = db_query("SELECT DISTINCT nid FROM {uc_product_kits} WHERE product_id = %d", $node->nid);
+      while ($k = db_fetch_object($result)) {
+        $kit = node_load($k->nid, NULL, TRUE);
+        unset($kit->products[$node->nid]);
+
+        if (empty($kit->products)) {
+          node_delete($kit->nid);
+        }
+        else {
+          $form_state = array(
+            'values' => array('nid' => $kit->nid),
+            'submit_handlers' => array('node_form_submit'),
+          );
+          drupal_execute('product_kit_node_form', $form_state, $kit);
+        }
+      }
+    break;
   }
 }
 

