Jump to content

[SOLVED] Combinations generator flexibility


Guest

Recommended Posts

Hi,

I find the "Product combinations generator" a great tool but unfortunately it seems to be too much "static".

 

What I mean is that it only does a cartesian product of the selected attributes+value, but what if I want to "differentiate" those combinations?

 

An example is worth more than thousands words:

 

A sofa may have different cover types (leather, ecoleather, fabric, etc etc) and for each of those may have different colors.

 

The first thing I tried is to create different Attributes of type "Color", but unfortunately this way will be possible to chose more than one color at once, since there will be a selected color for any color picker (I hope that I was clear, if not please tell me).

 

Since this didn't work, I think that the better solution is to do something like this: http://www.idealetti...etto-young.html

(For non-Italian speakers, just select an option from *Tipo Rivestimento in the bottom of the page and see what happens).

 

I will have no problem to achieve something like that by editing the product.tpl (which I already became familiar with).

 

Before start coding I made some tests and I found out that I need to create combinations of a subset of colors only for each type of cover: let's say that I have 10 colors for leather and 10 colors for fabric, this is what the product combinations generator will create:

 

Cover type - leather, Leather color - leathercolor1
Cover type - leather, Fabric color - leathercolor1
Cover type - leather, Leather color - leathercolor2
Cover type - leather, Fabric color - leathercolor2
[...]etc etc
Cover type - fabric, Leather color - leathercolor1
Cover type - fabric, Fabric color - leathercolor1
[...]etc etc

 

Obviously I cannot allow some combinations (leather with non-leather colors etc), so I need a way to generate only specific combinations (e.g., pseudo-coding: IF cover type == leather THEN generate combinations with leather colors etc etc).

 

Is there a not-excessively-complicated way to achieve this?

 

It's impossible to deal with it manually, considering that there will be hundreds of models with 10+ colors for each kind of cover type (up to 100 colors for each model). With other attributes (e.g. size and/or number of seats) becomes a true hell.

 

 

EDIT: Please note that I'm open to any kind of solution, including those ones that request php knowledge. The main requirement is that it should be as little "time-consuming" as possible.

Edited by Guest (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

Unfortunately I didn't get any answer...

 

By the way, I achieved what I wanted by editing my product.tpl (in an overly specific way honestly, but I don't care much since things aren't likely to change) but still I don't like the fact that I'm creating hundreds/thousands of combinations when I know that I'm going to use 10% to 40% of those.

I am also worried about how this could 'scale' when I have lots of options (groups/attributes): I don't like to fill db with useless records and maybe even the execution time of the script could be an issue.

 

So I took a look at /controllers/admin/AdminAttributeGeneratorController.php and I found out how combinations are generated ( = the recursive function createCombinations); I think that if I succeed to perform some properly edits I can leave everything else untouched (since $values is created from $combinations and then both are passed as parameters for the function generateMultipleCombinations of the class Product). I do really hope I won't need to modify classes/Product.php (which as foretold I think I don't have to, but I'll investigate deeper).

 

My request now, if someone of the prestashop team guys (or good-willing devs in general) is reading, is to help me to understand or guide me somehow.

 

Thanks :)

Link to comment
Share on other sites

Solved. :)

 

In order not to edit the original function that generates combinations, I just added another function that filters the combinations generated by createCombinations.

 

Further details are not needed, since the filtering of combinations depends heavily on the application domain.

 

Btw for the purpose of efficiency in future I will write a new createCombinations so that un-needed combinations won't even be created (instead of creating all of the possible combinations and then filtering).

Link to comment
Share on other sites

The only advantage I can see in the way PS generates attribute combinations is that it provides an easy way to set a different add on pricing for products. For example I can charge one price for size XS to XL and charge $2.00 more for size 2XL. But I wish I could understand better why it is done the way it is. It can add THOUSANDS of lines to the product page.

Link to comment
Share on other sites

  • 1 year later...
×
×
  • Create New...