Class representing the complete variation information for a master product in
the system. An instance of this class provides methods to access the
following information:
This model only considers variants which are complete (i.e. the variant has a
value for each variation attribute), and currently online. Incomplete or
offline variants will not be returned by any method that returns Variants,
and their attribute values will not be considered in any method that returns
values.
In addition to providing access to this meta information,
ProductVariationModel maintains a collection of selected variation attribute
values, representing the selections that a customer makes in the storefront.
If this model was constructed for a master product, then none of the
attributes will have pre-selected values. If this model was constructed for a
variant product, then all the attribute values of that variant will be
pre-selected.
It is possible to query the current selections by calling
getSelectedValue(ProductVariationAttribute) or
isSelectedAttributeValue(ProductVariationAttribute, ProductVariationAttributeValue).
The method
setSelectedAttributeValue(String, String) can be used to modify
the selected values. Depending on the product type, it's possible to select or modify
variation attribute values:
- If this model was constructed for a master product, it's possible to select and modify all variation attributes.
- If this model was constructed for a variation group, it's possible to select and modify all variation attributes that are not defined by the variation group.
- If this model was constructed for a variation product, it's not possible to select or modify any of the variation attributes.
Furthermore, the model provides helper methods to generate URLs
for selecting and unselecting variation attribute values. See those methods
for details.
If this model was constructed for a product that is neither a
master nor a variant, then none of the methods will return useful values at
all.
The methods in this class which access the currently selected variation
attribute values can be used on product detail pages to render information
about which combinations are available or unavailable. The methods
getFilteredValues(ProductVariationAttribute) and
hasOrderableVariants(ProductVariationAttribute, ProductVariationAttributeValue)
can be used to determine this type of situation and render the appropriate
message in the storefront.
NOTE: Several methods in this class have a version taking a
ProductVariationAttribute parameter, and another
deprecated version accepting a
ObjectAttributeDefinition
parameter instead. The former should be strictly favored. The latter are
historical leftovers from when object attributes were used directly as the
basis for variation, and the value lists were stored directly on the
ObjectAttributeDefinition. Every ProductVariationAttribute corresponds with
exactly one ObjectAttributeDefinition, but values are now stored on the
ProductVariationAttribute and not the ObjectAttributeDefinition.