=== modified file 'uc_product/uc_product.module'
--- uc_product/uc_product.module	2008-06-04 20:23:34 +0000
+++ uc_product/uc_product.module	2008-06-16 20:53:20 +0000
@@ -236,6 +236,20 @@
  * Set up default imagefield and imagecache settings.
  */
 function uc_product_enable() {
+  $node_types = node_get_types('types');
+  $product_classes = array('product');
+  $result = db_query("SELECT pcid, name, description FROM {uc_product_classes}");
+  while ($product_class = db_fetch_object($result)) {
+    $product_classes[] = $product_class->pcid;
+  }
+  foreach ($node_types as $type => $info) {
+    if ($info->module == 'node' && in_array($type, $product_classes)) {
+      $info->module = 'uc_product';
+      $info->custom = 0;
+      node_type_save($info);
+    }
+  }
+
   if (module_exists('imagefield')) {
     $result = db_query("SELECT field_name FROM {node_field} WHERE field_name = 'field_image_cache' AND type = 'image'");
     if (!db_num_rows($result)) {
@@ -262,7 +276,7 @@
       ),
     );
     foreach (module_invoke_all('product_types') as $type) {
-      $result = db_query("SELECT * FROM {node_field_instance} WHERE field_name = 'field_imagecache' and type_name = '%s'", $type);
+      $result = db_query("SELECT * FROM {node_field_instance} WHERE field_name = 'field_image_cache' and type_name = '%s'", $type);
       if (!db_num_rows($result)) {
         db_query("INSERT INTO {node_field_instance} VALUES ('field_image_cache', '%s', -2, 'Image', 'image', '%s', '%s', '')", $type, serialize($widget_settings), serialize($display_settings));
       }
@@ -298,13 +312,8 @@
     content_clear_type_cache();
   }
   if (module_exists('imagecache')) {
-    $presets = array('product', 'product_list', 'uc_thumbnail');
-    $preset_keys = array();
-    foreach ($presets as $preset) {
-      $preset_keys[$preset] = 0;
-    }
-    $presets = $preset_keys;
-    $result = db_query("SELECT * FROM {imagecache_preset} WHERE presetname IN ('". implode("','", $presets) ."')");
+    $presets = array('product' => 0, 'product_list' => 0, 'uc_thumbnail' => 0);
+    $result = db_query("SELECT * FROM {imagecache_preset} WHERE presetname IN ('". implode("','", array_keys($presets)) ."')");
     while ($preset = db_fetch_array($result)) {
       $presets[$preset['presetname']] = $preset['presetid'];
     }
@@ -336,6 +345,20 @@
   }
 }
 
+function uc_product_disable() {
+  $product_types = node_get_types('types');
+  // node_type_rebuild() deletes disabled modules' node types. Give these
+  // node types to node.module to prevent this. Get them back during
+  // hook_enable().
+  foreach ($product_types as $type) {
+    if ($type->module == 'uc_product') {
+      $type->module = 'node';
+      $type->custom = 1;
+      node_type_save($type);
+    }
+  }
+}
+
 /**
  * Implementation of hook_node_info().
  *
@@ -1498,14 +1521,16 @@
   switch ($op) {
     case 'insert':
       db_query("UPDATE {node_type} SET module = 'uc_product', custom = 0 WHERE type = '%s'", $pcid);
-      $result = db_query("SELECT vid, nid FROM {node} WHERE type = '%s'", $pcid);
+      $result = db_query("SELECT n.vid, n.nid, p.unique_hash FROM {node} AS n LEFT JOIN {uc_products} AS p ON n.vid = p.vid WHERE n.type = '%s'", $pcid);
       while ($node = db_fetch_object($result)) {
-        $node->weight_units = variable_get('uc_weight_unit', 'lb');
-        $node->length_units = variable_get('uc_length_unit', 'in');
-        $node->pkg_qty = 1;
-        $node->default_qty = 1;
-        $node->shippable = 1;
-        uc_product_insert($node);
+        if (!$node->unique_hash) {
+          $node->weight_units = variable_get('uc_weight_unit', 'lb');
+          $node->length_units = variable_get('uc_length_unit', 'in');
+          $node->pkg_qty = 1;
+          $node->default_qty = 1;
+          $node->shippable = 1;
+          uc_product_insert($node);
+        }
       }
     break;
   }
@@ -2173,9 +2198,12 @@
   node_types_rebuild();
   menu_rebuild();
   if ($is_new && module_exists('imagefield')) {
-    $result = db_query("SELECT field_name FROM {node_field} WHERE field_name = 'field_image_cache' AND type = 'image'");
-    if (db_num_rows($result)) {
-      drupal_execute('_content_admin_field_add_existing', array('type_name' => $pcid, 'field_name' => 'field_image_cache'), $pcid);
+    $info = content_types($pcid);
+    if (!isset($info['fields']['field_image_cache'])) {
+      $result = db_query("SELECT field_name FROM {node_field} WHERE field_name = 'field_image_cache' AND type = 'image'");
+      if (db_num_rows($result)) {
+        drupal_execute('_content_admin_field_add_existing', array('type_name' => $pcid, 'field_name' => 'field_image_cache'), $pcid);
+      }
     }
   }
 
@@ -2192,8 +2220,8 @@
   $products = db_fetch_object($result);
   $form['pcid'] = array('#type' => 'value', '#value' => $class_id);
   $form['#redirect'] = 'admin/store/products/classes';
-  $output = confirm_form($form, t('Be very sure you want to delete the %type product class. ', array('%type' => $class_id)), 'admin/store/products/classes',
-    format_plural($products->number, 'There is @count node of this type. It will be converted to the Product node type. ', 'There are @count nodes of this type. They will be converted to the Product node type'),
+  $output = confirm_form($form, t('Be very sure you want to delete the %type product class. It will become a standard node type.', array('%type' => $class_id)), 'admin/store/products/classes',
+    format_plural($products->number, 'There is @count node of this type.', 'There are @count nodes of this type.'),
     t('Continue'), t('Cancel'));
 
   return $output;
@@ -2204,12 +2232,10 @@
  */
 function uc_product_class_delete_confirm_submit($form_id, $form_values) {
   if ($form_values['confirm']) {
-    db_query("UPDATE {node} SET type = 'product' WHERE type = '%s'", $form_values['pcid']);
-
-    node_type_delete($form_values['pcid']);
-    $t_args = array('%name' => $form_values['pcid']);
-    drupal_set_message(t('The content type %name has been deleted.', $t_args));
-    watchdog('menu', t('Deleted content type %name.', $t_args), WATCHDOG_NOTICE);
+    $type = node_get_types('type', $form_values['pcid']);
+    $type->module = 'node';
+    $type->custom = 1;
+    node_type_save($type);
 
     db_query("DELETE FROM {uc_product_classes} WHERE pcid = '%s'", $form_values['pcid']);
     module_invoke_all('product_class', $form_values['pcid'], 'delete');

=== modified file 'uc_product_kit/uc_product_kit.module'
--- uc_product_kit/uc_product_kit.module	2008-05-30 16:02:36 +0000
+++ uc_product_kit/uc_product_kit.module	2008-06-16 20:02:41 +0000
@@ -34,6 +34,22 @@
   }
 }
 
+function uc_product_kit_enable() {
+  $node_type = node_get_types('type', 'product_kit');
+  if ($node_type->module == 'node') {
+    $node_type->module = 'uc_product_kit';
+    $node_type->custom = 0;
+    node_type_save($node_type);
+  }
+}
+
+function uc_product_kit_disable() {
+  $node_type = node_get_types('type', 'product_kit');
+  $node_type->module = 'node';
+  $node_type->custom = 1;
+  node_type_save($node_type);
+}
+
 /**
  * Implementation of hook_node_info().
  *

