Hyper Open Edge Cloud

How To Use Product Variation

How To showing how to work with sizes, colors, shapes of a product.
  • Last Update:2016-02-09
  • Version:001
  • Language:en

Variations are actually one of the coolest features of ERP5: if you trade or produce a product which comes in various sizes, colours, shapes or any other properties, you can define only one product, assign "variation axes" to them and then be able to choose allowed - well, variations. Then, when you fill a price list or a sales order, you don't need to put separate line for each variation of a product, but just one line for a product and then you fill a matrix of prices or quantities.

Table of Contents

Setup

To be able to set variations on a Product, you first need to define what variation axes a product can have. For this, you have to write a simple script:

variations=['size','colour']
context.setVariationBaseCategoryList(variations)

Go to your product, and run your script in the context of the product. Now see the "Price" tab in your product - the "Price Variation Axes" is not empty anymore - it lets you choose one or more of the variation base categories you've set.

For chosen categories associate Product portal type with them in portal type tool. For above example choose colour and size in Base Categories.

Assigning possible choices to a product

Once you've defined price variation axes, you need a way to define what variation this product may have. For this, follow these steps (assuming you want to variate by size):

  • in portal_categories, create some subcategories for 'size' base category
  • make sure "size" is one of the base categories for the 'Product' portal_type
  • add a MultiListField control to the Resource_viewDefaultPurchaseSupplyLine and/or Resource_viewDefaultSaleSupplyLine forms, name it "my_size_list"
  • go to the TALES tab of your my_size_list control, and in the "items" box type
    here/portal_categories/size/getCategoryChildLogicalPathItemList
        
  • in the same tab, in the "Enabled" box, type:
    python:'size' in here.getVariationBaseCategoryList()
        

Now, play with your product, and see what happens. The nice thingy you'll eventually see at the bottom of the form is called a matrixbox.

You can assign multiple variation axes to the same product, but do not assign more then three, because this is the maximum a matrixbox can handle (until someone comes up with a three-dimensional computer screen).

Using variations

Now you can set default prices for all possible variations of a product. If you create a Sales Order, you'll be able to type in eventual prices and quantities for the order; and if you create a Sales Supply, you'll be able to set up even more sophisticated pricing schemes, all the time using variations.

Fetching variation representation

To fetch variations for variated object methods getVariationText and getVariationTitle might be used. First one is discouraged because of returning list of relative URLs. Sometimes second one returns too less information. In this case below code might be used:

display_id = 'translated_title' 
# display_id = 'title' # if there is no need for translation

print object.getVariationCategoryItemList(display_id=display_id)

Related Articles