Class DefaultCartItemConfigurationService<P extends Product>

    • Method Detail

      • validateCartItem

        public void validateCartItem​(@NonNull
                                     @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                     @NonNull
                                     @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem,
                                     @NonNull
                                     @NonNull CatalogItemList<? extends CatalogItem> catalogItemList,
                                     @NonNull
                                     @NonNull String validationFlow)
        Description copied from interface: CartItemConfigurationService
        Process cart item configuration by validating catalog information. Errors for the item will be recorded into CartItem.getGlobalConfigErrors(), while errors for specific attributes will be recorded into CartItem.getAttributeConfigErrors(). For hierarchical cart items (items with CartItem.getDependentCartItems()) it is intended that this method be called from the bottom up, i.e., the lowest level dependent item gets called first. That way, errors on items will be properly cascaded up the hierarchy as CartItemConfigurationErrorEnum.MISCONFIGURED_DEPENDENT_ITEMS on CartItem.getGlobalConfigErrors().
        Specified by:
        validateCartItem in interface CartItemConfigurationService<P extends Product>
        Parameters:
        cart - The cart with the cart item
        cartItem - The cart item with which to process configuration.
        catalogItemList - The CatalogItemList that should contain the CartItem's related CatalogItem.
        validationFlow - The context used to identify validation requirements of the CartItem at that point in its lifecycle. If this is set to ValidationStrategy.ADD_ITEM, then the configuration service will try to
      • validateCartItem

        public void validateCartItem​(@NonNull
                                     @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                     @NonNull
                                     @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem,
                                     @NonNull
                                     @NonNull CatalogItem product,
                                     String validationFlow)
        Description copied from interface: CartItemConfigurationService
        Process cart item configuration by validating catalog information. Errors for the item will be recorded into CartItem.getGlobalConfigErrors(), while errors for specific attributes will be recorded into CartItem.getAttributeConfigErrors(). For hierarchical cart items (items with CartItem.getDependentCartItems()) it is intended that this method be called from the bottom up, i.e., the lowest level dependent item gets called first. That way, errors on items will be properly cascaded up the hierarchy as CartItemConfigurationErrorEnum.MISCONFIGURED_DEPENDENT_ITEMS on CartItem.getGlobalConfigErrors().
        Specified by:
        validateCartItem in interface CartItemConfigurationService<P extends Product>
        Parameters:
        cart - The cart with the cart item
        cartItem - The cart item with which to process configuration.
        product - The CatalogItem with configuration to be used for validation.
        validationFlow - The context used to identify validation requirements of the CartItem at that point in its lifecycle. If this is set to ValidationStrategy.ADD_ITEM, then the configuration service will try to
      • hasVariantDistinguishingOptions

        protected boolean hasVariantDistinguishingOptions​(@NonNull
                                                          P product)
      • validateItemAndDependentsHavePositiveQuantities

        protected void validateItemAndDependentsHavePositiveQuantities​(@NonNull
                                                                       @NonNull com.broadleafcommerce.cart.client.domain.CartItem item)
        A basic requirement is that all items added to a cart have a positive quantity. This method validates the given item and all of its nested dependents to ensure they have a positive quantity. Config errors will be registered on the item if the validation does not pass.
        Parameters:
        item - the item which should be validated to have a positive quantity for itself and dependents
      • hasPositiveQuantity

        protected boolean hasPositiveQuantity​(@NonNull
                                              @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
      • flattenWithDependents

        protected Stream<com.broadleafcommerce.cart.client.domain.CartItem> flattenWithDependents​(@NonNull
                                                                                                  @NonNull com.broadleafcommerce.cart.client.domain.CartItem item)
        Returns a flattened stream consisting of the given item with all of its nested dependents.
        Parameters:
        item - the item to flatten
        Returns:
        a flattened stream consisting of the given item with all of its nested dependents
      • validateQuantityWithinThreshold

        protected void validateQuantityWithinThreshold​(@NonNull
                                                       @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                                       @NonNull
                                                       @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem,
                                                       @NonNull
                                                       P product)
        Checks if the quantity of the item fits within the threshold.
        Parameters:
        cart - The cart for this cart item
        cartItem - The cart item whose quantity is being validated
        product - The product that this CartItem is intended to represent
      • calculateItemsQuantityWithSameSku

        protected int calculateItemsQuantityWithSameSku​(@NonNull
                                                        @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem,
                                                        @NonNull
                                                        @NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
                                                        int parentItemQuantity)
      • calculateDependentItemsQuantityWithSameSku

        protected int calculateDependentItemsQuantityWithSameSku​(@NonNull
                                                                 @NonNull com.broadleafcommerce.cart.client.domain.CartItem dependentCartItem,
                                                                 @NonNull
                                                                 @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem,
                                                                 int parentQuantity)
      • requiredAttributesMissing

        protected boolean requiredAttributesMissing​(@NonNull
                                                    @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
      • addItemConfigError

        protected void addItemConfigError​(@NonNull
                                          @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem,
                                          @NonNull
                                          @NonNull String errorCode,
                                          @NonNull
                                          @NonNull String errorMessage)
      • getMessage

        protected String getMessage​(@NonNull
                                    @NonNull String errorMessage,
                                    @Nullable
                                    Object... args)
      • identifyProductForCartItem

        protected Optional<P> identifyProductForCartItem​(@NonNull
                                                         @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem,
                                                         @NonNull
                                                         @NonNull CatalogItemList<? extends CatalogItem> catalogItemList)
      • getMessageSource

        protected org.springframework.context.MessageSource getMessageSource()
      • getTypeFactory

        protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()