Class DefaultStaleCartItemsService
java.lang.Object
com.broadleafcommerce.cartoperation.service.DefaultStaleCartItemsService
- All Implemented Interfaces:
StaleCartItemsService
The default implementation for
StaleCartItemsService
.- Author:
- Dima Myroniuk (dmyroniuk)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected com.broadleafcommerce.cart.client.domain.CartAlert
buildCatalogItemNotFoundCartAlert
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Builds aCartAlert
indicating that the catalog item was not found.protected List<com.broadleafcommerce.cart.client.domain.CartAlert>
buildCatalogItemNotFoundCartAlerts
(@NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems) Builds a list ofCartAlerts
indicating that the catalog item was not found from the givenCartItems
.protected 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) protected boolean
catalogItemRequestAlreadyExist
(@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
.protected CartOperationService
protected CatalogProvider<? extends CatalogItem>
protected String
getMessage
(@NonNull String errorMessage, Object... args) protected org.springframework.context.MessageSource
protected List<com.broadleafcommerce.cart.client.domain.CartItem>
getRemovedCartItems
(@NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> originalCartItems, @NonNull com.broadleafcommerce.cart.client.domain.Cart updatedCart) Gets a list of removedCartItems
based on the original list of items and the updatedCart
.protected com.broadleafcommerce.common.extension.TypeFactory
identifyKeysForCatalogItems
(@NonNull 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
(@NonNull Set<String> catalogItemKeys, @NonNull 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
for stale cart removal.com.broadleafcommerce.cart.client.domain.Cart
removeStaleCartItems
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, boolean price, boolean updateCart, @NonNull Map<String, String> paymentLockTokens, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Removes theCartItems
from the cart if the appropriate product doesn't exist and creates theCartAlert
about removed items.com.broadleafcommerce.cart.client.domain.Cart
removeStaleCartItems
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull CatalogItemList<? extends CatalogItem> catalogItemList, boolean price, boolean updateCart, @NonNull Map<String, String> paymentLockTokens, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Removes theCartItems
from the cart if the appropriate product doesn't exist and creates theCartAlert
about removed items.com.broadleafcommerce.cart.client.domain.Cart
removeStaleCartItems
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItemsToRemove, boolean price, boolean updateCart, @NonNull Map<String, String> paymentLockTokens, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Removes the specified cart items from the cart and adds theCartAlert
about removed items.void
setCartOperationService
(CartOperationService cartOperationService) void
setCatalogProvider
(CatalogProvider<? extends CatalogItem> catalogProvider) void
setMessageSource
(org.springframework.context.MessageSource messageSource) void
setTypeFactory
(com.broadleafcommerce.common.extension.TypeFactory typeFactory) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.cartoperation.service.StaleCartItemsService
removeStaleCartItems, removeStaleCartItems, removeStaleCartItems
-
Constructor Details
-
DefaultStaleCartItemsService
public DefaultStaleCartItemsService()
-
-
Method Details
-
removeStaleCartItems
public com.broadleafcommerce.cart.client.domain.Cart removeStaleCartItems(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, boolean price, boolean updateCart, @NonNull @NonNull Map<String, String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:StaleCartItemsService
Removes theCartItems
from the cart if the appropriate product doesn't exist and creates theCartAlert
about removed items.- Specified by:
removeStaleCartItems
in interfaceStaleCartItemsService
- Parameters:
cart
- the cart to check the stale itemsprice
- whether or not to re-price the cartupdateCart
- whether or not to updateCart
pricing and save the cart after the removalpaymentLockTokens
- Tokens that grant this service access to act upon the payment. The presence of these tokens indicates that this execution flow owns the lock.contextInfo
- context information about sandboxing and multitenant state- Returns:
- the cart without stale cart items
-
removeStaleCartItems
public com.broadleafcommerce.cart.client.domain.Cart removeStaleCartItems(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull CatalogItemList<? extends CatalogItem> catalogItemList, boolean price, boolean updateCart, @NonNull @NonNull Map<String, String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:StaleCartItemsService
Removes theCartItems
from the cart if the appropriate product doesn't exist and creates theCartAlert
about removed items.- Specified by:
removeStaleCartItems
in interfaceStaleCartItemsService
- Parameters:
cart
- the cart to check the stale itemscatalogItemList
- the list of the products for the cart itemsprice
- whether or not to re-price the cartupdateCart
- whether or not to updateCart
pricing and save the cart after the removalpaymentLockTokens
- Tokens that grant this service access to act upon the payment. The presence of these tokens indicates that this execution flow owns the lock.contextInfo
- context information about sandboxing and multitenant state- Returns:
- the cart without stale cart items
-
removeStaleCartItems
public com.broadleafcommerce.cart.client.domain.Cart removeStaleCartItems(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItemsToRemove, boolean price, boolean updateCart, @NonNull @NonNull Map<String, String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:StaleCartItemsService
Removes the specified cart items from the cart and adds theCartAlert
about removed items.- Specified by:
removeStaleCartItems
in interfaceStaleCartItemsService
- Parameters:
cart
- the cart to check the stale itemscartItemsToRemove
- the list of the items to removeprice
- whether or not to re-price the cartupdateCart
- whether or not to updateCart
pricing and save the cart after the removalpaymentLockTokens
- Tokens that grant this service access to act upon the payment. The presence of these tokens indicates that this execution flow owns the lock.contextInfo
- context information about sandboxing and multitenant state- Returns:
- the cart without stale cart items
-
getRemovedCartItems
protected List<com.broadleafcommerce.cart.client.domain.CartItem> getRemovedCartItems(@NonNull @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> originalCartItems, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart updatedCart) Gets a list of removedCartItems
based on the original list of items and the updatedCart
.- Parameters:
originalCartItems
- a list ofCartItems
before removing any items fromCart
updatedCart
- the updatedCart
after items are removed- Returns:
- a list of removed
CartItems
-
buildCatalogItemNotFoundCartAlerts
protected List<com.broadleafcommerce.cart.client.domain.CartAlert> buildCatalogItemNotFoundCartAlerts(@NonNull @NonNull List<com.broadleafcommerce.cart.client.domain.CartItem> cartItems) Builds a list ofCartAlerts
indicating that the catalog item was not found from the givenCartItems
.- Parameters:
cartItems
- a list ofCartItems
to build theCartAlerts
from- Returns:
- a list of
CartAlerts
indicating that the catalog item was not found for the givenCartItems
-
buildCatalogItemNotFoundCartAlert
protected com.broadleafcommerce.cart.client.domain.CartAlert buildCatalogItemNotFoundCartAlert(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Builds aCartAlert
indicating that the catalog item was not found.By default, this will create an alert of type `PRODUCT_NOT_FOUND`.
- Parameters:
cartItem
- theCartItem
to build theCartAlert
from- Returns:
- the
CartAlert
indicating that the catalog item was not found
-
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) -
catalogItemRequestAlreadyExist
protected boolean catalogItemRequestAlreadyExist(@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(@NonNull @NonNull 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(@NonNull @NonNull Set<String> catalogItemKeys, @NonNull @NonNull 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
for stale cart removal.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
-
getMessage
-
setCartOperationService
-
getCartOperationService
-
setCatalogProvider
-
getCatalogProvider
-
setTypeFactory
@Autowired public void setTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
setMessageSource
@Autowired public void setMessageSource(org.springframework.context.MessageSource messageSource) -
getMessageSource
protected org.springframework.context.MessageSource getMessageSource()
-