Class 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 between Variants.
    Author:
    Chad Harchar (charchar)
    See Also:
    allowedValues, Serialized Form
    • Constructor Detail

      • AttributeChoice

        public AttributeChoice()
    • 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 attribute
        value - 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 cart

        When 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 and allowedValues are always validated.
        Returns:
        the strategy when this choice should be validated or null if no extra validation should be performed
      • getValidationRule

        public String getValidationRule()
        If validationType is regex, 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 a getValidationStrategy() this is the message that should be shown to customers. Intended to be displayed directly on the page when the getValidationStrategy() 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 a getValidationStrategy() 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 to getErrorMessage().
        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 the attributeName 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 cart

        When 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 and allowedValues are always validated.
        Parameters:
        validationStrategy - when this choice should be validated
      • setValidationRule

        public void setValidationRule​(String validationRule)
        If validationType is regex, 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 a getValidationStrategy() this is the message that should be shown to customers. Intended to be displayed directly on the page when the getValidationStrategy() 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 a getValidationStrategy() 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 to getErrorMessage().
        Parameters:
        errorCode - additional information that should be shown when getValidationStrategy() 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 the attributeName 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)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object