Class DefaultInventoryAvailabilityService<I extends CatalogItem>
- All Implemented Interfaces:
InventoryAvailabilityService<I>
- Author:
- Chris Kittrell (ckittrell)
-
Constructor Summary
ConstructorDescriptionDefaultInventoryAvailabilityService
(InventoryProvider inventoryProvider, org.springframework.context.MessageSource messageSource, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected List<InventoryAvailabilityRequest>
buildInventoryAvailabilityRequests
(@NonNull Map<String, Integer> requestedQuantitiesPerSku, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull CatalogItemList<I> catalogItemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point for building the request object being sent to theinventory provider
.protected com.broadleafcommerce.cart.client.domain.ConfigError
protected int
calculateDependentItemsQuantityWithSameSku
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem dependentCartItem, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, int parentQuantity) protected int
calculateItemsQuantityWithSameSku
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart) protected int
calculateItemsQuantityWithSameSku
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, int parentItemQuantity) protected boolean
catalogItemInternalInventoryUnavailable
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, I catalogItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determine within theCatalogItem
if an inventory check is necessary.protected void
checkDependentItemInternalInventoryAvailability
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, I catalogItem, @NonNull com.broadleafcommerce.cart.client.domain.CartItem dependantCartItem, I dependentCatalogItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Checks the inventory-related fields in the catalog data to determine whether or not the dependent item is available.protected void
checkInternalInventoryAvailability
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, I catalogItem, @NonNull CatalogItemList<I> catalogItems, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Checks the inventory-related fields in the catalog data to determine whether or not the item is available.protected void
checkInventoryAvailability
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, I catalogItem, @NonNull CatalogItemList<I> catalogItemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Checks the inventory of the cart item.void
checkInventoryAvailability
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull CatalogItemList<I> catalogItemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Checks the inventory of the cart item.protected String
determineCatalogItemInventoryCheckStrategy
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, I catalogItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines the inventory lookup strategy type from theCatalogItem
fpr theCartItem
.protected String
determineDependentItemKey
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem dependantCartItem, @NonNull CatalogItem catalogItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines the item key for the dependent cart item.protected String
getCatalogItemKeyFromCartItem
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Hook point to determine what the catalog item is keyed on from theCartItem
.protected InventoryProvider
protected org.springframework.context.MessageSource
protected BroadleafProductService<Product>
getRequestedQuantitiesPerSku
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, I catalogItem, @NonNull CatalogItemList<I> catalogItemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines the quantity per sku requested by thiscart item
and its dependent items.protected com.broadleafcommerce.common.extension.TypeFactory
protected void
handleInventoryCheckWithoutCatalogItem
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull CatalogItemList<I> catalogItemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determine how to handle inventory checks when there is no backingcatalog item
for thecart item
in this request.identifyCatalogItemForCartItem
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull CatalogItemList<I> catalogItemList) protected boolean
isAvailableOnline
(I catalogItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Checks whether or not the catalog item is available online.protected boolean
isCatalogItemExternalInventoryUnavailable
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, I catalogItem, @NonNull Map<String, Boolean> availabilityMap, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) void
setProductService
(BroadleafProductService<Product> productService) protected boolean
shouldCheckInventoryForCartItem
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, I catalogItem, @NonNull CatalogItemList<I> catalogItemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to determine if inventory should be checked for the CartItem.protected boolean
shouldCheckInventoryForCartItemWithoutBackingCatalogItem
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull CatalogItemList<I> catalogItemList, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to determine if inventory should be checked for theCartItem
since it doesn't have a backingCatalogItem
.protected void
verifySkuAvailability
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, I catalogItem, @NonNull CatalogItemList<I> catalogItems, @NonNull Map<String, Boolean> availabilityMap, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Checks the inventory availability response map against the cart item, and determines if the cart item and its dependent items are available.
-
Constructor Details
-
DefaultInventoryAvailabilityService
public DefaultInventoryAvailabilityService(InventoryProvider inventoryProvider, org.springframework.context.MessageSource messageSource, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
checkInventoryAvailability
public void checkInventoryAvailability(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull CatalogItemList<I> catalogItemList, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:InventoryAvailabilityService
Checks the inventory of the cart item. First, it will check the catalog-based inventory details, and if it passes that check it will make a call to the inventory provider to check availability with the external inventory system.- Specified by:
checkInventoryAvailability
in interfaceInventoryAvailabilityService<I extends CatalogItem>
- Parameters:
cart
- The cart for thiscart item
cartItem
- The cart item whose inventory is being checkedcatalogItemList
- TheCatalogItemList
that should contain theCartItem's
relatedCatalogItem
.contextInfo
- Context information about sandboxing and multitenant state
-
identifyCatalogItemForCartItem
protected Optional<I> identifyCatalogItemForCartItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull CatalogItemList<I> catalogItemList) -
checkInventoryAvailability
protected void checkInventoryAvailability(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull I catalogItem, @NonNull @NonNull CatalogItemList<I> catalogItemList, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Checks the inventory of the cart item. First, it will check the catalog-based inventory details, and if it passes that check it will make a call to the inventory provider to check availability with the external inventory system.- Parameters:
cartItem
- The cart item whose inventory is being checkedcart
- The cart for thiscart item
catalogItem
- The catalog item that this CartItem is intended to representcatalogItemList
- The list of catalog items identified for this requestcontextInfo
- Context information about sandboxing and multitenant state
-
checkInternalInventoryAvailability
protected void checkInternalInventoryAvailability(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull I catalogItem, @NonNull @NonNull CatalogItemList<I> catalogItems, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Checks the inventory-related fields in the catalog data to determine whether or not the item is available.- Parameters:
cartItem
- The cart item whose inventory is being checkedcatalogItem
- The catalog item that this CartItem is intended to representcatalogItems
- The list of catalog items identified for this request
-
checkDependentItemInternalInventoryAvailability
protected void checkDependentItemInternalInventoryAvailability(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull I catalogItem, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem dependantCartItem, @NonNull I dependentCatalogItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Checks the inventory-related fields in the catalog data to determine whether or not the dependent item is available.- Parameters:
cartItem
- The cart item whose inventory is being checkedcatalogItem
- The catalog item that this CartItem is intended to representdependantCartItem
- The dependent cart item whose inventory is being checkeddependentCatalogItem
- The catalog item that this dependent CartItem is intended to represent
-
getRequestedQuantitiesPerSku
protected Map<String,Integer> getRequestedQuantitiesPerSku(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull I catalogItem, @NonNull @NonNull CatalogItemList<I> catalogItemList, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines the quantity per sku requested by thiscart item
and its dependent items.This includes checking for the same items based on the
DefaultMergingType
. If the same item is added to the cart with theDefaultMergingType.SEPARATE
, then the cart will contain several items for the same sku. In this case, we should sum the quantity of these items to check for overall inventory availability on the total.- Parameters:
cartItem
- The cart item whose inventory is being checkedcart
- The cart for thiscart item
catalogItem
- The catalog item that this CartItem is intended to representcatalogItemList
- The list of catalog items identified for this requestcontextInfo
- Context information about sandboxing and multitenant state- Returns:
- a map keyed by SKU of the total quantities requested
-
calculateItemsQuantityWithSameSku
protected int calculateItemsQuantityWithSameSku(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart) -
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) -
verifySkuAvailability
protected void verifySkuAvailability(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull I catalogItem, @NonNull @NonNull CatalogItemList<I> catalogItems, @NonNull @NonNull Map<String, Boolean> availabilityMap, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Checks the inventory availability response map against the cart item, and determines if the cart item and its dependent items are available. For any cart items that are not available,inventory unavailable errors
are built and added to the cart item global config errors.- Parameters:
cartItem
- The cart item whose inventory is being checkedcatalogItem
- The catalog item that this CartItem is intended to representcatalogItems
- The list of catalog items identified for this requestavailabilityMap
- A map of the sku code withtrue
if inventory is available for the SKU and quantity, andfalse
otherwisecontextInfo
- Context information about sandboxing and multitenant state
-
handleInventoryCheckWithoutCatalogItem
protected void handleInventoryCheckWithoutCatalogItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull CatalogItemList<I> catalogItemList, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determine how to handle inventory checks when there is no backingcatalog item
for thecart item
in this request.- Parameters:
cartItem
- The cart item whose inventory is being checkedcart
- The cart for thiscart item
catalogItemList
- The list of catalog items identified for this requestcontextInfo
- Context information about sandboxing and multitenant state
-
buildInventoryAvailabilityRequests
protected List<InventoryAvailabilityRequest> buildInventoryAvailabilityRequests(@NonNull @NonNull Map<String, Integer> requestedQuantitiesPerSku, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull CatalogItemList<I> catalogItemList, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point for building the request object being sent to theinventory provider
.- Parameters:
requestedQuantitiesPerSku
- a map keyed by SKU of the total quantities requestedcart
- The cart for thiscart item
cartItem
- The cart item whose inventory is being checkedcatalogItemList
- The list of catalog items identified for this requestcontextInfo
- Context information about sandboxing and multitenant state- Returns:
- a list of
InventoryAvailabilityRequests
-
isAvailableOnline
protected boolean isAvailableOnline(@NonNull I catalogItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Checks whether or not the catalog item is available online.By default, checks
Product.isAvailableOnline()
flag.- Parameters:
catalogItem
- The catalog item that this CartItem is intended to representcontextInfo
- Context information about sandboxing and multitenant state- Returns:
- true if the catalog item is available online
-
shouldCheckInventoryForCartItemWithoutBackingCatalogItem
protected boolean shouldCheckInventoryForCartItemWithoutBackingCatalogItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull CatalogItemList<I> catalogItemList, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to determine if inventory should be checked for theCartItem
since it doesn't have a backingCatalogItem
.By default, returns false.
- Parameters:
cart
- The cart for thiscart item
cartItem
- The cart item whose inventory is being checkedcatalogItemList
- The list of catalog items identified for this requestcontextInfo
- Context information about sandboxing and multitenant state- Returns:
- true if inventory should be checked
-
shouldCheckInventoryForCartItem
protected boolean shouldCheckInventoryForCartItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull I catalogItem, @NonNull @NonNull CatalogItemList<I> catalogItemList, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to determine if inventory should be checked for the CartItem.By default, checks for no config errors and a positive quantity.
- Parameters:
cart
- The cart for thiscart item
cartItem
- The cart item whose inventory is being checkedcatalogItem
- The catalog item that this CartItem is intended to representcatalogItemList
- The list of catalog items identified for this requestcontextInfo
- Context information about sandboxing and multitenant state- Returns:
- true if inventory should be checked
-
getCatalogItemKeyFromCartItem
protected String getCatalogItemKeyFromCartItem(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem) Hook point to determine what the catalog item is keyed on from theCartItem
.By default, this is set to the product ID.
- Parameters:
cartItem
- the cart item to identify a catalog item key from- Returns:
- the key for the catalog item
-
determineDependentItemKey
protected String determineDependentItemKey(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem dependantCartItem, @NonNull @NonNull CatalogItem catalogItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines the item key for the dependent cart item.By default, uses the
BroadleafProductService.determineDependentItemKey(CartItem, Product, ContextInfo)
to determine the item's key.- Parameters:
catalogItem
- The catalog item of the parent cart itemdependantCartItem
- The dependent cart item whose item key is being determined- Returns:
- the item key for the dependent item
-
determineCatalogItemInventoryCheckStrategy
protected String determineCatalogItemInventoryCheckStrategy(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull I catalogItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines the inventory lookup strategy type from theCatalogItem
fpr theCartItem
.By default, this assumes the catalog item is of type
Product
. If using another type, this would be a good hook point to override this logic for determining theInventoryCheckStrategy
.- Parameters:
catalogItem
- The catalog item that this CartItem is intended to representcartItem
- The cart item whose inventory is being checkedcontextInfo
- Context information about sandboxing and multitenant state- Returns:
-
getInventoryProvider
-
getProductService
-
setProductService
-
getMessageSource
protected org.springframework.context.MessageSource getMessageSource() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-