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

nedjo’s picture

Thanks, 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.

brmassa’s picture

nedjo,

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

darren oh’s picture

Status: Needs review » Active

No patch is attached.

brmassa’s picture

Title: Subproducts combinations (not permutations) » Subproducts: combinations (not permutations)
Status: Active » Reviewed & tested by the community
StatusFileSize
new2.65 KB

darren

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

darren oh’s picture

Thank 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.

recidive’s picture

Status: Reviewed & tested by the community » Needs review

Someone 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.

waxman2’s picture

OK, I edited my sub_products.module file with above code. Now what? Do I need to reload something to make it work?

waxman2’s picture

never 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.

havoc’s picture

Category: bug » task
StatusFileSize
new2.38 KB

attached is a path for 4.7

I have tested it and it does work. it appears clean and clear.

havoc’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new2.69 KB

Another patch attempt.

nedjo’s picture

Status: Reviewed & tested by the community » Fixed

Thanks brmassa, and others for testing, applied to 4.7 and HEAD.

Anonymous’s picture

Status: Fixed » Closed (fixed)