SKU properties, both custom and out-of-the-box, are returned as part of the ProductViewModel
. Any widget that has access to the ProductViewModel
can access SKU properties from it. Widgets that do not have access to the ProductViewModel
can access SKU properties via the viewModels/SkuPropertiesHandler
module.
A call to either of these APIs returns an array of SKU properties. Each item in the array consists of a property definition for a SKU property, including ID, label, type, and so on. Note that the values for the properties are returned as part of the child SKU objects, so you must make a call to one of the APIs to determine what SKU properties exist and then call the SKU objects themselves to get the values for those properties. For example, if a custom SKU property called upcCode
exists, your widget can retrieve the value for the property for each child SKU object from the ProductViewModel
as shown in the example below (assuming your widget has access to the ProductViewModel
):
<div><span data-bind="text: product().childSKUs()[0].upcCode"></span></div>
As with other product properties, SKU properties can be any of five types:
Short text
Rich text
Number
Date
Checkbox
To correctly display a SKU property’s value, you must take into account the type of property being handled.