- The variation attributes of the master product (e.g. size and color). Use getProductVariationAttributes().
- The variation attribute values (e.g. size=Small, Medium, Large and color=Red, Blue). Use getAllValues(ProductVariationAttribute).
- The variation groups which may represent a subset of variants by defining a subset of the variation attribute values (e.g. color=Red, size=empty). Use getVariationGroups().
- The variants themselves (e.g. the products representing Small Red, Large Red, Small Blue, Large Blue, etc). Use getVariants().
- The variation attribute values of those variants. Use getVariationValue(Product, ProductVariationAttribute).
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.
Returns an empty collection if the passed attribute is not even a variation attribute of the master product.
Returns an empty collection if the passed attribute is not even a variation attribute of the master product.
A value is only returned if it at least one variant has the value and also possesses the selected values for all previous attributes. It is important to know that the filter is applied in a certain order. The method looks at all ObjectAttributeDefinition instances that appear before the passed one in the sorted collection returned by getAttributeDefinitions(). If the passed attribute is the first in this collection, then this method simply returns all its values. If an earlier attribute does not have a selected value, this method returns an empty list. Otherwise, the filter looks at all variants matching the selected value for all previous attributes, and considers the range of values possessed by these variants for the passed attribute.
The idea behind this method is that customers in the storefront select variation attribute values one by one in the order the variation attributes are defined and displayed. After each selection, customer only wants to see values that he can possibly order for the remaining attributes.
Returns an empty collection if the passed attribute is not even a variation attribute of the master product.
A value is only returned if it at least one variant has the value and also possesses the selected values for all previous attributes. It is important to know that the filter is applied in a certain order. The method looks at all ProductVariationAttribute instances that appear before the passed one in the sorted collection returned by getProductVariationAttributes(). If the passed attribute is the first in this collection, then this method simply returns all its values. If an earlier attribute does not have a selected value, this method returns an empty list. Otherwise, the filter looks at all variants matching the selected value for all previous attributes, and considers the range of values possessed by these variants for the passed attribute.
The idea behind this method is that customers in the storefront select variation attribute values one by one in the order the variation attributes are defined and displayed. After each selection, customer only wants to see values that he can possibly order for the remaining attributes.
Returns an empty collection if the passed attribute is not even a variation attribute of the master product.
- If no variation value is currently selected, the method returns true if any variant with the specified value is available, else false.
- if one or more variation values are selected, the method returns true if any variant with a combination of the specified value and the selected value is available, else false.
- if all variation values are selected, the method returns true of the variant that is represented by the current selection is available, else false.
- A Variation Model created for Variation Group A can't be switched to Variation Group B.
- A Variation Model created for Variant A can't be switched to Variant B.
- The state of a Variation Model for a Variation Group that defines color = red can't be changed to color = black.
- The state of a Variation Model for a Variant that defines color = red / size = L can't be changed to color = black / size = S. However, the state of a Variation Model created for a Variation Group that defines color = red can be changed to a more specific state by adding another selected value, e.g. size = L.
null
, otherwise a exception is thrown
varAttrAndValues
argument can be empty, or can
contain one or more variation attribute / value pairs. This variable list
should be even in length, with attributes and values alternating.
Attributes can be specified as instances of ProductVariationAttribute, or
String variation attribute ID. (Note: ObjectAttributeDefinition IDs are
not supported.) Values can be specified as instances of
ProductVariationAttributeValue or String or Integer depending on the data
type of the variation attribute. If a parameter type is invalid, or does
not reference a valid ProductVariationAttribute or
ProductVariationAttributeValue, then the parameter pair is not included
in the generated URL. The returned URL will contain variation attributes
and values already selected in the product variation model, as well as
attributes and values specified as method parameters. Sample usage:
master.variationModel.url("Product-Show", "color", "red", "size", "XL");
master.variationModel.url("Product-Show", colorVarAttr, colorValue, sizeVarAttr, sizeValue);
// --> on/demandware.store/Sites-SiteGenesis-Site/default/Product-Show?pid=master_id&dwvar_color=red&dwvar_size=XL
The generated URL will be an absolute URL which uses the protocol of the current request.
UpdateProductVariationSelections
pipelet. That pipelet reads
the querystring parameters and returns an updated variation model with
the desired attribute value selected.
The generated URL will be an absolute URL which uses the protocol of the current request.
The generated URL will be an absolute URL which uses the protocol of the current request.
UpdateProductVariationSelections
pipelet.
That pipelet reads the querystring parameters and returns an updated
variation model with the desired attribute value unselected.
The generated URL will be an absolute URL which uses the protocol of the current request.