Updating Stock Levels

The mechanism for updating stock levels depends on the version of the API your storefront is using.

Stock Level Update Cancellation or Replacement Mechanism

If an order is canceled or replaced, the inventory for the products in the order is updated. For example, if an order for five rings is canceled, the inventory for the rings increases by five. Because order cancellation and replacement are normally done through an integration with an order management system (OMS), there is no example of cancellation and replacement in SiteGenesis.

The stock update mechanism, which uses the ReserveInventoryForOrder pipelet is the recommended method for updating stock levels.
CAUTION:
If you are using the inventory import feed to reset inventory levels, if the inventory level is set to zero via an import feed and an order is then replaced or canceled, the inventory is updated and the inventory level set to the quantity of inventory in the order. The replacement or cancellation is important in the case of a product recall or other situation in which you have decided to immediately stop selling a product and don't want it to appear as an available product.

Replacing an order uses the mechanism for canceling an order followed by the mechanism for creating an order. For replacement orders, the ReserveInventoryForOrder pipelet only reserves inventory for the new order and items for the order being replaced are available for the replacement order.

Order cancellation inventory Process

The following table shows the changes to inventory levels throughout the checkout process.

Checkout step Pipelet Change Inventory Total Example
Customer has created an order, but has not entered the checkout process    

i

i is the inventory at the start of the checkout process.

5 shirts, 3 pants, 10 caps available

two shirts, one pants, three caps in order

Customer enters the checkout process for order X ReserveInventoryForOrder Reserves the change to the inventory for the order. This transaction includes an internal timestamp, so that reservations can timeout if the cart is abandoned.

i - x (while the timestamp is valid)

where:

i is the inventory at the start of the checkout process.

x is the quantity in order X.

Three shirts, two pants, seven caps available

two shirts, one pants, three caps in reserved for order

Customer submits order X

CreateOrder Finalizes the inventory change made using ReserveInventoryForOrder.

i - x

Three shirts, two pants, seven caps available
Customer cancels order X CancelOrder Returns the inventory for the order.

i - x + x

x is the quantity in order X.

5 shirts, 3 pants, 10 caps available

The cancellation mechanism isn't implemented in SiteGenesis, because replacement and cancellation are only used when Salesforce B2C Commerce is integrated with an order management system and SiteGenesis doesn't generally include integration functionality.

Order Replacement Inventory Process

The following table shows the changes to inventory levels throughout the checkout process. An order replacement is equivalent to an order cancellation followed by a new order, except that is it wholly handled by the CreateOrder pipelet. The process allows the inventory from the canceled order to be used for the new order. If the creation of the replacement order fails, the items continue to be reserved for the replacement order.

Checkout step Pipelet Change Inventory Total Example
Customer has created an order, but has not entered the checkout process    

i

i is the inventory at the start of the checkout process.

5 shirts, 3 pants, 10 caps available

two shirts, one pants, three caps in order

Customer enters the checkout process for order X ReserveInventoryForOrder Reserves the change to the inventory for the order. This transaction includes an internal timestamp, so that reservations can timeout if the cart is abandoned.

i - x (while the timestamp is valid)

where:

i is the inventory at the start of the checkout process.

x is the quantity in order X.

Three shirts, two pants, seven caps available

Two shirts, one pants, three caps in reserved for order

Customer submits order X

CreateOrder Finalizes the inventory change made using ReserveInventoryForOrder.

i - x

Three shirts, two pants, seven caps available
Customer replaces order X with order Y ReserveInventoryForOrder

Calculates the change in order quantities and reserves the new quantity.

(x - y) = d

i + d

x is the quantity in order X.

y is the quantity in order Y.

d is the change quantity between in order X and Y. The change for each item in the order is calculated separately. The change can be either negative or positive depending on whether the replacement order item quantity is larger or smaller than the original order.

Four shirts, one pant, four caps in the new order

One shirt, two pants, six caps available

Four shirts, one pants, five caps in reserved for order

  CreateOrder Updates the inventory for the order if the change, returning inventory if fewer items were ordered and finalizing the reservation if more items were ordered.

i + d

d is the change quantity between in order X and Y.

One shirt, two pants, six caps available

Four shirts, one pants, five caps in reserved for order

The order replacement mechanism isn't implemented in SiteGenesis, because replacement is only used when B2C Commerce is integrated with an order management system and SiteGenesis doesn't generally include integration functionality.

Canceling or replacing orders in Business Manager

While you can manually cancel or replace orders in Business Manager, the process doesn't update the stock level for your storefront.

Canceling or Replacing Orders Using Order.SetStatus()

While you can manually cancel or replace orders using the Order.setStatus() method, the process doesn't affect the stock level.

Stock Level Update Mechanism for Order Placement

The stock update mechanism prevents accidental overselling by reserving inventory early in the transaction and not finalizing the stock update until the order is placed.

Checkout step Pipelet Change Inventory Total
Customer starts the checkout process    

i

where n is the inventory at the start of the checkout process.

After payment calculation and before personal information gathered ReserveInventoryForOrder Reserves the change to the inventory for the order. This transaction includes an internal timestamp, so that reservations can timeout if the cart is abandoned.

i - x (while the timestamp is valid)

i (after the timestamp expires)

where:
  • n is the inventory at the start of the checkout process.
  • a is the quantity in the order.

After personal information gathered and before payment handling CreateOrder Finalizes the inventory change made using ReserveInventoryForOrder.

i - x

An example of this mechanism is implemented in the SiteGenesis COPlaceOrder pipeline.

Note: Using the Order.setStatus() method doesn't affect the stock level.

if an order is canceled or replaced, inventory isn't returned.