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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanintboolean<T> TgetAttribute(String name) Configuration when thetypeof this option is one of:DefaultProductOptionType.VARIANT_DISTINGUISHING- drives customer further specifying their choices into a specificVariantthat 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.Miscellaneous attributes for this tag.com.broadleafcommerce.data.tracking.core.EmbeddedContextStateA subset ofTrackinginformation 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 anOptionTemplatethis 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.inthashCode()booleanDenotes whether this option was added from anOptionTemplateby reference rather than being embedded on theProduct.voidsetAddedByReference(boolean addedByReference) Denotes whether this option was added from anOptionTemplateby reference rather than being embedded on theProduct.voidsetAttributeChoice(AttributeChoice attributeChoice) Configuration when thetypeof this option is one of:DefaultProductOptionType.VARIANT_DISTINGUISHING- drives customer further specifying their choices into a specificVariantthat 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.voidsetAttributes(Map<String, Object> attributes) Miscellaneous attributes for this tag.voidsetContextState(com.broadleafcommerce.data.tracking.core.EmbeddedContextState contextState) A subset ofTrackinginformation to expose the context state for this object.voidsetDisplayOrder(Integer displayOrder) The ordering of this option in relation to other options on the page.voidvoidsetItemChoice(ItemChoice itemChoice) Configuration for theDefaultProductOptionType.ITEM_CHOICE.voidThe label shown to customers when displaying this option.voidsetSearchOnOption(Boolean searchOnOption) If the product option is of typeDefaultProductOptionType.VARIANT_DISTINGUISHING, this allows searching based on this product option.voidsetTemplateContextId(String templateContextId) If this option came from anOptionTemplatethis allows data synchronization if the template is updated.voidControls 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
-
getAttribute
-
compareTo
- Specified by:
compareToin interfaceComparable<ProductOption>
-
getId
- Specified by:
getIdin interfacecom.broadleafcommerce.translation.mapping.SubIdentifiable- See Also:
-
SubIdentifiable.getId()
-
getTemplateContextId
If this option came from anOptionTemplatethis allows data synchronization if the template is updated.- Returns:
- the id of the
OptionTemplatethat this option was created from or null if this was created in isolation
-
isAddedByReference
public boolean isAddedByReference()Denotes whether this option was added from anOptionTemplateby reference rather than being embedded on theProduct. If true, then this Option needs to be hydrated from theOptionTemplatereferenced bytemplateContextIdbefore responding to client requests, e.g., before Product Details, Admin, or Indexer requests, to read the Product that owns this option.- Returns:
- whether this option was added from an
OptionTemplateby reference rather than being embedded on theProduct
-
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
typeof this option is one of:DefaultProductOptionType.VARIANT_DISTINGUISHING- drives customer further specifying their choices into a specificVariantthat 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_ATTRIBUTEorDefaultProductOptionType.CART_ATTRIBUTE, otherwise null
-
getAttributes
Miscellaneous attributes for this tag.- Returns:
- Miscellaneous attributes for this tag.
-
getContextState
public com.broadleafcommerce.data.tracking.core.EmbeddedContextState getContextState()A subset ofTrackinginformation to expose the context state for this object.- Specified by:
getContextStatein interfacecom.broadleafcommerce.data.tracking.core.EmbeddedContextStateAware- Returns:
- a subset of
Trackinginformation to expose the context state for this object
-
setId
- Specified by:
setIdin interfacecom.broadleafcommerce.translation.mapping.SubIdentifiable- See Also:
-
SubIdentifiable.getId()
-
setTemplateContextId
If this option came from anOptionTemplatethis allows data synchronization if the template is updated.- Parameters:
templateContextId- theOptionTemplatethis option was created from
-
setAddedByReference
public void setAddedByReference(boolean addedByReference) Denotes whether this option was added from anOptionTemplateby reference rather than being embedded on theProduct. If true, then this Option needs to be hydrated from theOptionTemplatereferenced bytemplateContextIdbefore responding to client requests, e.g., before Product Details, Admin, or Indexer requests, to read the Product that owns this option.- Parameters:
addedByReference- whether this option was added from anOptionTemplateby reference rather than being embedded on theProduct
-
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 whentypeisDefaultProductOptionType.ITEM_CHOICE
-
setAttributeChoice
Configuration when the
typeof this option is one of:DefaultProductOptionType.VARIANT_DISTINGUISHING- drives customer further specifying their choices into a specificVariantthat 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
-
setAttributes
Miscellaneous attributes for this tag.- Parameters:
attributes- Miscellaneous attributes for this tag.
-
setContextState
public void setContextState(com.broadleafcommerce.data.tracking.core.EmbeddedContextState contextState) A subset ofTrackinginformation to expose the context state for this object.- Specified by:
setContextStatein interfacecom.broadleafcommerce.data.tracking.core.EmbeddedContextStateAware- Parameters:
contextState- a subset ofTrackinginformation to expose the context state for this object
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-