java.lang.Object
com.broadleafcommerce.catalog.domain.product.option.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:
Phillip Verheyden (phillipuniverse)
See Also:
  • Constructor Details

    • AttributeChoice

      public AttributeChoice(String name, String type)
      Convenience method primarily intended for testing.
      Parameters:
      name -
      type -
    • AttributeChoice

      public AttributeChoice()
  • Method Details

    • 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.optionValues.

      Returns:
      the the attribute of where this should be stored
    • getType

      public String getType()
      A hint to the frontend of how to display the customer-facing input. For instance, you might display a set of DefaultAttributeChoiceType.COLOR as a color picker, a DefaultAttributeChoiceType.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

      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
      See Also:
    • getValidationType

      public String getValidationType()
      How the validation from getValidationStrategy() should be performed. Only relevant if getValidationStrategy() is non-null
      Returns:
      how validation should be performed or null if there is no validation
      See Also:
    • 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:
    • 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.optionValues map for the attributeName key.

      Returns:
      the hardcoded values that the customer can input
    • 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.optionValues.

      Parameters:
      name - attribute that this choice is stored into, either on the order item or order
    • setType

      public void setType(String type)
      A hint to the frontend of how to display the customer-facing input. For instance, you might display a set of DefaultAttributeChoiceType.COLOR as a color picker, a DefaultAttributeChoiceType.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

      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
      See Also:
    • setValidationType

      public void setValidationType(String validationType)
      How the validation from getValidationStrategy() should be performed. Only relevant if getValidationStrategy() is non-null
      Parameters:
      validationType - how validation should be performed
      See Also:
    • 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:
    • 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.optionValues map for the attributeName key.

      Parameters:
      allowedValues - the potential values that a customer can input
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object