Class CartItemValidationActivity
java.lang.Object
com.broadleafcommerce.cartoperation.service.checkout.workflow.activity.CartItemValidationActivity
- All Implemented Interfaces:
CheckoutWorkflowActivity
This
CheckoutWorkflowActivity
is responsible for validating that the cart's
CartItems
include all necessary selections and data so that we can clearly
understand what is being purchased and must later be fulfilled.- Author:
- Chad Harchar (charchar), Chris Kittrell (ckittrell)
-
Constructor Summary
ConstructorDescriptionCartItemValidationActivity
(CatalogProvider<? extends CatalogItem> catalogProvider, CartItemConfigurationService<? extends CatalogItem> cartItemConfigurationService, org.springframework.context.MessageSource messageSource) -
Method Summary
Modifier and TypeMethodDescriptionprotected CatalogItemRequest
buildCatalogItemRequest
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to create theCatalogItemRequest
and populate any additional attributes that should be passed to theCatalogProvider
when fetching the catalog representation for the cart item.protected Collection<CatalogItemRequest>
buildCatalogItemRequests
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) execute
(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Method responsible for executing some work against the cart that is required for checkout.gatherCartItemConfigErrors
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Gathers all of the config error messages for theCartItem
into a map.protected CartItemConfigurationService<? extends CatalogItem>
protected CatalogProvider<? extends CatalogItem>
protected org.springframework.context.MessageSource
protected com.broadleafcommerce.pricing.client.domain.context.PriceContext
getPriceContext
(Locale locale, javax.money.CurrencyUnit currency) protected StaleCartItemsService
protected com.broadleafcommerce.common.extension.TypeFactory
protected CatalogItem
identifyCatalogItemForCartItem
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull CatalogItemList<? extends CatalogItem> catalogItemList) identifyKeysForCatalogItems
(CatalogItemList<? extends CatalogItem> catalogItemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to collect the keys that will identify theCatalogItems
.protected boolean
isCartItemMissingCatalogItems
(Set<String> catalogItemKeys, com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to determine if theCartItem
does not have a backingCatalogItem
.protected boolean
isDuplicateCatalogItemRequest
(@NonNull Set<CatalogItemRequest> catalogItemRequests, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to prevent duplicateCatalogItemRequests
from being built based on theCartItem
.rollback
(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Method responsible for rolling back any work that was done during the execution of theCheckoutWorkflowActivity.execute(CheckoutProcessDto, ContextInfo)
method.void
setStaleCartItemsService
(StaleCartItemsService staleCartItemsService) void
setTypeFactory
(com.broadleafcommerce.common.extension.TypeFactory typeFactory) protected void
validateCartItems
(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that each of the cart'sCartItems
include all necessary selections and data
-
Constructor Details
-
CartItemValidationActivity
public CartItemValidationActivity(CatalogProvider<? extends CatalogItem> catalogProvider, CartItemConfigurationService<? extends CatalogItem> cartItemConfigurationService, org.springframework.context.MessageSource messageSource)
-
-
Method Details
-
execute
public CheckoutProcessDto execute(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CheckoutWorkflowActivity
Method responsible for executing some work against the cart that is required for checkout. This may include, but is not limited to, cart validation checks, inventory reservations, or payment authorizations.- Specified by:
execute
in interfaceCheckoutWorkflowActivity
- Parameters:
processDto
- TheCheckoutProcessDto
that we're attempting to checkout with.contextInfo
- Context information around sandbox and multitenant state.- Returns:
- The final state of the
CheckoutProcessDto
following the execution of the activity.
-
rollback
public CheckoutProcessDto rollback(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CheckoutWorkflowActivity
Method responsible for rolling back any work that was done during the execution of theCheckoutWorkflowActivity.execute(CheckoutProcessDto, ContextInfo)
method.- Specified by:
rollback
in interfaceCheckoutWorkflowActivity
- Parameters:
processDto
- TheCheckoutProcessDto
that we were attempting to checkout with, but ran into an exception/error.contextInfo
- Context information around sandbox and multitenant state.- Returns:
- The final state of the
CheckoutProcessDto
following the rollback of the activity.
-
validateCartItems
protected void validateCartItems(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that each of the cart'sCartItems
include all necessary selections and data- Parameters:
processDto
- theCheckoutProcessDto
being used for checkoutcontextInfo
- Context information around sandbox and multitenant state.- Throws:
CheckoutWorkflowActivityException
- thrown if an unrecoverable error is encountered during the execution of the activity
-
gatherCartItemConfigErrors
protected Map<String,String> gatherCartItemConfigErrors(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Gathers all of the config error messages for theCartItem
into a map.- Parameters:
cartItem
-- Returns:
- the map of CartItem config error messages
-
identifyCatalogItemForCartItem
protected CatalogItem identifyCatalogItemForCartItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull CatalogItemList<? extends CatalogItem> catalogItemList) -
buildCatalogItemRequests
protected Collection<CatalogItemRequest> buildCatalogItemRequests(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
isDuplicateCatalogItemRequest
protected boolean isDuplicateCatalogItemRequest(@NonNull @NonNull Set<CatalogItemRequest> catalogItemRequests, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to prevent duplicateCatalogItemRequests
from being built based on theCartItem
.By default, we filter on the product ID.
- Parameters:
catalogItemRequests
- the list of requests to pass to theCatalogProvider
cartItem
- theCartItem
to build theCatalogItemRequest
contextInfo
- context information around sandbox and multitenant state- Returns:
- true if building a new
CatalogItemRequest
would be a duplicate of an existing request incatalogItemRequests
-
buildCatalogItemRequest
protected CatalogItemRequest buildCatalogItemRequest(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to create theCatalogItemRequest
and populate any additional attributes that should be passed to theCatalogProvider
when fetching the catalog representation for the cart item.- Parameters:
cartItem
- theCartItem
to build theCatalogItemRequest
contextInfo
- context information around sandbox and multitenant state- Returns:
- the populated
CatalogItemRequest
for theCartItem
-
identifyKeysForCatalogItems
protected Set<String> identifyKeysForCatalogItems(CatalogItemList<? extends CatalogItem> catalogItemList, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to collect the keys that will identify theCatalogItems
.- Parameters:
catalogItemList
- the list ofCatalogItems
contextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- the set of identifying keys for the catalog items
-
isCartItemMissingCatalogItems
protected boolean isCartItemMissingCatalogItems(Set<String> catalogItemKeys, com.broadleafcommerce.cart.client.domain.CartItem cartItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to determine if theCartItem
does not have a backingCatalogItem
.By default, the keys are checked against the cart item's product ID.
- Parameters:
catalogItemKeys
- the set of identifying keys for the catalog itemscartItem
- the cart item to checkcontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- true if the
cartItem
does not have a backingCatalogItem
-
getPriceContext
@Nullable protected com.broadleafcommerce.pricing.client.domain.context.PriceContext getPriceContext(@Nullable Locale locale, @Nullable javax.money.CurrencyUnit currency) -
getCatalogProvider
-
getCartItemConfigurationService
-
getMessageSource
protected org.springframework.context.MessageSource getMessageSource() -
setStaleCartItemsService
-
getStaleCartItemsService
-
setTypeFactory
@Autowired public void setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-