Class DefaultCartItemConfigurationService
- java.lang.Object
-
- com.broadleafcommerce.cartoperation.service.configuration.DefaultCartItemConfigurationService
-
- All Implemented Interfaces:
CartItemConfigurationService
public class DefaultCartItemConfigurationService extends Object implements CartItemConfigurationService
- Author:
- Chad Harchar (charchar)
-
-
Constructor Summary
Constructors Constructor Description DefaultCartItemConfigurationService(CatalogProvider catalogProvider, IncludedProductConfigurationService includedProductService, ItemChoiceConfigurationService itemChoiceService, AttributeChoiceConfigurationService attributeChoiceService, org.springframework.context.MessageSource messageSource, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
addItemConfigError(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull String errorCode, @NonNull String errorMessage)
Variant
determineVariant(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull Product product)
Attempt to determine the variant by the requested variant ID on theCartItem
.protected AttributeChoiceConfigurationService
getAttributeChoiceService()
protected CatalogProvider
getCatalogProvider()
Deprecated.This implementation does not usecatalogProvider
protected IncludedProductConfigurationService
getIncludedProductService()
protected ItemChoiceConfigurationService
getItemChoiceService()
protected String
getMessage(@NonNull String errorMessage, Object... args)
protected org.springframework.context.MessageSource
getMessageSource()
protected com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
protected boolean
hasVariantDistinguishingOptions(@NonNull Product product)
void
hydrateIncludedProductDependentItems(com.broadleafcommerce.cart.client.domain.CartItem cartItem, List<com.broadleafcommerce.cart.client.domain.CartItem> potentialDependentItems, Product product, boolean isAdd)
PopulateIncludedProduct
information onCartItem.getDependentCartItems()
based on the product configuration.void
hydrateItemChoiceDependentItems(com.broadleafcommerce.cart.client.domain.CartItem cartItem, List<com.broadleafcommerce.cart.client.domain.CartItem> potentialDependentItems, Product product)
PopulateItemChoice
information onCartItem.getDependentCartItems()
based on the product configuration.protected boolean
requiredAttributesMissing(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)
void
validateCartItem(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.cart.client.domain.CartItem cartItem, Product product, String validationFlow)
Validate theCartItem
against the providedProduct
.protected void
validateItemAndDependentsHavePositiveQuantities(com.broadleafcommerce.cart.client.domain.CartItem item)
A basic requirement is that all items added to a cart have a positive quantity.
-
-
-
Constructor Detail
-
DefaultCartItemConfigurationService
public DefaultCartItemConfigurationService(CatalogProvider catalogProvider, IncludedProductConfigurationService includedProductService, ItemChoiceConfigurationService itemChoiceService, AttributeChoiceConfigurationService attributeChoiceService, org.springframework.context.MessageSource messageSource, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Detail
-
getCatalogProvider
@Deprecated protected CatalogProvider getCatalogProvider()
Deprecated.This implementation does not usecatalogProvider
Access orcatalogProvider
.- Returns:
- The configured
catalogProvider
-
determineVariant
@Nullable public Variant determineVariant(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull Product product)
Description copied from interface:CartItemConfigurationService
Attempt to determine the variant by the requested variant ID on theCartItem
. Otherwise, if any of theProduct's Options
are marked asProductOptionType.VARIANT_DISTINGUISHING
, we need to determine theVariant
for theCartItem
using theCartItem.getAttributeChoices()
.- Specified by:
determineVariant
in interfaceCartItemConfigurationService
- Parameters:
cartItem
- The cart item to determine the variant for.product
- TheProduct
containing options and variants.
-
hasVariantDistinguishingOptions
protected boolean hasVariantDistinguishingOptions(@NonNull @NonNull Product product)
-
hydrateIncludedProductDependentItems
public void hydrateIncludedProductDependentItems(com.broadleafcommerce.cart.client.domain.CartItem cartItem, List<com.broadleafcommerce.cart.client.domain.CartItem> potentialDependentItems, Product product, boolean isAdd)
Description copied from interface:CartItemConfigurationService
PopulateIncludedProduct
information onCartItem.getDependentCartItems()
based on the product configuration.- Specified by:
hydrateIncludedProductDependentItems
in interfaceCartItemConfigurationService
- Parameters:
cartItem
- The cart item on which to populate dependent item product configuration information.potentialDependentItems
- The list ofCartItem.getDependentCartItems()
to pick from to find a match for anIncludedProduct
.product
- The product with configuration to be used for hydration.isAdd
- Whether we are in an add-to-cart flow
-
hydrateItemChoiceDependentItems
public void hydrateItemChoiceDependentItems(com.broadleafcommerce.cart.client.domain.CartItem cartItem, List<com.broadleafcommerce.cart.client.domain.CartItem> potentialDependentItems, Product product)
Description copied from interface:CartItemConfigurationService
PopulateItemChoice
information onCartItem.getDependentCartItems()
based on the product configuration.- Specified by:
hydrateItemChoiceDependentItems
in interfaceCartItemConfigurationService
- Parameters:
cartItem
- The cart item on which to populate dependent item product configuration information.potentialDependentItems
- The list ofCartItem.getDependentCartItems()
to pick from to find a match for anItemChoice
.product
- The product with configuration to be used for hydration.
-
validateCartItem
public void validateCartItem(@Nullable com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.cart.client.domain.CartItem cartItem, Product product, String validationFlow)
Validate theCartItem
against the providedProduct
. For each ofProduct.getOptions()
, determine if it isProductOptionType.isItemChoice(String)
orProductOptionType.isAttributeChoice(String)
and validate the cart item in the corresponding service. Populate the cart with any errors found.- Specified by:
validateCartItem
in interfaceCartItemConfigurationService
- Parameters:
cart
- The cart with the cart itemcartItem
- TheCartItem
to validate.product
- TheProduct
to get options from to validate the cart against.validationFlow
- The context used to identify validation requirements of theCartItem
at that point in its lifecycle.
-
validateItemAndDependentsHavePositiveQuantities
protected void validateItemAndDependentsHavePositiveQuantities(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
-
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)
-
getIncludedProductService
protected IncludedProductConfigurationService getIncludedProductService()
-
getItemChoiceService
protected ItemChoiceConfigurationService getItemChoiceService()
-
getAttributeChoiceService
protected AttributeChoiceConfigurationService getAttributeChoiceService()
-
getMessageSource
protected org.springframework.context.MessageSource getMessageSource()
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
-