menu

SiteGenesis / Server-side JS / Module: models/ProductModel

Model for product functionality.

Source:

module:models/ProductModel

The product class

Source:

Classes

ProductModel

Methods

(inner) isAttrSelectable(variationGroup, attr, value) → {Boolean}

Determines whether an attribute is selectable for a given Variation Group

Parameters:
Name Type Description
variationGroup dw.catalog.VariationGroup
attr dw.catalog.ProductVariationAttribute
value dw.catalog.ProductVariationAttributeValue
Source:
Returns:
Type
Boolean

(inner) ProductModel/get(parameter) → {module:models/ProductModel~ProductModel}

Gets a new instance of a given product or product ID.

Parameters:
Name Type Description
parameter dw.catalog.Product | String

The product object to enhance/wrap or the product ID of the product object.

Source:
Returns:
Type
module:models/ProductModel~ProductModel

(inner) ProductModel/getAvailability(quantity) → {Object}

Returns a JSON object holding availability information for the current product and the given quantity.

Parameters:
Name Type Description
quantity String

the quantity. Usually, this is the amount the customer has selected to purchase.

Source:
Returns:
Type
Object

(inner) ProductModel/getOnlineProductSetProducts() → {dw.util.Collection}

Returns a collection of all online products that are assigned to this product and that are also available through the current site. If this product does not represent a product set then an empty collection is returned.

Source:
Returns:

Collection of online products that are assigned to this product and that are also available through the current site.

Type
dw.util.Collection

(inner) ProductModel/isVisible() → {boolean}

Returns true if the product is visible in the storefront. The function checks the online flag of the product itself and if the product is a product set, checks the online flag of all products in the product set.

Source:
Returns:

true if the product is visible in the storefront, false otherwise

Type
boolean

(inner) ProductModel/updateOptionSelection(product, parameterMap, optionalCustomPrefix) → {dw.catalog.ProductOptionModel}

Processes option value selections and calculates and returns the ProductOptionModels for one or multiple products. Option value selections must be specified as HTTP parameters in the following form:

{prefix_}{pid}_optionID={optionValueID}

A custom prefix is set using the 'optionalCustomPrefix" parameter. Otherwise, the default prefix dwopt_ is used. {pid} is the product id.

Example:

dwopt_PN00049_memory=2GB

For each product specified as {pid}, a ProductOptionModel instance is created and returned as an element of the 'ProductOptionModels' HashMap output parameter. The function validates both option id and option value id and selects the option in the related ProductOptionModel instance.

If an option is not specified as an HTTP parameter, or the specified optionValueID is invalid, the default option value of this option is selected. Invalid optionIDs are silently ignored. The function returns a map of ProductOptionModels with the product instance as the key and the ProductOptionModel as the value. For compatibility reasons, the function does still accept an individual product instance as input parameter. If specified, the function returns the ProductOptionModel for this product as 'ProductOptionModel' and also as element of the 'ProductOptionModels' hashmap parameter.

Parameters:
Name Type Description
product dw.catalog.Product

An optional product instance for which the ProductOptionModel is updated.

parameterMap dw.web.HttpParameterMap

Product option selections as HTTP parameters.

optionalCustomPrefix String

Optional prefix for HTTP parameters. If nothing is passed, the default prefix "dwopt_" is assumed.

Source:
Returns:

The product option model.

Type
dw.catalog.ProductOptionModel

(inner) ProductModel/updateVariationSelection(parameterMap, optionalCustomPrefix) → {dw.catalog.ProductVariationModel}

Processes variation value selections and calculates and returns the ProductVariationModels for one or multiple products. The function uses the given HttpParameterMap, so the request parameters do not need to be passed in. Variation value selections must be specified as HTTP parameters in the following form:

{prefix_}{pid}_varAttrID={varAttrValueID}

A custom prefix can be set using the optionalCustomPrefix parameter. Otherwise, the default prefix dwvar_ is used. {pid}is the product id.

Example:

dwvar_PN00050_color=red

The function processes variation attributes in their defined order and ignores attributes or values not defined for a variation. The function returns a map of ProductVariationModels with the product instance as the key and the ProductVariationModel as the value. The product may either be a master or a variant.

Parameters:
Name Type Description
parameterMap dw.web.HttpParameterMap

Variation value selections as HTTP parameters.

optionalCustomPrefix String

Optional prefix for HTTP parameters. If nothing is passed, the default prefix "dwvar_" is assumed.

Source:
Returns:
Type
dw.catalog.ProductVariationModel