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

    Modifier and Type
    Method
    Description
    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 the inventory 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 the CatalogItem 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 the CatalogItem fpr the CartItem.
    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 the CartItem.
     
    protected org.springframework.context.MessageSource
     
     
    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 this cart 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 backing catalog item for the cart item in this request.
    protected Optional<I>
    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
     
    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 the CartItem since it doesn't have a backing CatalogItem.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 interface InventoryAvailabilityService<I extends CatalogItem>
      Parameters:
      cart - The cart for this cart item
      cartItem - The cart item whose inventory is being checked
      catalogItemList - The CatalogItemList that should contain the CartItem's related CatalogItem.
      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 checked
      cart - The cart for this cart item
      catalogItem - The catalog item that this CartItem is intended to represent
      catalogItemList - The list of catalog items identified for this request
      contextInfo - 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 checked
      catalogItem - The catalog item that this CartItem is intended to represent
      catalogItems - 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 checked
      catalogItem - The catalog item that this CartItem is intended to represent
      dependantCartItem - The dependent cart item whose inventory is being checked
      dependentCatalogItem - 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 this cart 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 the DefaultMergingType.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 checked
      cart - The cart for this cart item
      catalogItem - The catalog item that this CartItem is intended to represent
      catalogItemList - The list of catalog items identified for this request
      contextInfo - 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 checked
      catalogItem - The catalog item that this CartItem is intended to represent
      catalogItems - The list of catalog items identified for this request
      availabilityMap - A map of the sku code with true if inventory is available for the SKU and quantity, and false otherwise
      contextInfo - 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 the CatalogItem if an inventory check is necessary.

      By default, this checks for InventoryCheckStrategy.NEVER and checks if the CatalogItem is available online.

      Parameters:
      cartItem - The cart item whose inventory is being checked
      catalogItem - The catalog item that this CartItem is intended to represent
      contextInfo - 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 backing catalog item for the cart item in this request.
      Parameters:
      cartItem - The cart item whose inventory is being checked
      cart - The cart for this cart item
      catalogItemList - The list of catalog items identified for this request
      contextInfo - 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 the inventory provider.
      Parameters:
      requestedQuantitiesPerSku - a map keyed by SKU of the total quantities requested
      cart - The cart for this cart item
      cartItem - The cart item whose inventory is being checked
      catalogItemList - The list of catalog items identified for this request
      contextInfo - 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 represent
      contextInfo - 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 the CartItem since it doesn't have a backing CatalogItem.

      By default, returns false.

      Parameters:
      cart - The cart for this cart item
      cartItem - The cart item whose inventory is being checked
      catalogItemList - The list of catalog items identified for this request
      contextInfo - 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 this cart item
      cartItem - The cart item whose inventory is being checked
      catalogItem - The catalog item that this CartItem is intended to represent
      catalogItemList - The list of catalog items identified for this request
      contextInfo - 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 the CartItem.

      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 item
      dependantCartItem - 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 the CatalogItem fpr the CartItem.

      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 the InventoryCheckStrategy.

      Parameters:
      catalogItem - The catalog item that this CartItem is intended to represent
      cartItem - The cart item whose inventory is being checked
      contextInfo - 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()