You can configure the fulfillment system to fill a partial order and backorder the rest if there is not enough inventory to fulfill an entire order. For example, if a customer orders five towels, but there are only three towels available, you can configure the Fulfillment system to “purchase” as many items as possible and backorder any additional items. Follow these steps to make the configuration changes:
Determine how many items are available using
InventoryManager.queryStockLevel()
.Purchase that amount remaining using
InventoryManager.purchase()
.Note: It is possible that another customer could purchase these items in the time between when you called
queryStockLevel
and called purchase. If this is the case, you can either loop until the purchase is successful or there is no inventory left or you can extend theInventoryManager
to purchase all items available.Create a new
ShippingGroupCommerceItemRelationship
in the same shipping group as the item currently being processed and for the sameCommerceItem
. Set the old relationship’s quantity to whatever was successfully purchased. Set the new relationship’s quantity to the remaining quantity. The state of the old relationship is PENDING_DELIVERY while the state of the new relationship will depend onInventoryManager.queryAvailabilityStatus()
.