Broadleaf Microservices
  • v1.0.0-latest-prod

Inventory Services Key Components

Domain

Inventory Services are relatively simple. There are 3 major domain components:

  • SKU Inventory (com.broadleafcommerce.inventory.domain.SkuInventory)

    • This represents an Inventory record for a particular SKU or product.

    • Sku Inventory is always associated with an Inventory Location.

    • SKU Inventory records have a soft reference to a SKU or Product via 1 or more properties, including skuCode, externalId, upc, ean, gtin.

    • SKU Inventory records maintain several counts, including quantityAvailable, quantityOnHand, quantityReserved, safetyStock, and quantityOnOrder.

  • Inventory Location (com.broadleafcommerce.inventory.domain.InventoryLocation)

    • Inventory Locations can be none, any, or all of the following: shipping location, pickup location, and/or store location.

    • Shipping Locations are able to ship products to customers, typically after an online purchase. This is typically a warehouse, but could be any location that ships products to a customer.

    • Pickup Locations allow customers to pickup products after an online purchase. This is typically a store, but could be a warehouse, kiosk, or any location where customers can come to pickup an order.

    • Store Location is a location that allows customers to come to shop and buy in store. This type of location is usually one that customers are seeking so that they can physically visit and shop in person.

    • Inventory Location optionally has an address, including latitude and longitude for geo location.

    • All SKU Inventory records must be associated with an Inventory Location.

    • An Application may have 0 or more Inventory Locations, each with 0 or more SKU Inventory records.

  • Inventory Transaction (com.broadleafcommerce.inventory.domain.InventoryTransaction)

    • Inventory Transaction represent adjustments to SKU Inventory records; specifically quantities.

    • Inventory Transactions have specific types: SOFT_RESERVED, HARD_RESERVED, FULFILLED, CANCELLED, ORDERED, RETURNED, RECEIVED, and SHRINKAGE

    • Inventory Transactions are essentially a mechanism to do double sided accounting for changes to Inventory counts.

    • The most common uses right now include SOFT_RESERVED and HARD_RESERVED. SOFT_RESERVED is a temporary reservation of Inventory. In reduces quantity available and increases quantity reserved for a given inventory record. SOFT_RESERVED means that the reservation is temporary and can be rolled back if the status doesn’t change (typically to HARD_RESERVED) within a configurable period of time. HARD_RESERVED is a more permanent transaction status that indicates that the inventory reservation has been made permanent and will not be rolled back, except via a compensating transaction (e.g. RETURNED).

    • Inventory transactions also include properties for quantity, dateProcessed, referenceNumber (typically FulfillmentItem#referenceNumber or a PO number, for example)

Additional, embedded domain:

  • Sku Reference (com.broadleafcommerce.inventory.domain.SkuRef)

    • Represents a soft reference to a SKU or Product

    • Contains the following fields: skuName (optional), skuCode (default), externalId, upc, ean, gtin (at least 1 is required)

    • By default, only skuCode is exposed via the Broadleaf Administrative Console

  • Address (com.broadleafcommerce.inventory.domain.Address)

    • Represents a physical address (most commonly for Inventory Locations)

    • Includes coordinates (latitude / longitude)

    • Includes physical (e.g. mailing) address details such as street, city, state/province/region, country, postal code

Endpoints

Inventory Location

  • /inventory-location/{id}

    • GET, POST`, PUT, DELETE (archive) operations for Inventory Locations

  • /inventory-location/location-number/{inventoryLocationNumber}

    • GET operation to retrieve an Inventory Location by location number, which is an arbitrary business identifier for a store or location

  • /inventory-location/all-locations/country-code/{countryCode}/postal-code/{postalCode}

    • GET operation that retrieves all inventory locations that have the given country code and postal code

  • /inventory-location/shipping-locations/country-code/{countryCode}/postal-code/{postalCode}

    • GET operation that retrieves shipping locations that have the given country code and postal code

  • /inventory-location/pickup-locations/country-code/{countryCode}/postal-code/{postalCode}

    • GET operation that retrieves pickup locations that have the given country code and postal code

  • /inventory-location/store-locations/country-code/{countryCode}/postal-code/{postalCode}

    • GET operation that retrieves store locations that have the given country code and postal code

  • /inventory-location/all-locations/country-code/{countryCode}/region-code/{stateProvinceRegionCode}

    • GET operation that retrieves all locations that have the given country code and state/province/region code

  • /inventory-location/shipping-locations/country-code/{countryCode}/region-code/{stateProvinceRegionCode}

    • GET operation that retrieves shipping locations that have the given country code and state/province/region code

  • /inventory-location/pickup-locations/country-code/{countryCode}/region-code/{stateProvinceRegionCode}

    • GET operation that retrieves pickup locations that have the given country code and state/province/region code

  • /inventory-location/store-locations/country-code/{countryCode}/region-code/{stateProvinceRegionCode}

    • GET operation that retrieves store locations that have the given country code and state/province/region code

  • /inventory-location/all-locations/within-area

    • GET operation that retrieves all locations within a given radius based on latitude and longitude

    • Request parameters include latitude, longitude, radius, distanceType (MILES, KILOMETERS, default is KILOMETERS)

  • /inventory-location/pickup-locations/within-area

    • GET operation that retrieves pickup locations within a given radius based on latitude and longitude

    • Request parameters include latitude, longitude, radius, distanceType (MILES, KILOMETERS, default is KILOMETERS)

  • /inventory-location/shipping-locations/within-area

    • GET operation that retrieves shipping locations within a given radius based on latitude and longitude

    • Request parameters include latitude, longitude, radius, distanceType (MILES, KILOMETERS, default is KILOMETERS)

  • /inventory-location/store-locations/within-area

    • GET operation that retrieves store locations within a given radius based on latitude and longitude

    • Request parameters include latitude, longitude, radius, distanceType (MILES, KILOMETERS, default is KILOMETERS)

SKU Inventory

  • /sku-inventory

    • POST operation that creates a new SKU Inventory record.

    • GET operation that returns all SKU Inventory records for the current Application.

  • /sku-inventory/{id}

    • GET, PUT, DELETE (archive) operations for SKU Inventory based on the database ID.

Inventory Shopping

  • /shop-sku-inventory/availability

    • GET operation to retrieve SKU Inventory summary (availability)

    • Request parameters include:

      • skuFieldType - defaults to SKU_CODE, which means the inventory will be queried based on the SKU code field

      • skuFieldReferences - One or more comma-separated identifiers to query (affected by skuFieldType, which defaults to SKU_CODE)

      • forShipping - Indicates that you are requesting inventory that is available at a shipping location (defaults to true)

      • forPickup - Indicates that you are requesting inventory that is available at a pickup location

      • inStore - Indicates that you are requesting inventory that is available at a store location

  • /shop-sku-inventory/availability/sku-reference/{skuReference}

    • GET operation to retrieve inventory availability for a particular SKU

    • Request parameters include:

      • skuFieldType - defaults to SKU_CODE, which means the inventory will be queried by skuReference based on the SKU code field

      • minAvailableQuantity - Mininmum quantity that is being requested (defaults to 1)

      • forShipping - Indicates that you are requesting inventory that is available at a shipping location (defaults to true)

      • forPickup - Indicates that you are requesting inventory that is available at a pickup location

      • inStore - Indicates that you are requesting inventory that is available at a store location

  • /shop-sku-inventory/availability/inventory-location/{inventoryLocationId}

    • GET operation to retrieve inventory availability at a specified Inventory Location, based on inventoryLocationId

    • Request parameters include:

      • skuFieldType - defaults to SKU_CODE, which means the inventory will be queried by skuReference based on the SKU code field

      • skuFieldReferences - One or more comma-separated identifiers to query (affected by skuFieldType, which defaults to SKU_CODE)

  • /shop-sku-inventory/reservation

    • POST operation to create an InventoryTransaction with a type of HARD or SOFT indicating that a HARD_RESERVATION or a SOFT_RESERVATION should be created

Services

Inventory Location Service

  • com.broadleafcommerce.inventory.service.InventoryLocationService

  • This service provides general CRUD functionality for Inventory Locations. It also provides features for doing geo location queries, if needed, assuming that Inventory Locations have been provided a latitude and longitude.

  • This service is the back-end for most of the functionality associated with /inventory-location/* URIs.

SKU Inventory Service

  • com.broadleafcommerce.inventory.service.SkuInventoryService

  • This service provides general CRUD functionality for SKU Inventory.

SKU Inventory Summary Service

  • com.broadleafcommerce.inventory.service.SkuInventorySummaryService

  • This service provides read-only functionality to find inventory availability and convert that availability to summary data that indicates if it is available or not. This is used mostly for shopping/browsing. However, by default Broadleaf’s sample application does not make use of this. This functionality can be used, as needed, to show inventory availability, typically on a PLP or PDP.

SKU Inventory Availability Strategy

  • com.broadleafcommerce.inventory.service.SkuInventoryAvailabilityStrategy

  • This component will likely be one that is most customized based on specific business requirements. This component has several methods that allow one to read inventory availability, usually for shopping purposes or for reservation purposes. This component has methods to read available inventory generally, based on whether it’s for shipping, pickup, or in-store shopping. It also has the capability to find inventory at a particular location for specific quantities. Additionally, it has a method to accept a Shipping Address to feed heuristics to select the best Inventory Location.

The reason that this component may be customized is that it does not make any assumptions about shipping heuristics (e.g. closest Inventory Location, least expensive shipping scenario, smallest number of shipments, etc.) Rather, this component attempts to find available inventory (for shipping, pickup, or in store shopping) by default, without any exotic heuristics or rules for closest location, least expensive fulfillment, smallest number of shipements, etc.

SKU Inventory Adjustment Service

  • com.broadleafcommerce.inventory.service.SkuInventoryAdjustmentService

  • Inventory can be reserved, typically at checkout. Inventory Reservations are really a type of Inventory Transaction. There are 2 types of Inventory Reservations: SOFT_RESERVATION and HARD_RESERVATION. Soft reservations are temporary and allow for the reservation and decrement of available inventory prior to completion of an order. This can be useful for reserving the inventory prior to payment or reserving inventory for a short period of time with a requirement to purchase or lose the inventory reservation (e.g. concert ticket sales). Hard reservations convert soft reservations into permanent reservations ready for fulfillment. If a hard reservation is created without a soft reservation, then it is equivalent to creating a soft reservation and then a hard reservation at the same time. Here is an diagram that describes the typical process:

Inventory Reservation Sequence Diagram

Persistence

By default, Inventory Services make use of an RDBMS with JPA/Hibernate. Inventory Services makes use of pessimistic locking (DB row locking) when updating SKU Inventory records to ensure that updates are always accurate and predictable.

Additionally (because of pessimistic locking), we use a Spring Data Repository fragment for specific PESSIMISTIC_LOCK functionality and to simplify certain queries. See com.broadleafcommerce.inventory.provider.jpa.repository.DefaultJpaCustomizableSkuInventoryRepository for more information.

Sandboxing Configuration

At the time of this writing, there’s no sandboxable entities in this service. If a sandboxable entity is introduced in this service, the following configurations should be added:

spring:
  cloud:
    stream:
      bindings:
        persistenceOutput:
            triggeredJobEventInputPurgeSandbox:
              group: inventory-purge-sandbox
              destination: triggeredJobEvent
broadleaf:
   transitionrequest:
     enabled: true
   changesummary:
     notification:
       active: true
   tracking:
     sandbox:
       purge:
         enabled: true

See Sandboxing In Detail for more details.

Note
These configurations typically only affect the Granular Deployment model. For Min and Balanced deployements, these configurations are likely already added at the flexpackage-level configuration.