Hello,
I am currently running drupal 4.7.0 w/out any CVS modules (need to get that out of the way). I am currently attempting to configure the e-commerce module and specifically the subproducts module so that it will not print all of the subproducts (variations of the product) within the category that the product resides.
What I really need to know is how can I set the "category" of these subproducts to be "none" as opposed to the "parent category" when they are created - so I dont have to do it by hand? I have attempted to set the $node->cid = 0 in the functions that it seemed necessary which I will include below. These functions come from the subproducts.inc file that lives quitely in the subproducts.module.
/**
* The third stage of the variation generation wizard.
*
* Having received user input on which attribute combinations
* to use for new subproducts, we generate the requested
* subproducts.
*
* @param $node
* A node object representing a parent product.
*/
function subproducts_generate_wizard3($node) {
$node->pparent = $node->nid;
// $node->status = 0;
$node->comment = 0;
$node->voting = 0;
$children = $node->children;
$title = $node->title;
// It's not clear where this array key comes from, but it generates errors and so needs to be unset.
unset($node->path);
$permutations = $_POST['edit']['permutations'];
foreach ($permutations as $key => $value) {
if ($value['use']) {
$title_bits = array();
$node->variations = array();
$pairs = explode('||', $key);
foreach ($pairs as $pair) {
$item = explode('|', $pair);
$node->variations[] = $item[1];
$attribute = subproducts_get_attribute($item[1]);
$title_bits[] = $attribute->name;
}
$node->title = $title . ' ' . implode(' ', $title_bits);
$node->price = $value['price'];
$node->stock = $value['stock'];
unset($node->nid);
unset($node->path);
$node->cid = 0; // <---- Here is what I added.
node_save($node);
}
}
drupal_goto('node/' . $node->pparent);
}
/**
* The third stage of the base selection wizard.
*
* Having received user input on which attribute combinations
* to use for the selected base products, we generate the requested
* subproducts.
*
* @param $node
* A node object representing a parent product.
*/
function subproducts_select_bases_wizard3($node) {
$status = subproducts_admin_sql();
// We copy the original node to retain its properties
// before selectively removing some, which we don't want
// in the subproducts.
$parent = $node;
$node->pparent = $parent->nid;
// $node->status = 0;
$node->comment = 0;
$node->voting = 0;
unset($node->price_type);
unset($node->path);
$bases = $_POST['edit']['bases'];
foreach ($bases as $nid => $variations) {
$options = array();
foreach ($variations as $vid => $attributes) {
$array[$vid] = array();
foreach ($attributes as $aid => $use) {
if ($use['use']) {
$options[$vid][] = $aid;
}
}
}
// Find all the permutations.
$permutations = subproducts_permute($options);
// For each permutation, test if there is a product that has the required attributes,
// and if so create a new child product with it as a base.
foreach ($permutations as $permutation) {
$joins = array();
$wheres = array();
foreach ($permutation as $index => $aid) {
$joins[] = 'INNER JOIN {ec_product_attribute} a'. $index .' ON p.nid = a'. $index .'.nid';
$wheres[] = 'a'. $index .'.aid = ' . $aid;
}
$result = db_query('SELECT DISTINCT(p.nid) FROM {ec_product} p INNER JOIN {node} n ON p.nid = n.nid ' . implode(' ', $joins) . ' WHERE ' . implode(' AND ', $wheres) . ' AND ' . $status . ' p.pparent = %d', $nid);
if (db_num_rows($result)) {
$match = db_fetch_object($result);
// If we already have a subproduct with this base product, skip.
if (count($node->children) && db_num_rows(db_query("SELECT * FROM {ec_product_base} WHERE product IN (%s) AND base = %d", implode(',', $node->children), $match->nid))) {
continue;
}
$node->base = $match->nid;
// Set values from the base product.
$base = node_load($node->base);
$node->title = $parent->title . ' ' . $base->title;
if (isset($parent->price_type)) {
$node->base_price = $base->price;
subproducts_reset_price_base($node, $parent);
}
else {
$node->price = $parent->price + $base->price;
}
$node->stock = $base->stock;
// It's not clear where this array key comes from, but it generates errors and so needs to be unset.
unset($node[0]);
unset($node->nid);
$node->cid = 0; // <---- here is the other modification
node_save($node);
}
}
}
// It's not clear where this array key comes from, but it generates errors and so needs to be unset.
unset($parent[0]);
// We resave the parent node to trigger any nodeapi hooks that might act on a product with subproducts.
node_save($parent);
// Display the parent page.
drupal_goto('node/' . $parent->nid);
}
So i hope that someone out there is able to help me find a way to keep the listings of subproducts out of the category of products. I dont even see why they are listed since the product has a handy way of selecting which type of subproduct is desired, it just clutters up the screen.
Perhaps I might be able to use the unset() function to clear out the category information to the product. At this point I am not sure. I cant really even say that I know what variable is used to store the category information of each product so I hope some Drupal Master (DM) can help.
Best Regards, Derek
Comments
Unset() did the trick!
So, in order to prohibit the automatic generation of subproducts in the pparent category we just added the following function calls to the subproducts.inc file:
unset($node->category);
unset($node->taxonomy);
here's the code:
and this supresses the inclusion of subproducts in the category of the parent. Hooray for us!
THANKS!!
Thanks for this post. I have been searching for this for 3 days. From the title I could not judge that this solution is in this post.
Thanks again
Best Regards
Rudy