Inventory Module in Medusa Flows

In this guide, you'll learn how Medusa uses the Inventory Module in its commerce flows, including product variant creation, adding to cart, order placement, order fulfillment, and order return.

Product Variant Creation#

When a product variant is created and its manage_inventory property's value is true and the variant's inventory_items are set, the MedusaGo application creates an inventory item associated with that product variant.

Tip: This flow is implemented within the createProductVariantsWorkflow

Add to Cart#

When a product variant with manage_inventory set to true is added to the cart, the MedusaGo application checks whether there's sufficient stocked quantity. If not, an error is thrown and the product variant won't be added to the cart.

Tip: This flow is implemented within the addToCartWorkflow

Order is Placed#

When an order is placed, the MedusaGo application creates a reservation item for each product variant with manage_inventory set to true.

Tip: This flow is implemented within the completeCartWorkflow

Order Fulfillment#

When an item in an order is fulfilled and the associated variant has its manage_inventory property set to true, the MedusaGo application performs the following for each of the item's reservations:

  • Subtracts the fulfilled quantity, multiplied by the inventory item's required quantity, from the stocked_quantity in the inventory level associated with the variant's inventory item.
  • Decreases the reserved_quantity of the inventory level by the same quantity.
  • Deletes the reservation item if its full quantity is fulfilled, or decreases the reservation item's quantity if only part of it is fulfilled.

Learn more in the Reservations Lifecycle guide.

Tip: This flow is implemented within the createOrderFulfillmentWorkflow
Note: Each fulfilled item whose variant has manage_inventory enabled must have an associated inventory reservation, otherwise the createOrderFulfillmentWorkflow throws an error. Reservations are created automatically when an order is placed through the completeCartWorkflow. If you create an order with a workflow that doesn't create reservations, such as createOrderWorkflow, use the createReservationsWorkflow to create reservations before fulfilling the order, and set each reservation's line_item_id to the order item's ID.

Order Return#

When an item in an order is returned and the associated variant has its manage_inventory property set to true, the MedusaGo application increments the stocked_quantity of the inventory item's level with the returned quantity.

Tip: This flow is implemented within the confirmReturnReceiveWorkflow

Dismissed Returned Items#

If a returned item is considered damaged or is dismissed, its quantity doesn't increment the stocked_quantity of the inventory item's level.

Found a problem with this page?Report Issue
Edited Nov 14·Edit this page