Class AttributeChoice
java.lang.Object
com.broadleafcommerce.catalog.domain.product.option.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:
- Phillip Verheyden (phillipuniverse)
- See Also:
-
allowedValues
- Serialized Form
-
Constructor Summary
ConstructorDescriptionAttributeChoice
(String name, String type) Convenience method primarily intended for testing. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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.The order or item attribute that this choice is stored in when the user adds to their cartIn 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.getType()
A hint to the frontend of how to display the customer-facing input.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
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
A hint to the frontend of how to display the customer-facing input.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
Convenience method primarily intended for testing.- Parameters:
name
-type
-
-
AttributeChoice
public AttributeChoice()
-
-
Method Details
-
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.optionValues
.- Returns:
- the the attribute of where this should be stored
-
getType
A hint to the frontend of how to display the customer-facing input. For instance, you might display a set ofDefaultAttributeChoiceType.COLOR
as a color picker, aDefaultAttributeChoiceType.DATE
as a date field, etc.- Returns:
- how the customer-facing UI should display this choice
- See Also:
-
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
- See Also:
-
DefaultValidationStrategy
validationType
-
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.optionValues
map for theattributeName
key.- Returns:
- the hardcoded values that the customer can input
-
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.optionValues
.- Parameters:
name
- attribute that this choice is stored into, either on the order item or order
-
setType
A hint to the frontend of how to display the customer-facing input. For instance, you might display a set ofDefaultAttributeChoiceType.COLOR
as a color picker, aDefaultAttributeChoiceType.DATE
as a date field, etc.- Parameters:
type
- hint for how the customer-facing UI should display this choice- See Also:
-
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- See Also:
-
DefaultValidationStrategy
validationType
-
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.optionValues
map for theattributeName
key.- Parameters:
allowedValues
- the potential values that a customer can input
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-