the current code limits the possible variations to each product to 5. (ie color, lenght, size, material and texture or cpu, display, keyboard, sound and motherboard). more than this it wont make the combinations,
the subproducts_permute function should be:
function subproducts_permute($array, $start = 0, $value = array(), $results = array()) {
$keys = array_keys($array) ;
$number = count($keys) -1;
foreach($array[$keys[$start]] as $value[$start] ) {
if ($start < $number) {
$results = subproducts_permute($array, $start+1, $value, $results);
}
else {
$values=array();
for($i = 0; $i <= $number ; $i++){
$values[$keys[$i]]= $value[$i] ;
}
$results[] = $values;
}
}
return $results;
}
its a recursive function and dont need any other modifications.
regards,
massa
Comments
Comment #1
nedjoThanks, the existing function, which I wrote, is indeed a hack, and this looks like what I wanted to do. Can you turn this into a patch? We'll need one for both 4.7 and CVS HEAD.
Comment #2
brmassa commentednedjo,
im working so heavily in this module that a cant diff/patch this code only.
i created some other issues to subproduct:
* "Subproduct: doesnt show the atribute AND surcharge correctly" in http://drupal.org/node/74441
* "Attributes stocks summed during permutations creation" (that i believe its an error) in http://drupal.org/node/75445
and im gonna publish in the next few days some new features that i did for my site:
* some variations that are checkboxes instead select (it changes a lot of code, due the combination/permutation processes)
* combine SKU codes also (it adds a new collumn into the table)
* a new function that recalculates all products' price once its attributes' prices chages.
ragards,
massa
Comment #3
darren ohNo patch is attached.
Comment #4
brmassa commenteddarren
instead marking as "active", why dont you try to build the patch yourself man? the code is there, all instructions are there...
drupal community will gain more if people add stuff instead make it deevolute. let the issue as patch (code needs review) you let people know the existing solution.
well, against my previous statement, here is the patch FILE. it gave me a lot of useless work.
regards,
massa
Comment #5
darren ohThank you. I marked this issue as active because I was going to use your instructions to create a patch (when I had the time) and needed to keep track of which issues need patches.
Comment #6
recidive commentedSomeone else besides the author needs to test the code before it can be commited.
The patch looks great, I'll test this when I get a chance.
Comment #7
waxman2 commentedOK, I edited my sub_products.module file with above code. Now what? Do I need to reload something to make it work?
Comment #8
waxman2 commentednever mind I spoke to soon. It works on new products just not current ones. Is there any one working on a item update button? That way customers can update price after choosing attributes before adding item to cart.
Comment #9
havoc commentedattached is a path for 4.7
I have tested it and it does work. it appears clean and clear.
Comment #10
havoc commentedAnother patch attempt.
Comment #11
nedjoThanks brmassa, and others for testing, applied to 4.7 and HEAD.
Comment #12
(not verified) commented