Class ProductOption
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.EmbeddedContextStateAware
,com.broadleafcommerce.translation.mapping.SubIdentifiable
,Serializable
,Comparable<ProductOption>
A "product option" encapsulates additional, variable information about a Product
explicitly designed for customer-facing input. This can be info necessary for distinguishing
particular variants
such as shirt size, color, or material, or it can be some
custom user-input such as a name to emboss on the back of a jersey. Finally, it can even drive
additional products that should be added to the cart along with the product that it is configured
for.
Product Option comes configured with out of the box types, documented below.
Item Choice
The customer is selecting from a group of products or variants that will be added to their cart along with the parent item. The choices that the customer can select from can come from a category or an explicitly-defined set of products or variants.
Variant Distinguishing
Since ProductOptions tend to be used in distinguishing variants, it is common to allow
automatic generation of variants based on the options added to a product. This means that there
should exist a unique variant for every combination of each option's
AttributeChoice#allowedValues(s)
. Therefore, if a there is a "shirt"
product that has "size" (Small, Medium, Large) and "color" (Black, White, Red) options and each
option is set to be used in variant distinguishing, then there should exist 9 variants:
- Small Black
- Small White
- Small Red
- Medium Black
- Medium White
- Medium Red
- Large Black
- Large White
- Large Red
While Variant/SKU generation is one use case of the variants, a user can also add a single
variant that maps to specific combinations. In the example above, a user might only care about a
'Small Black' and 'Medium Large' shirts. The customer-facing frontend should react to this and
only display the values for which there exist Variant.getOptionValues()
.
All of the variant distingushing attributes are similar to the
item attribute
type in that the values that
the customer fills out are eventually stored as attributes on the item in the cart.
Item Attribute
and
Order Attribute
Dictates where the customer input should be stored once received. Most commonly this can be used for dynamic customer input (like a gift card message or name on the back of a jersey) but picking from a set of pre-defined values is supported here as well.
Validation
If allowed values
or AttributeChoice.required
are
specified then the user input is validated against it when adding to the cart. If a
item attribute
or
order attribute
allows dynamic input, you can add
additional validation to it. For instance, when requesting text for embossing a name on a jersey
the length of the message and characters used need to be restricted. The support defining a
AttributeChoice.validationRule
, , and
AttributeChoice.errorMessage
. Normally, the validation rule will be a regular expression;
however, a field for AttributeChoice.validationType
is also supported to define some
other means of validation.
It may also be important to control when this extra validation occurs during the shopping
flow. Some values may need to be validated immediately when an item is added to cart while others
should be validated once the order is submitted. Thus, AttributeChoice.validationStrategy
has been provided. The default supported values are enumerated in
DefaultValidationStrategy
.
- Author:
- Phillip Verheyden (phillipuniverse)
- See Also:
-
Field Summary
Fields inherited from interface com.broadleafcommerce.data.tracking.core.EmbeddedContextStateAware
DEFAULT_FIELD_NAME
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
int
boolean
Configuration when thetype
of this option is one of:DefaultProductOptionType.VARIANT_DISTINGUISHING
- drives customer further specifying their choices into a specificVariant
that contains a unique SKU code, pricing concerns, etc.DefaultProductOptionType.CART_ITEM_ATTRIBUTE
- Customer input will flow directly in the item attributes within their cartDefaultProductOptionType.CART_ATTRIBUTE
.com.broadleafcommerce.data.tracking.core.EmbeddedContextState
A subset ofTracking
information to expose the context state for this object.The ordering of this option in relation to other options on the page.getId()
Configuration for theDefaultProductOptionType.ITEM_CHOICE
.getLabel()
The label shown to customers when displaying this option.If the product option is of typeDefaultProductOptionType.VARIANT_DISTINGUISHING
, this allows searching based on this product option.If this option came from anOptionTemplate
this allows data synchronization if the template is updated.getType()
Controls both how the customer should be inputting values to fill out this option as well as storage of where the value will go once added to the cart.int
hashCode()
void
setAttributeChoice
(AttributeChoice attributeChoice) Configuration when thetype
of this option is one of:DefaultProductOptionType.VARIANT_DISTINGUISHING
- drives customer further specifying their choices into a specificVariant
that contains a unique SKU code, pricing concerns, etc.DefaultProductOptionType.CART_ITEM_ATTRIBUTE
- Customer input will flow directly in the item attributes within their cartDefaultProductOptionType.CART_ATTRIBUTE
.void
setContextState
(com.broadleafcommerce.data.tracking.core.EmbeddedContextState contextState) A subset ofTracking
information to expose the context state for this object.void
setDisplayOrder
(Integer displayOrder) The ordering of this option in relation to other options on the page.void
void
setItemChoice
(ItemChoice itemChoice) Configuration for theDefaultProductOptionType.ITEM_CHOICE
.void
The label shown to customers when displaying this option.void
setSearchOnOption
(Boolean searchOnOption) If the product option is of typeDefaultProductOptionType.VARIANT_DISTINGUISHING
, this allows searching based on this product option.void
setTemplateContextId
(String templateContextId) If this option came from anOptionTemplate
this allows data synchronization if the template is updated.void
Controls both how the customer should be inputting values to fill out this option as well as storage of where the value will go once added to the cart.toString()
-
Constructor Details
-
ProductOption
public ProductOption()
-
-
Method Details
-
compareTo
- Specified by:
compareTo
in interfaceComparable<ProductOption>
-
getId
- Specified by:
getId
in interfacecom.broadleafcommerce.translation.mapping.SubIdentifiable
- See Also:
-
SubIdentifiable.getId()
-
getTemplateContextId
If this option came from anOptionTemplate
this allows data synchronization if the template is updated.- Returns:
- the id of the
OptionTemplate
that this option was created from or null if this was created in isolation
-
getLabel
The label shown to customers when displaying this option. This helps communicate to customers how they should fill out the input- Returns:
- the display shown to customer for this option
-
getType
Controls both how the customer should be inputting values to fill out this option as well as storage of where the value will go once added to the cart.- Returns:
- which type of input this option is configured for
- See Also:
-
getDisplayOrder
The ordering of this option in relation to other options on the page. Can be null which indicates ordered last.- Returns:
- how this option should display in relation to other options
- See Also:
-
getSearchOnOption
If the product option is of typeDefaultProductOptionType.VARIANT_DISTINGUISHING
, this allows searching based on this product option. For example, if the product were a T-Shirt with three colors, three documents for each color would be indexed. -
getItemChoice
Configuration for theDefaultProductOptionType.ITEM_CHOICE
. Drives customer selection of an additional item to add to their cart- Returns:
- configuration if the type of this option is an
DefaultProductOptionType.ITEM_CHOICE
, otherwise null
-
getAttributeChoice
Configuration when the
type
of this option is one of:DefaultProductOptionType.VARIANT_DISTINGUISHING
- drives customer further specifying their choices into a specificVariant
that contains a unique SKU code, pricing concerns, etc.DefaultProductOptionType.CART_ITEM_ATTRIBUTE
- Customer input will flow directly in the item attributes within their cartDefaultProductOptionType.CART_ATTRIBUTE
. Customer input will flow directly in the global cart attribute. Any previously-set attribute should be replaced with new values.
- Returns:
- attributeChoice if the type of this option is an
DefaultProductOptionType.VARIANT_DISTINGUISHING
,DefaultProductOptionType.CART_ITEM_ATTRIBUTE
orDefaultProductOptionType.CART_ATTRIBUTE
, otherwise null
-
getContextState
public com.broadleafcommerce.data.tracking.core.EmbeddedContextState getContextState()A subset ofTracking
information to expose the context state for this object.- Specified by:
getContextState
in interfacecom.broadleafcommerce.data.tracking.core.EmbeddedContextStateAware
- Returns:
- a subset of
Tracking
information to expose the context state for this object
-
setId
- Specified by:
setId
in interfacecom.broadleafcommerce.translation.mapping.SubIdentifiable
- See Also:
-
SubIdentifiable.getId()
-
setTemplateContextId
If this option came from anOptionTemplate
this allows data synchronization if the template is updated.- Parameters:
templateContextId
- theOptionTemplate
this option was created from
-
setLabel
The label shown to customers when displaying this option. This helps communicate to customers how they should fill out the input- Parameters:
label
- the display shown to customers for this option
-
setType
Controls both how the customer should be inputting values to fill out this option as well as storage of where the value will go once added to the cart.- Parameters:
type
- the type of input that the drives customer selection, defaults fromDefaultProductOptionType
- See Also:
-
setDisplayOrder
The ordering of this option in relation to other options on the page. Can be null which indicates ordered last.- Parameters:
displayOrder
- how this option should display in relation to other options- See Also:
-
setSearchOnOption
If the product option is of typeDefaultProductOptionType.VARIANT_DISTINGUISHING
, this allows searching based on this product option. For example, if the product were a T-Shirt with three colors, three documents for each color would be indexed. -
setItemChoice
Configuration for theDefaultProductOptionType.ITEM_CHOICE
. Drives customer selection of an additional item to add to their cart- Parameters:
itemChoice
- configuration only whentype
isDefaultProductOptionType.ITEM_CHOICE
-
setAttributeChoice
Configuration when the
type
of this option is one of:DefaultProductOptionType.VARIANT_DISTINGUISHING
- drives customer further specifying their choices into a specificVariant
that contains a unique SKU code, pricing concerns, etc.DefaultProductOptionType.CART_ITEM_ATTRIBUTE
- Customer input will flow directly in the item attributes within their cartDefaultProductOptionType.CART_ATTRIBUTE
. Customer input will flow directly in the global cart attribute. Any previously-set attribute should be replaced with new values.
- Parameters:
attributeChoice
- configuration for customer-driven values that flow into an attribute
-
setContextState
public void setContextState(com.broadleafcommerce.data.tracking.core.EmbeddedContextState contextState) A subset ofTracking
information to expose the context state for this object.- Specified by:
setContextState
in interfacecom.broadleafcommerce.data.tracking.core.EmbeddedContextStateAware
- Parameters:
contextState
- a subset ofTracking
information to expose the context state for this object
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-