--- subproducts.inc	2007-11-29 13:26:02.672717000 -0800
+++ new.subproducts.inc	2007-11-29 13:25:15.430928000 -0800
@@ -191,9 +191,18 @@ function subproducts_generate_wizard2($f
     }
     $price = $node->price;
     $stock = 0;
+    if (variable_get('file_product_friendly', 0)) {
+      $file = $node->fpath;
+    }
     $fields = array();
     foreach ($permutation as $key => $value) {
-      $fields[] = $key . '|' . $value;
+      // '|' delimiter breakes autocomplete
+      if (variable_get('file_product_friendly', 0)) {
+        $fields[] = $key . '-' . $value;
+      }
+      else {
+        $fields[] = $key . '|' . $value;
+      }
     }
     $fields = implode('||', $fields);
     $form['permutations']['#tree'] = TRUE;
@@ -209,11 +218,30 @@ function subproducts_generate_wizard2($f
       $stock += $settings[$vid][$aid]['stock'];
     }
     // Set price and stock data.
-    $form['price'][$fields] = array('#type' => 'markup', '#value' => $price);
-    $form['permutations'][$fields]['price'] = array(
+    if (!variable_get('file_product_friendly', 0)) {
+      $form['price'][$fields] = array('#type' => 'markup', '#value' => $price);
+      $form['permutations'][$fields]['price'] = array(
       '#type' => 'hidden',
       '#value' => $price
-    );
+      );
+    }
+    else {
+      $form['permutations'][$fields]['price'] = array(
+        '#type' => 'textfield',
+        '#title' => '',
+        '#default_value' => $price,
+        '#size' => 10,
+        '#maxlength' => 10
+      );
+      $form['permutations'][$fields]['file'] = array(
+          '#type' => 'textfield',
+          '#default_value' => $file,
+          '#size' => 50,
+          '#maxlength' => 200,
+          '#autocomplete_path' => 'ec_file/autocomplete',
+          '#disabled' => FALSE,
+      );
+    }  
     $form['permutations'][$fields]['stock'] = array(
       '#type' => 'textfield',
       '#title' => '',
@@ -248,6 +276,9 @@ function theme_subproducts_generate_wiza
     $header[] = array('data' => drupal_render($form['header'][$key]));
   }
   $header[] = array('data' => t('Price'));
+  if (variable_get('file_product_friendly', 0)) {
+    $header[] = array('data' => t('File <a href="!file_quicklist" onclick="window.open(this.href, \'!file_quicklist\', \'width=480,height=480,scrollbars=yes,status=yes\'); return false">(list of files)</a>', array('!file_quicklist' => url('admin/store/products/files'), '!file_path' => ec_file_create_path())));
+  }
   $header[] = array('data' => t('Stock'));
   $rows = array();
   $i = 0;
@@ -261,7 +292,13 @@ function theme_subproducts_generate_wiza
         'align' => 'center'
       );
     }
-    $rows[$i][] = array('data' => drupal_render($form['price'][$key]));
+    if (!variable_get('file_product_friendly', 0)) {
+      $rows[$i][] = array('data' => drupal_render($form['price'][$key]));
+    }
+    else {
+      $rows[$i][] = array('data' => drupal_render($form['permutations'][$key]['price']));
+      $rows[$i][] = array('data' => drupal_render($form['permutations'][$key]['file']));
+    }
     $rows[$i][] = array('data' => drupal_render($form['permutations'][$key]['stock']));
     $i++;
   }
@@ -286,7 +323,9 @@ function subproducts_generate_wizard2_su
   $node = $form_values['node'];
 
   $node->pparent = $node->nid;
-//  $node->status = 0;
+  if (variable_get('invisible_subproducts', 0)) {
+    $node->status = 0;
+  }
   $node->comment = 0;
   $node->voting = 0;
   $children = $node->children;
@@ -300,7 +339,13 @@ function subproducts_generate_wizard2_su
       $node->variations = array();
       $pairs = explode('||', $key);
       foreach ($pairs as $pair) {
-        $item = explode('|', $pair);
+        // '|' delimiter breakes autocomplete
+        if (variable_get('file_product_friendly', 0)) {
+          $item = explode('-', $pair);
+        }
+        else {
+          $item = explode('|', $pair);
+        }
         $node->variations[] = $item[1];
         $attribute = subproducts_get_attribute($item[1]);
         $title_bits[] = $attribute->name;
@@ -308,6 +353,20 @@ function subproducts_generate_wizard2_su
       $node->title = $title . ' ' . implode(' ', $title_bits);
       $node->price = $value['price'];
       $node->stock = $value['stock'];
+      if (variable_get('file_product_friendly', 0)) {
+        $node->fpath = $value['file'];
+        if (empty($node->fpath)) {
+          form_set_error('fpath', t('Please enter the path to the file.'));
+	  return;
+        }
+        else {
+          $full_path = ec_file_create_path($node->fpath);
+          if (!file_exists($full_path)) {
+            form_set_error('fpath', t('The file doesn\'t exist.'));
+	    return;
+          }
+	}
+      }
       unset($node->nid);
       unset($node->path);
       node_save($node);
