Vars functionality for combinations of options (e.g. vars in table product_stock)

Verze:

07. 02. 2023

Zodpovědná osoba:

Dominik Šlechta

Vars are most often a label for a combination of options in a product (otherwise diluted as "combination"). In projects, this is most often used in 2 ways.

1. the product has checked options for different properties, from which combinations are then generated. The combinations then carry values such as the stock of this combination, EAN, etc. This is most often used for example in a clothing store or with items of different colours and sizes. For example: drevojas.cz or runsport.cz

2. the product has only combinations and the solution of options is secondary (product options are solved on the basis of combinations, which are then offered everywhere instead of a selection of options). It is most often used on e-shops, where it is not solved by selecting options, but mainly by selecting a given combination E.g. for screws it is solved mainly "by eye" rather than by whether it is brass or stainless. For example: briol.cz

Vars have their own structure.Options in vars are separated by '_' (underscore) and are sorted by property id from lowest to highest (ascending).
Options are unique across all properties, so it cannot happen that a vars contains the same option twice. Furthermore, vars cannot contain more than 1 option from 1 property i.e. from the size property, the XS size can only appear 1x in the vars. I have added an example below for better understanding:

Product 2 has:

// the associative field is formed as property_id => [...option_ids]
[
3 => [ 4, 5, 6],
5 => [ 1, 2, 3],
]

 

The product will have vars in the style 4_1 or 6_3 or 6_2 etc. But it can no longer take the state where the combination would be e.g. 4_5 or 1_3 or 3_5 etc.