Class AttributeChoice
- java.lang.Object
-
- com.broadleafcommerce.cartoperation.domain.AttributeChoice
-
- All Implemented Interfaces:
Serializable
public class AttributeChoice extends Object implements 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 betweenVariants
.- Author:
- Chad Harchar (charchar)
- See Also:
allowedValues
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AttributeChoice()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAttribute(String name, Object value)
Takes in any additional attributes passed in the request not matching any defined properties.protected boolean
canEqual(Object other)
boolean
equals(Object o)
List<AttributeChoiceValue>
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.Map<String,Object>
getAttribute()
Return any additional attributes passed in the request not matching any defined properties.String
getAttributeName()
The order or item attribute that this choice is stored in when the user adds to their cartMap<String,Object>
getAttributes()
Map holding any additional attributes passed in the request not matching any defined properties.String
getErrorCode()
In case of a validation failure in conjunction with agetValidationStrategy()
this is the error code that should be shown to customers.String
getErrorMessage()
In case of a validation failure in conjunction with agetValidationStrategy()
this is the message that should be shown to customers.String
getValidationRule()
IfvalidationType
isregex
, this is the expression that should execute against the user's value.String
getValidationStrategy()
The strategy used to determine when this product option is validated.String
getValidationType()
How the validation fromgetValidationStrategy()
should be performed.int
hashCode()
boolean
isRequired()
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.String
toString()
-
-
-
Method Detail
-
addAttribute
public void addAttribute(String name, Object value)
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
public Map<String,Object> 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
public String 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
public String 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
public String 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:
ValidationType
-
getValidationRule
public String 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
public String 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
public String 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:
getErrorMessage()
-
getAllowedValues
public List<AttributeChoiceValue> 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
public Map<String,Object> getAttributes()
Map holding any additional attributes passed in the request not matching any defined properties.
-
setAttributeName
public void setAttributeName(String attributeName)
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
public void setValidationStrategy(String validationStrategy)
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
public void setValidationType(String validationType)
How the validation fromgetValidationStrategy()
should be performed. Only relevant ifgetValidationStrategy()
is non-null- Parameters:
validationType
- how validation should be performed- See Also:
ValidationType
-
setValidationRule
public void setValidationRule(String validationRule)
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
public void setErrorMessage(String errorMessage)
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
public 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. 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:
getErrorMessage()
-
setAllowedValues
public 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. 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
public void setAttributes(Map<String,Object> attributes)
Map holding any additional attributes passed in the request not matching any defined properties.
-
canEqual
protected boolean canEqual(Object other)
-
-