dw.catalog.ProductVariationModelIn 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:
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.
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.