public class ExternalInventoryProvider extends AbstractExternalProvider implements InventoryProvider
InventoryProvider,
EmptyInventoryProvider| Modifier and Type | Field and Description |
|---|---|
protected static String |
AVAILABILITY_CHECK_UNEXPECTED_FAILURE_ERROR_MSG |
protected static String |
CANNOT_DETERMINE_CART_ITEM_INVENTORY_ERROR_MSG |
protected static String |
DEFAULT_RESERVATION_REQUEST_TYPE |
protected static String |
DEFAULT_SKU_REF_FIELD_TYPE |
protected static String |
INVENTORY_UNAVAILABLE |
protected static String |
UNAVAILABLE_CART_ITEM_INVENTORY_ERROR_MSG |
| Constructor and Description |
|---|
ExternalInventoryProvider(org.springframework.web.reactive.function.client.WebClient webClient,
com.fasterxml.jackson.databind.ObjectMapper objectMapper,
com.broadleafcommerce.common.extension.TypeFactory typeFactory,
ExternalInventoryProperties properties) |
| Modifier and Type | Method and Description |
|---|---|
protected InventoryUnavailableException |
buildExceptionForUnexpectedReservationError(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
@NonNull Exception ex) |
protected Optional<SkuInventoryReservationRequest> |
buildInventoryReservationRequest(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
This allows implementors to build a
SkuInventoryReservationRequest or return an empty
Optional if no external request should be made (e.g. |
protected Exception |
buildReservationResponseException(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
@NonNull org.springframework.web.reactive.function.client.WebClientResponseException ex)
Builds the appropriate exception that should be thrown when a request to reserve inventory
fails.
|
protected List<SkuInventoryAvailabilityRequest> |
buildSkuInventoryAvailabilityRequests(Map<String,Integer> skuCodesAndQuantity)
Builds a list
SkuInventoryAvailabilityRequest to verify the availability of the SKU
for the provided quantity. |
protected String |
getAvailabilityCheckUri(@NonNull String skuCode,
int quantity,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Return the GET URI for Inventory Availability.
|
protected String |
getBulkAvailabilityCheckUri(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Return the GET URI for Inventory Availability.
|
protected org.springframework.core.ParameterizedTypeReference<List<SkuInventoryAvailabilitySummary>> |
getListType()
Gets the type reference for a list of sku availability.
|
protected Object |
getProductType(com.broadleafcommerce.cart.client.domain.CartItem cartItem) |
protected ExternalInventoryProperties |
getProperties() |
protected String |
getReservationRequestType(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Indicates the reservation request type (e.g.
|
protected String |
getReservationUri(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Return the POST URI for Inventory Reservations.
|
protected String |
getSkuReferenceFieldType(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
SkuInventory records can be looked up or reference by a number of field types, including:
SKU_CODE - Identifies a Product.getSku() or Variant.getSku() by a unique SKU
code SKU_EXTERNAL_ID - An ID in another 1st or 3rd party system (e.g. |
Map<String,Boolean> |
isInventoryAvailable(Map<String,Integer> skuCodesAndQuantity,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Determines whether Inventory is available for a list of SKUs.
|
boolean |
isInventoryAvailable(String skuCode,
int quantity,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Determines whether Inventory is available for a particular SKU.
|
protected boolean |
isInventoryUnavailableResponse(@NonNull org.springframework.web.reactive.function.client.WebClientResponseException ex) |
protected void |
postProcessReservationResponse(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
@NonNull SkuInventoryReservationResponse response,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Arbitrary hook point to allow for post processing of the
Cart and/or the
SkuInventoryReservationResponse. |
void |
reserveInventory(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Decrement or otherwise "reserve" inventory for a cart during checkout.
|
executeRequest, getHeaders, getObjectMapper, getTypeFactory, getWebClient, pageableToParams, uriVarsprotected static final String DEFAULT_RESERVATION_REQUEST_TYPE
protected static final String DEFAULT_SKU_REF_FIELD_TYPE
protected static final String INVENTORY_UNAVAILABLE
protected static final String CANNOT_DETERMINE_CART_ITEM_INVENTORY_ERROR_MSG
protected static final String UNAVAILABLE_CART_ITEM_INVENTORY_ERROR_MSG
protected static final String AVAILABILITY_CHECK_UNEXPECTED_FAILURE_ERROR_MSG
public ExternalInventoryProvider(org.springframework.web.reactive.function.client.WebClient webClient,
com.fasterxml.jackson.databind.ObjectMapper objectMapper,
com.broadleafcommerce.common.extension.TypeFactory typeFactory,
ExternalInventoryProperties properties)
public boolean isInventoryAvailable(String skuCode, int quantity, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
InventoryProviderisInventoryAvailable in interface InventoryProviderskuCode - the sku code for which to check inventory availabilityquantity - the quantity of the sku code that will be requestedcontextInfo - context information surrounding sandboxing and multitenant statetrue if inventory is available for the SKU and quantity, false
otherwisepublic Map<String,Boolean> isInventoryAvailable(Map<String,Integer> skuCodesAndQuantity, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
InventoryProviderisInventoryAvailable in interface InventoryProviderskuCodesAndQuantity - a map of the sku codes and quantity for which to check inventory
availabilitycontextInfo - context information surrounding sandboxing and multitenant statetrue if inventory is available for the SKU and
quantity, and false otherwisepublic void reserveInventory(@NonNull
@NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
@Nullable
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
InventoryProviderreserveInventory in interface InventoryProvidercart - The cart for which to decrement inventory.contextInfo - Context information around sandbox and multitenant state.protected Exception buildReservationResponseException(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull org.springframework.web.reactive.function.client.WebClientResponseException ex)
By default, all errors (even those caused by unexpected issues) will result in an
InventoryUnavailableException.
cart - the cart for which reservation was requestedex - the error that was encountered when making the requestprotected InventoryUnavailableException buildExceptionForUnexpectedReservationError(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull Exception ex)
cart - the cart for which inventory reservation was requestedex - the unexpected error that was encounteredprotected boolean isInventoryUnavailableResponse(@NonNull
@NonNull org.springframework.web.reactive.function.client.WebClientResponseException ex)
protected Optional<SkuInventoryReservationRequest> buildInventoryReservationRequest(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
SkuInventoryReservationRequest or return an empty
Optional if no external request should be made (e.g. if all items in the cart are
considered implicitly available.cart - contextInfo - InventoryUnavailableException - - if one or more items are in the cart that are
unavailable.@Nullable protected Object getProductType(com.broadleafcommerce.cart.client.domain.CartItem cartItem)
protected String getReservationUri(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
contextInfo - protected String getAvailabilityCheckUri(@NonNull @NonNull String skuCode, int quantity, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
skuCode.contextInfo - protected String getBulkAvailabilityCheckUri(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
skuCodes.contextInfo - Context information around sandbox and multitenant state.protected void postProcessReservationResponse(@NonNull
@NonNull com.broadleafcommerce.cart.client.domain.Cart cart,
@NonNull
@NonNull SkuInventoryReservationResponse response,
@Nullable
com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Cart and/or the
SkuInventoryReservationResponse.cart - response - contextInfo - protected String getReservationRequestType(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
cart - contextInfo - protected String getSkuReferenceFieldType(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Product.getSku() or Variant.getSku() by a unique SKU
code cart - contextInfo - protected org.springframework.core.ParameterizedTypeReference<List<SkuInventoryAvailabilitySummary>> getListType()
protected List<SkuInventoryAvailabilityRequest> buildSkuInventoryAvailabilityRequests(Map<String,Integer> skuCodesAndQuantity)
SkuInventoryAvailabilityRequest to verify the availability of the SKU
for the provided quantity.protected ExternalInventoryProperties getProperties()
Copyright © 2021. All rights reserved.