Source Priority Algorithm
Custom stocks include an assigned list of sources to sell and ship available product inventory through your storefront. The Source Priority Algorithm uses the order of assigned sources in the stock to recommend product deductions per source when invoicing and shipping the order.
When run, the algorithm:
- Works through the configured order of sources at the stock level starting at the top
- Recommends a quantity to ship and source per product based on the order in the list, available quantity, and quantity ordered
- Continues down the list until the order shipment is filled
- Skips disabled sources if found in the list
To configure, assign and order sources to a custom stock. See Prioritizing Sources for a Stock.
The following example details the mapped sources in order, available quantity, and recommended source and amount to deduct and ship. The top source is a Drop Shipper in the United Kingdom with an available quantity of 240.
Distance Priority Algorithm
The Distance Priority Algorithm compares the location of the shipping destination address with source locations to determine the closest source to fulfill shipments. The distance may be determined by physical distance or time spent traveling from one location to another, using imported database locations or Google directions (driving, walking, or bicycling).
You have two options for calculating the distance and time to find the closest source for shipment fulfillment:
-
Google MAP - Uses Google Maps Platform services to calculate the distance and time between the shipping destination address and source locations (address and GPS coordinates). This option uses the source’s Latitude and Longitude. A Google API key is required with Geocoding API and Distance Matrix API enabled. This option requires a Google billing plan and may incur charges through Google.
-
Offline Calculation - Calculates the distance using downloaded and imported geocode data to determine the closest source to the shipping destination address. This option uses the country codes of the shipping address and source. To configure this option, you may require developer assistance to initially download and import geocodes using a command line.
To configure, select configurations and complete additional steps such as the Google API key or downloading shipping data. See Configure the Distance Priority Algorithm.
Custom algorithms
Commerce supports custom development and extensions to add alternative algorithms to prioritize sources. For example, you can have one priority algorithm based on geography and another based on expense of stock or a customer attribute. When the cost of stock changes, your implementation can easily change algorithms to ensure the lowest cost.
Reservations
Instead of immediately deducting or adding product inventory quantities, reservations hold inventory amounts until orders ship or cancel. Reservations work entirely in the backend to automatically update your salable quantity at the stock level.
inventory.reservations.updateSalabilityStatus
message queue consumer to run continuously. To check if it is running, use the bin/magento queue:consumers:list
command. If the message queue consumer is not listed, start it: bin/magento queue:consumers:start inventory.reservations.updateSalabilityStatus
.Order reservations
Reservations place holds on inventory quantities deducted from the salable quantity when submitting an order. The reservations are at the stock level, counting against quantities until the order is invoiced and shipped, canceled, and so on. When shipping the order, you can use the SSA recommendations or manually enter quantity deductions per source. When shipped, the reservations are automatically cleared and the quantity deducted. The salable quantity recalculates for the stock with an updated quantity and any reservation amounts remaining in the system.
The following diagram helps define the process of reservations during an order and through to shipment.
A customer submits an order. Commerce checks the current inventory salable quantity. If enough inventory is available at the stock level, a reservation enters placing a temporary hold for the product SKU (for that stock) and recalculates the salable quantity.
After invoicing the order, you determine the product amounts to deduct and ship from your sources. The shipment is processed and sent from one or more selected sources to the customer. The quantities automatically deduct from the source inventory quantity and reservations clear. For complete details and examples, see About Order Status and Reservations.
Reservation calculations
The system creates a reservation for each product when the following events occur:
- A customer or merchant places an order.
- A customer or merchant fully or partially cancels an order.
- The merchant creates a shipment for a physical product.
- The merchant creates an invoice for a virtual or downloadable product.
- The merchant issues a credit memo.
Reservations are append-only operations, similar to a log of events. The initial reservation is assigned a negative quantity value. All subsequent reservations created while processing the order are positive values. When the order is complete, the sum of all reservations for the product is 0.
Before the system can issue a reservation in response to a new order, it determines whether there are enough salable items to fulfill the order. The following quantities factor into the calculation:
-
StockItem quantity. The StockItem quantity is the aggregated amount of inventory from all the physical sources for the current sales channel. Consider an example where the Baltimore source has 20 units of a product, the Austin source has 25 units of the same product, and the Reno source has 10. When all of these sources are linked to Stock A, the StockItem count for this product is 55 (20 + 25 + 10). (When items are shipped, the Inventory indexer updates the quantities available at each source.)
-
Outstanding reservations. The system totals all the initial reservations that have not been compensated. This number is always negative. If customer A has a reservation for ten items, and customer B has a reservation 5 for items, then outstanding reservations for the product total -15.
Therefore, the merchant can fulfill an incoming order as long as the customer orders less than 40 (55 + -15) units.
When you complete processing an order (Complete, Canceled, Closed), all reservations in the scope of that order should resolve to 0
. This clears all salable quantity holds.