Class DefaultInventoryAvailabilityService<I extends CatalogItem>
- java.lang.Object
-
- com.broadleafcommerce.cartoperation.service.inventory.DefaultInventoryAvailabilityService<I>
-
- All Implemented Interfaces:
InventoryAvailabilityService<I>
public class DefaultInventoryAvailabilityService<I extends CatalogItem> extends Object implements InventoryAvailabilityService<I>
- Author:
- Chris Kittrell (ckittrell)
-
-
Constructor Summary
Constructors Constructor Description DefaultInventoryAvailabilityService(InventoryProvider inventoryProvider, org.springframework.context.MessageSource messageSource, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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.ConfigErrorbuildInventoryUnavailableError()protected intcalculateDependentItemsQuantityWithSameSku(@NonNull com.broadleafcommerce.cart.client.domain.CartItem dependentCartItem, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, int parentQuantity)protected intcalculateItemsQuantityWithSameSku(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart)protected intcalculateItemsQuantityWithSameSku(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, int parentItemQuantity)protected booleancatalogItemInternalInventoryUnavailable(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, I catalogItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Determine within theCatalogItemif an inventory check is necessary.protected voidcheckDependentItemInternalInventoryAvailability(@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 voidcheckInternalInventoryAvailability(@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 voidcheckInventoryAvailability(@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.voidcheckInventoryAvailability(@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 StringdetermineCatalogItemInventoryCheckStrategy(@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 theCatalogItemfpr theCartItem.protected StringdetermineDependentItemKey(@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 StringgetCatalogItemKeyFromCartItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem)Hook point to determine what the catalog item is keyed on from theCartItem.protected InventoryProvidergetInventoryProvider()protected org.springframework.context.MessageSourcegetMessageSource()protected BroadleafProductService<Product>getProductService()protected Map<String,Integer>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 itemand its dependent items.protected com.broadleafcommerce.common.extension.TypeFactorygetTypeFactory()protected voidhandleInventoryCheckWithoutCatalogItem(@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 itemfor thecart itemin this request.protected Optional<I>identifyCatalogItemForCartItem(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull CatalogItemList<I> catalogItemList)protected booleanisAvailableOnline(I catalogItem, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Checks whether or not the catalog item is available online.protected booleanisCatalogItemExternalInventoryUnavailable(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, I catalogItem, @NonNull Map<String,Boolean> availabilityMap, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)voidsetProductService(BroadleafProductService<Product> productService)protected booleanshouldCheckInventoryForCartItem(@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 booleanshouldCheckInventoryForCartItemWithoutBackingCatalogItem(@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 theCartItemsince it doesn't have a backingCatalogItem.protected voidverifySkuAvailability(@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 Detail
-
DefaultInventoryAvailabilityService
public DefaultInventoryAvailabilityService(InventoryProvider inventoryProvider, org.springframework.context.MessageSource messageSource, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Detail
-
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:InventoryAvailabilityServiceChecks 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:
checkInventoryAvailabilityin interfaceInventoryAvailabilityService<I extends CatalogItem>- Parameters:
cart- The cart for thiscart itemcartItem- The cart item whose inventory is being checkedcatalogItemList- TheCatalogItemListthat should contain theCartItem'srelatedCatalogItem.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 itemcatalogItem- 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
-
buildInventoryUnavailableError
protected com.broadleafcommerce.cart.client.domain.ConfigError buildInventoryUnavailableError()
-
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 itemand 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 itemcatalogItem- 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 errorsare 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 withtrueif inventory is available for the SKU and quantity, andfalseotherwisecontextInfo- Context information about sandboxing and multitenant state
-
catalogItemInternalInventoryUnavailable
protected boolean catalogItemInternalInventoryUnavailable(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull I catalogItem, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Determine within theCatalogItemif an inventory check is necessary.By default, this checks for
InventoryCheckStrategy.NEVERand checks if theCatalogItemis available online.- Parameters:
cartItem- The cart item whose inventory is being checkedcatalogItem- The catalog item that this CartItem is intended to representcontextInfo- Context information about sandboxing and multitenant state- Returns:
-
isCatalogItemExternalInventoryUnavailable
protected boolean isCatalogItemExternalInventoryUnavailable(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull I catalogItem, @NonNull @NonNull Map<String,Boolean> availabilityMap, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
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 itemfor thecart itemin this request.- Parameters:
cartItem- The cart item whose inventory is being checkedcart- The cart for thiscart itemcatalogItemList- 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 itemcartItem- 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 theCartItemsince it doesn't have a backingCatalogItem.By default, returns false.
- Parameters:
cart- The cart for thiscart itemcartItem- 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 itemcartItem- 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 theCatalogItemfpr 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
protected InventoryProvider getInventoryProvider()
-
getProductService
protected BroadleafProductService<Product> getProductService()
-
setProductService
@Autowired public void setProductService(BroadleafProductService<Product> productService)
-
getMessageSource
protected org.springframework.context.MessageSource getMessageSource()
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
-