diefenbach / django-lfs

An online-shop based on Django
http://www.getlfs.com
BSD 3-Clause "New" or "Revised" License
622 stars 222 forks source link

Product variants addition based on global properties is broken #148

Closed ghost closed 7 years ago

ghost commented 10 years ago

Hi,

It is not possible to add more but just one variant for a product using global properties instead of local ones. I added a product using the dashboard, changed its type to "product with variants" and tried to add the variants by pressing "add variant(s)", so that I could assign properties later on. It only works for the first time, when I tried to add the second variant the message "no variants have been added" appears.

diefenbach commented 10 years ago

Which version do you use? How does your global properties look like?

ghost commented 10 years ago

Hi Kai,

The code has just been cloned from lfs-buildout-devel repo this morning. I think I possibly found the cause - the code in add_variants() function @ /lfs/manage/product/variants.py mostly takes care of local properties and checks against duplicated entries in this context only. In particular:

    # Create a variant for every requested option combination
    for i, options in enumerate(manage_utils.cartesian_product(*properties)):
        if product.has_variant(options, only_active=False):
                continue

However, in case of global properties-based variants there are no options at all. So the first time has_variant returns False, the second time it returns True and the whole further code responsible for variant production is omitted. My quick hack to this is below:

    # Create a variant for every requested option combination
    for i, options in enumerate(manage_utils.cartesian_product(*properties)):
        if product.has_variant(options, only_active=False):
            if options: # MY HACK
                continue

The only problem is that variants' names displayed in the left part of the dashboard are all the same, taken from parent product name, but this most likely is another issue.

ghost commented 10 years ago

Hi, The problem with names mentioned at the end of previous comment is not a bug, I just had to activate names of the variants.

diefenbach commented 10 years ago

Hi,

I'm going to look at this as soon as I find some time. Thx for reporting this.

Kai

diefenbach commented 7 years ago

Can't reproduce.