Class AttributeChoice
java.lang.Object
com.broadleafcommerce.cartoperation.domain.AttributeChoice
- All Implemented Interfaces:
Serializable
Customer-facing input to take in additional information about the product that they are
purchasing. Generic choices can be required or not, have validation, provide structured input, or
can be used to differentiate between
Variants
.- Author:
- Chad Harchar (charchar)
- See Also:
-
allowedValues
- Serialized Form
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttribute
(String name, Object value) Takes in any additional attributes passed in the request not matching any defined properties.protected boolean
boolean
Gives the customer more structured input to fill out their option, which can drive a select field or a color picker with particular colors.Return any additional attributes passed in the request not matching any defined properties.The order or item attribute that this choice is stored in when the user adds to their cartMap holding any additional attributes passed in the request not matching any defined properties.In case of a validation failure in conjunction with agetValidationStrategy()
this is the error code that should be shown to customers.In case of a validation failure in conjunction with agetValidationStrategy()
this is the message that should be shown to customers.IfvalidationType
isregex
, this is the expression that should execute against the user's value.The strategy used to determine when this product option is validated.How the validation fromgetValidationStrategy()
should be performed.int
hashCode()
boolean
Whether or not the user is required to fill out this option in order to add the product to their cart.void
setAllowedValues
(List<AttributeChoiceValue> allowedValues) Gives the customer more structured input to fill out their option, which can drive a select field or a color picker with particular colors.void
setAttributeName
(String attributeName) The order or item attribute that this choice is stored in when the user adds to their cartvoid
setAttributes
(Map<String, Object> attributes) Map holding any additional attributes passed in the request not matching any defined properties.void
setErrorCode
(String errorCode) In case of a validation failure in conjunction with agetValidationStrategy()
this is the error code that should be shown to customers.void
setErrorMessage
(String errorMessage) In case of a validation failure in conjunction with agetValidationStrategy()
this is the message that should be shown to customers.void
setRequired
(boolean required) Whether or not the user is required to fill out this option in order to add the product to their cart.void
setValidationRule
(String validationRule) IfvalidationType
isregex
, this is the expression that should execute against the user's value.void
setValidationStrategy
(String validationStrategy) The strategy used to determine when this product option is validated.void
setValidationType
(String validationType) How the validation fromgetValidationStrategy()
should be performed.toString()
-
Constructor Details
-
AttributeChoice
public AttributeChoice()
-
-
Method Details
-
addAttribute
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
-
getAttribute
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.
-
getAttributeName
The order or item attribute that this choice is stored in when the user adds to their cartWhen used to distinguish variants, this field corresponds to a key in
Variant.getOptionValues()
.- Returns:
- the the attribute of where this should be stored
-
isRequired
public boolean isRequired()Whether or not the user is required to fill out this option in order to add the product to their cart. This is always validated on cart add.- Returns:
- whether selecting a value from this option is required before adding this product to the cart
-
getValidationStrategy
The strategy used to determine when this product option is validated. For example, validation can be done when a product is added to a cart, when an order is submitted, or never (null). Regardless of this strategy,required
andallowedValues
are always validated.- Returns:
- the strategy when this choice should be validated or null if no extra validation should be performed
-
getValidationType
How the validation fromgetValidationStrategy()
should be performed. Only relevant ifgetValidationStrategy()
is non-null- Returns:
- how validation should be performed or null if there is no validation
- See Also:
-
getValidationRule
IfvalidationType
isregex
, this is the expression that should execute against the user's value.- Returns:
- the rule the validate the user input or null if there is no
getValidationStrategy()
-
getErrorMessage
In case of a validation failure in conjunction with agetValidationStrategy()
this is the message that should be shown to customers. Intended to be displayed directly on the page when thegetValidationStrategy()
fails validation.- Returns:
- the message that should be displayed to customers or null if there is no
getValidationStrategy()
-
getErrorCode
In case of a validation failure in conjunction with agetValidationStrategy()
this is the error code that should be shown to customers. This could map into a special message key on the frontend or provide additional information to the user in addition togetErrorMessage()
.- Returns:
- the error code that should be displayed to customers or null if there is
no
getValidationStrategy()
- See Also:
-
getAllowedValues
Gives the customer more structured input to fill out their option, which can drive a select field or a color picker with particular colors. This restricts the available values that the user can use to complete this option.When used to distinguish variants, a value in this list should correspond to the value in a variant's
Variant.getOptionValues()
map for theattributeName
key.- Returns:
- the hardcoded values that the customer can input
-
getAttributes
Map holding any additional attributes passed in the request not matching any defined properties. -
setAttributeName
The order or item attribute that this choice is stored in when the user adds to their cartWhen used to distinguish variants, this field corresponds to a key in
Variant.getOptionValues()
.- Parameters:
name
- attribute that this choice is stored into, either on the order item or order
-
setRequired
public void setRequired(boolean required) Whether or not the user is required to fill out this option in order to add the product to their cart. This is always validated on cart add.- Parameters:
required
- whether selecting a value from this option is required before adding this product to the cart
-
setValidationStrategy
The strategy used to determine when this product option is validated. For example, validation can be done when a product is added to a cart, when an order is submitted, or never (null). Regardless of this strategy,required
andallowedValues
are always validated.- Parameters:
validationStrategy
- when this choice should be validated
-
setValidationType
How the validation fromgetValidationStrategy()
should be performed. Only relevant ifgetValidationStrategy()
is non-null- Parameters:
validationType
- how validation should be performed- See Also:
-
setValidationRule
IfvalidationType
isregex
, this is the expression that should execute against the user's value.- Parameters:
validationRule
- the rule used to validate the user input
-
setErrorMessage
In case of a validation failure in conjunction with agetValidationStrategy()
this is the message that should be shown to customers. Intended to be displayed directly on the page when thegetValidationStrategy()
fails validation.- Parameters:
errorMessage
- message that customers see on invalid input
-
setErrorCode
In case of a validation failure in conjunction with agetValidationStrategy()
this is the error code that should be shown to customers. This could map into a special message key on the frontend or provide additional information to the user in addition togetErrorMessage()
.- Parameters:
errorCode
- additional information that should be shown whengetValidationStrategy()
is non-null and validation fails- See Also:
-
setAllowedValues
Gives the customer more structured input to fill out their option, which can drive a select field or a color picker with particular colors. This restricts the available values that the user can use to complete this option.When used to distinguish variants, a value in this list should correspond to the value in a variant's
Variant.getOptionValues()
map for theattributeName
key.- Parameters:
allowedValues
- the potential values that a customer can input
-
setAttributes
Map holding any additional attributes passed in the request not matching any defined properties. -
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-