Class DefaultCartItemConfigurationService<P extends Product>
java.lang.Object
com.broadleafcommerce.cartoperation.service.configuration.DefaultCartItemConfigurationService<P>
- All Implemented Interfaces:
CartItemConfigurationService<P>
public class DefaultCartItemConfigurationService<P extends Product>
extends Object
implements CartItemConfigurationService<P>
- Author:
- Chad Harchar (charchar)
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultCartItemConfigurationService(IncludedProductConfigurationService includedProductService, ItemChoiceConfigurationService itemChoiceService, AttributeChoiceConfigurationService attributeChoiceService, org.springframework.context.MessageSource messageSource, com.broadleafcommerce.common.extension.TypeFactory typeFactory) DefaultCartItemConfigurationService(CatalogProvider<? extends CatalogItem> catalogProvider, IncludedProductConfigurationService includedProductService, ItemChoiceConfigurationService itemChoiceService, AttributeChoiceConfigurationService attributeChoiceService, org.springframework.context.MessageSource messageSource, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddItemConfigError(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull String errorCode, @NonNull String errorMessage) protected intcalculateDependentItemsQuantityWithSameSku(@NonNull com.broadleafcommerce.cart.client.domain.CartItem dependentCartItem, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, int parentQuantity) protected intcalculateItemsQuantityWithSameSku(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, int parentItemQuantity) booleancartItemHasQuantityThresholds(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull CatalogItemList<? extends CatalogItem> catalogItemList) Determines if the providedCartItem'srelatedCatalogItemhas quantity threshold restrictions.protected Stream<com.broadleafcommerce.cart.client.domain.CartItem>flattenWithDependents(@NonNull com.broadleafcommerce.cart.client.domain.CartItem item) Returns a flattened stream consisting of the given item with all of its nested dependents.protected AttributeChoiceConfigurationServiceprotected BroadleafProductService<Product>protected CatalogProvider<? extends CatalogItem>Deprecated.protected IncludedProductConfigurationServiceprotected ItemChoiceConfigurationServiceprotected StringgetMessage(@NonNull String errorMessage, Object... args) protected org.springframework.context.MessageSourceprotected com.broadleafcommerce.common.extension.TypeFactoryprotected booleanhasPositiveQuantity(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) protected booleanhasVariantDistinguishingOptions(P product) identifyProductForCartItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull CatalogItemList<? extends CatalogItem> catalogItemList) protected booleanrequiredAttributesMissing(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) voidsetBroadleafProductService(BroadleafProductService<Product> broadleafProductService) voidvalidateCartItem(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull CatalogItemList<? extends CatalogItem> catalogItemList, @NonNull String validationFlow) Process cart item configuration by validating catalog information.voidvalidateCartItem(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull CatalogItem product, String validationFlow) Process cart item configuration by validating catalog information.protected voidvalidateItemAndDependentsHavePositiveQuantities(@NonNull com.broadleafcommerce.cart.client.domain.CartItem item) A basic requirement is that all items added to a cart have a positive quantity.protected voidvalidateQuantityWithinThreshold(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, P product) Checks if the quantity of the item fits within the threshold.
-
Constructor Details
-
DefaultCartItemConfigurationService
public DefaultCartItemConfigurationService(IncludedProductConfigurationService includedProductService, ItemChoiceConfigurationService itemChoiceService, AttributeChoiceConfigurationService attributeChoiceService, org.springframework.context.MessageSource messageSource, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
DefaultCartItemConfigurationService
public DefaultCartItemConfigurationService(CatalogProvider<? extends CatalogItem> catalogProvider, IncludedProductConfigurationService includedProductService, ItemChoiceConfigurationService itemChoiceService, AttributeChoiceConfigurationService attributeChoiceService, org.springframework.context.MessageSource messageSource, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
getCatalogProvider
Deprecated.This implementation does not usecatalogProviderAccess orcatalogProvider.- Returns:
- The configured
catalogProvider
-
cartItemHasQuantityThresholds
public boolean cartItemHasQuantityThresholds(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull CatalogItemList<? extends CatalogItem> catalogItemList) Description copied from interface:CartItemConfigurationServiceDetermines if the providedCartItem'srelatedCatalogItemhas quantity threshold restrictions.- Specified by:
cartItemHasQuantityThresholdsin interfaceCartItemConfigurationService<P extends Product>- Parameters:
cartItem- TheCartItemthat we need to check for quantity thresholds.catalogItemList- TheCatalogItemListthat should contain theCartItem'srelatedCatalogItem.- Returns:
- If the provided
CartItem'srelatedCatalogItemhas quantity threshold restrictions.
-
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:CartItemConfigurationServiceProcess cart item configuration by validating catalog information. Errors for the item will be recorded intoCartItem.getGlobalConfigErrors(), while errors for specific attributes will be recorded intoCartItem.getAttributeConfigErrors(). For hierarchical cart items (items withCartItem.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 asCartItemConfigurationErrorEnum.MISCONFIGURED_DEPENDENT_ITEMSonCartItem.getGlobalConfigErrors().- Specified by:
validateCartItemin interfaceCartItemConfigurationService<P extends Product>- Parameters:
cart- The cart with the cart itemcartItem- The cart item with which to process configuration.catalogItemList- TheCatalogItemListthat should contain theCartItem'srelatedCatalogItem.validationFlow- The context used to identify validation requirements of theCartItemat that point in its lifecycle. If this is set toValidationStrategy.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:CartItemConfigurationServiceProcess cart item configuration by validating catalog information. Errors for the item will be recorded intoCartItem.getGlobalConfigErrors(), while errors for specific attributes will be recorded intoCartItem.getAttributeConfigErrors(). For hierarchical cart items (items withCartItem.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 asCartItemConfigurationErrorEnum.MISCONFIGURED_DEPENDENT_ITEMSonCartItem.getGlobalConfigErrors().- Specified by:
validateCartItemin interfaceCartItemConfigurationService<P extends Product>- Parameters:
cart- The cart with the cart itemcartItem- The cart item with which to process configuration.product- TheCatalogItemwith configuration to be used for validation.validationFlow- The context used to identify validation requirements of theCartItemat that point in its lifecycle. If this is set toValidationStrategy.ADD_ITEM, then the configuration service will try to
-
hasVariantDistinguishingOptions
-
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 thiscart itemcartItem- The cart item whose quantity is being validatedproduct- 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
-
getMessage
-
identifyProductForCartItem
protected Optional<P> identifyProductForCartItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull CatalogItemList<? extends CatalogItem> catalogItemList) -
getIncludedProductService
-
getItemChoiceService
-
getAttributeChoiceService
-
getMessageSource
protected org.springframework.context.MessageSource getMessageSource() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getBroadleafProductService
-
setBroadleafProductService
@Autowired public void setBroadleafProductService(BroadleafProductService<Product> broadleafProductService)
-
catalogProvider