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 voidaddItemConfigError(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull String errorCode, @NonNull String errorMessage)VariantdetermineVariant(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull Product product)Attempt to determine the variant by the requested variant ID on theCartItem.protected AttributeChoiceConfigurationServicegetAttributeChoiceService()protected CatalogProvidergetCatalogProvider()Deprecated.This implementation does not usecatalogProviderprotected IncludedProductConfigurationServicegetIncludedProductService()protected ItemChoiceConfigurationServicegetItemChoiceService()protected StringgetMessage(@NonNull String errorMessage, Object... args)protected org.springframework.context.MessageSourcegetMessageSource()protected com.broadleafcommerce.common.extension.TypeFactorygetTypeFactory()protected booleanhasVariantDistinguishingOptions(@NonNull Product product)voidhydrateIncludedProductDependentItems(com.broadleafcommerce.cart.client.domain.CartItem cartItem, List<com.broadleafcommerce.cart.client.domain.CartItem> potentialDependentItems, Product product, boolean isAdd)PopulateIncludedProductinformation onCartItem.getDependentCartItems()based on the product configuration.voidhydrateItemChoiceDependentItems(com.broadleafcommerce.cart.client.domain.CartItem cartItem, List<com.broadleafcommerce.cart.client.domain.CartItem> potentialDependentItems, Product product)PopulateItemChoiceinformation onCartItem.getDependentCartItems()based on the product configuration.protected booleanrequiredAttributesMissing(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)voidvalidateCartItem(com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.cart.client.domain.CartItem cartItem, Product product, String validationFlow)Validate theCartItemagainst the providedProduct.protected voidvalidateItemAndDependentsHavePositiveQuantities(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 usecatalogProviderAccess 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:CartItemConfigurationServiceAttempt to determine the variant by the requested variant ID on theCartItem. Otherwise, if any of theProduct's Optionsare marked asProductOptionType.VARIANT_DISTINGUISHING, we need to determine theVariantfor theCartItemusing theCartItem.getAttributeChoices().- Specified by:
determineVariantin interfaceCartItemConfigurationService- Parameters:
cartItem- The cart item to determine the variant for.product- TheProductcontaining 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:CartItemConfigurationServicePopulateIncludedProductinformation onCartItem.getDependentCartItems()based on the product configuration.- Specified by:
hydrateIncludedProductDependentItemsin 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:CartItemConfigurationServicePopulateItemChoiceinformation onCartItem.getDependentCartItems()based on the product configuration.- Specified by:
hydrateItemChoiceDependentItemsin 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 theCartItemagainst 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:
validateCartItemin interfaceCartItemConfigurationService- Parameters:
cart- The cart with the cart itemcartItem- TheCartItemto validate.product- TheProductto get options from to validate the cart against.validationFlow- The context used to identify validation requirements of theCartItemat 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()
-
-