Class ProductOption
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.EmbeddedContextStateAware,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:
-
ItemChoiceAttributeChoiceDefaultValidationTypeDefaultValidationStrategyDefaultProductOptionTypeOptionTemplate- Serialized Form
-
Field Summary
Fields inherited from interface com.broadleafcommerce.data.tracking.core.EmbeddedContextStateAware
DEFAULT_FIELD_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAdditionalAttribute(String name, Object value) Takes in any additional attributes passed in the request not matching any defined properties.protected booleanintbooleanReturn any additional attributes passed in the request not matching any defined properties.Map holding any additional attributes passed in the request not matching any defined properties.<T> TgetAttribute(String name) 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.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()voidsetAdditionalAttributes(Map<String, Object> additionalAttributes) Map holding any additional attributes passed in the request not matching any defined properties.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.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
-
addAdditionalAttribute
Takes in any additional attributes passed in the request not matching any defined properties.- Parameters:
name- Name of the additional attributevalue- Value of the additional attribute
-
getAdditionalAttribute
Return any additional attributes passed in the request not matching any defined properties.- Returns:
- any additional attributes passed in the request not matching any defined properties.
-
compareTo
- Specified by:
compareToin interfaceComparable<ProductOption>
-
getId
-
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
-
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
-
getAdditionalAttributes
Map holding any additional attributes passed in the request not matching any defined properties. -
setId
-
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
-
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
-
setAdditionalAttributes
Map holding any additional attributes passed in the request not matching any defined properties. -
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-