Developer Forum »
Product variants, can not see properties
62 posts

Hi!

I have customized the Webnodes e-commerce shoe demo. It works fine so far :)

But I don't understand what happens with the variant product. When I am in a product-node and I create a new variant, it creates a new product, but only of type "Basic product". Then I am not able to set the color and size in the variant.

If I create the variant first (separat), and then add it to the main product, the template renders the color and size, but still I cannot see these properties in Webnodes when I edit the variant.

Could it be that I have overwritten some custom-files? I have ran several rebuilds since I downloaded the copy. 

181 posts

Hi!

When you click on the Add button on the variant relation on the main product, you should get a standard dialogue where you select which product type you want to create.  

Which properties are shown is controlled in a couple of methods on the content class that you can override. If you look at the custom partial class file for ShoeProduct, you will see the following code:

public override System.Collections.Generic.List<int> GetVariantProperties() {
        List<int> varProps = base.GetVariantProperties();
        varProps.Add(ShoeProduct.PropertyIdColor);
        varProps.Add(ShoeProduct.PropertyIdSize);
        return varProps;
    }

    public override List<int> GetPropertiesToExcludeInVariantAutoUpdate() {
        List<int> varProps = base.GetPropertiesToExcludeInVariantAutoUpdate();
        if(varProps.Contains(ShoeProduct.PropertyIdItemNumber)){
            varProps.Remove(ShoeProduct.PropertyIdItemNumber);
        }
        varProps.Add(ShoeProduct.PropertyIdAdditionalImages);
        varProps.Add(ShoeProduct.PropertyIdReviews);
        varProps.Add(ShoeProduct.PropertyIdMainProductImage);        
        return varProps;
    }

    public override List<int> GetPropertiesToRenderInSubVariant() {
        List<int> varProps = base.GetPropertiesToRenderInSubVariant();
        if (varProps.Contains(ShoeProduct.PropertyIdItemNumber)) {
            varProps.Remove(ShoeProduct.PropertyIdItemNumber);
        }
        varProps.Add(ShoeProduct.PropertyIdAdditionalImages);
        varProps.Add(ShoeProduct.PropertyIdMainProductImage);        
        return varProps;       
    }

The names of the properties should explain fairly well what each of them does, but to give you a bit more info:

GetVariantProperties() - this is where you tell the system what properties on the content class that are variant properties.

GetPropertiesToExcludeInVariantAutoUpdate - When you save a main variant, all the other variants get the same content in most properties. The variant properties is of course not the same on all variants, but in addition, there are often a few other properties that are unique to the variant. For example, often each variant has a unique item number/manufacturer id and often a different picture. All the properties specified here need to be manually edited (or kept up to date with an import workflow from an ERP system etc).

GetPropertiesToRenderInSubVariant - It does what it says basically. It returns the property ids of properties you want to be visible when you edit a variant.

 

You can also find more information on variants here: http://developer.webnodes.com/variants

62 posts

Nice.

I had accidently overwritten this custom class. Makes sense.

So now, when I have added some new custom fields to my product, for example properties related to delivery and weight, I then need to update this file, right?

By the way, these properties could have been included in the basic product class as well ;)

181 posts

You don't have to update this file if you add custom properties. You only need to do that if:

  • The properties are variant properties.
  • The properties are not variant properties, but should still be visible for all variants. Item number for example can is a property that is visible for sub variants, but it's not a variant property. Weight could be a variant property, but usually it's either the same for all variants, or it's just a property visible on subvariants.
  We could have added weight, delivery properties to the base product in Webnodes, but it was decided to not do that since delivery charge calculations vary a lot. Some use weight. Some use a combination of weight and volume. Some use the same shipping fee regardless of weight, number of items in order and volume. 
1