|
1
|
export const metadata = { |
|
2
|
title: `Inventory Module in Medusa Flows`, |
|
3
|
} |
|
4
|
|
|
5
|
# {metadata.title} |
|
6
|
|
|
7
|
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. |
|
8
|
|
|
9
|
## Product Variant Creation |
|
10
|
|
|
11
|
When a product variant is created and its `manage_inventory` property's value is `true` and the variant's `inventory_items` are set, the Medusa application creates an inventory item associated with that product variant. |
|
12
|
|
|
13
|
<Note title="Tip"> |
|
14
|
|
|
15
|
This flow is implemented within the [createProductVariantsWorkflow](/references/medusa-workflows/createProductVariantsWorkflow) |
|
16
|
|
|
17
|
</Note> |
|
18
|
|
|
19
|
 |
|
20
|
|
|
21
|
--- |
|
22
|
|
|
23
|
## Add to Cart |
|
24
|
|
|
25
|
When a product variant with `manage_inventory` set to `true` is added to the cart, the Medusa 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. |
|
26
|
|
|
27
|
<Note title="Tip"> |
|
28
|
|
|
29
|
This flow is implemented within the [addToCartWorkflow](/references/medusa-workflows/addToCartWorkflow) |
|
30
|
|
|
31
|
</Note> |
|
32
|
|
|
33
|
 |
|
34
|
|
|
35
|
--- |
|
36
|
|
|
37
|
## Order is Placed |
|
38
|
|
|
39
|
When an order is placed, the Medusa application creates a reservation item for each product variant with `manage_inventory` set to `true`. |
|
40
|
|
|
41
|
<Note title="Tip"> |
|
42
|
|
|
43
|
This flow is implemented within the [completeCartWorkflow](/references/medusa-workflows/completeCartWorkflow) |
|
44
|
|
|
45
|
</Note> |
|
46
|
|
|
47
|
 |
|
48
|
|
|
49
|
--- |
|
50
|
|
|
51
|
## Order Fulfillment |
|
52
|
|
|
53
|
When an item in an order is fulfilled and the associated variant has its `manage_inventory` property set to `true`, the Medusa application: |
|
54
|
|
|
55
|
- Subtracts the `reserved_quantity` from the `stocked_quantity` in the inventory level associated with the variant's inventory item. |
|
56
|
- Resets the `reserved_quantity` to `0`. |
|
57
|
- Deletes the associated reservation item. |
|
58
|
|
|
59
|
<Note title="Tip"> |
|
60
|
|
|
61
|
This flow is implemented within the [createOrderFulfillmentWorkflow](/references/medusa-workflows/createOrderFulfillmentWorkflow) |
|
62
|
|
|
63
|
</Note> |
|
64
|
|
|
65
|
<Note> |
|
66
|
|
|
67
|
Each fulfilled item whose variant has `manage_inventory` enabled must have an associated inventory reservation, otherwise the [createOrderFulfillmentWorkflow](/references/medusa-workflows/createOrderFulfillmentWorkflow) throws an error. Reservations are created automatically when an order is placed through the [completeCartWorkflow](/references/medusa-workflows/completeCartWorkflow). If you create an order with a workflow that doesn't create reservations, such as [createOrderWorkflow](/references/medusa-workflows/createOrderWorkflow), use the [createReservationsWorkflow](/references/medusa-workflows/createReservationsWorkflow) to create reservations before fulfilling the order, and set each reservation's `line_item_id` to the order item's ID. |
|
68
|
|
|
69
|
</Note> |
|
70
|
|
|
71
|
 |
|
72
|
|
|
73
|
--- |
|
74
|
|
|
75
|
## Order Return |
|
76
|
|
|
77
|
When an item in an order is returned and the associated variant has its `manage_inventory` property set to `true`, the Medusa application increments the `stocked_quantity` of the inventory item's level with the returned quantity. |
|
78
|
|
|
79
|
<Note title="Tip"> |
|
80
|
|
|
81
|
This flow is implemented within the [confirmReturnReceiveWorkflow](/references/medusa-workflows/confirmReturnReceiveWorkflow) |
|
82
|
|
|
83
|
</Note> |
|
84
|
|
|
85
|
 |
|
86
|
|
|
87
|
### Dismissed Returned Items |
|
88
|
|
|
89
|
If a returned item is considered damaged or is dismissed, its quantity doesn't increment the `stocked_quantity` of the inventory item's level. |