|
1
|
export const metadata = { |
|
2
|
title: `Order Edit`, |
|
3
|
} |
|
4
|
|
|
5
|
# {metadata.title} |
|
6
|
|
|
7
|
In this guide, you'll learn about order edits. |
|
8
|
|
|
9
|
<Note title="Looking for no-code docs?"> |
|
10
|
|
|
11
|
Refer to this [Medusa Admin User Guide](!user-guide!/orders/edit) to learn how to edit an order's items using the dashboard. |
|
12
|
|
|
13
|
</Note> |
|
14
|
|
|
15
|
## What is an Order Edit? |
|
16
|
|
|
17
|
A merchant can edit an order to add new items or change the quantity of existing items. |
|
18
|
|
|
19
|
An order edit is represented by the [OrderChange data model](/references/order/models/OrderChange). |
|
20
|
|
|
21
|
The `OrderChange` data model is associated with any type of change, including returns or exchanges. However, its `change_type` property distinguishes the type of change being made. |
|
22
|
|
|
23
|
For order edits, the `OrderChange`'s `change_type` is `edit`. |
|
24
|
|
|
25
|
--- |
|
26
|
|
|
27
|
## Add Items in an Order Edit |
|
28
|
|
|
29
|
When a merchant adds new items to an order during editing, the item is added as an [OrderItem](/references/order/models/OrderItem). |
|
30
|
|
|
31
|
Additionally, an `OrderChangeAction` is created. The [OrderChangeAction data model](/references/order/models/OrderChangeAction) represents a change made by an `OrderChange`, such as adding an item. |
|
32
|
|
|
33
|
When an item is added, an `OrderChangeAction` is created with the type `ITEM_ADD`. Its `details` property stores the item's ID, price, and quantity. |
|
34
|
|
|
35
|
--- |
|
36
|
|
|
37
|
## Update Items in an Order Edit |
|
38
|
|
|
39
|
A merchant can update an existing item's quantity, price, or metadata. |
|
40
|
|
|
41
|
This change is recorded as an `OrderChangeAction` with the type `ITEM_UPDATE`. Its `details` property stores the item's ID, updated price, and updated quantity. |
|
42
|
|
|
43
|
Once the order edit is confirmed, the Order Module writes the updated `quantity`, `unit_price`, `compare_at_unit_price`, and `metadata` to the [OrderItem record](/references/order/models/OrderItem) of the order's new version. The [OrderLineItem record](/references/order/models/OrderLineItem) keeps the values it had when the item was added to the order. |
|
44
|
|
|
45
|
<Note> |
|
46
|
|
|
47
|
Retrieving the order after the edit returns the updated values in `items.unit_price` and `items.metadata`, since the Order Module merges the versioned record into each item. To read the versioned values directly, select `items.detail.unit_price` and `items.detail.metadata`. Refer to the [Order Versioning guide](../order-versioning/page.mdx#retrieve-versioned-item-details) for details. |
|
48
|
|
|
49
|
</Note> |
|
50
|
|
|
51
|
--- |
|
52
|
|
|
53
|
## Shipping Methods of New Items in the Edit |
|
54
|
|
|
55
|
Adding new items to the order requires adding shipping methods for those items. |
|
56
|
|
|
57
|
These shipping methods are represented by the [OrderShippingMethod data model](/references/order/models/OrderShippingMethod). Also, an `OrderChangeAction` is created with the type `SHIPPING_ADD`. |
|
58
|
|
|
59
|
--- |
|
60
|
|
|
61
|
## How Order Edits Impact an Order’s Version |
|
62
|
|
|
63
|
When an order edit is confirmed, the order’s [version](../order-versioning/page.mdx) is incremented. |
|
64
|
|
|
65
|
--- |
|
66
|
|
|
67
|
## Payments and Refunds for Order Edit Changes |
|
68
|
|
|
69
|
Once the order edit is confirmed, any additional payment or refund required can be made on the original order. |
|
70
|
|
|
71
|
This is determined by the comparison between the `OrderSummary` and the order's transactions, as mentioned in the [Transactions guide](../transactions/page.mdx#checking-outstanding-amount). |
|
72
|
|
|
73
|
--- |
|
74
|
|
|
75
|
## Suppress Customer Notification for an Order Edit |
|
76
|
|
|
77
|
<Note> |
|
78
|
|
|
79
|
This feature is available since Medusa [v2.19.0](https://github.com/medusajs/medusa/releases/tag/v2.19.0). |
|
80
|
|
|
81
|
</Note> |
|
82
|
|
|
83
|
When requesting an order edit, you can pass `no_notification: true` to the `requestOrderEditRequestWorkflow` to indicate that the customer should not be notified about the order edit request. |
|
84
|
|
|
85
|
The value is stored on the `OrderChange` record and forwarded to the `order-edit.requested` event's payload. Subscribers that send notifications to the customer can check `no_notification` before sending: |
|
86
|
|
|
87
|
```ts title="src/subscribers/order-edit-requested.ts" |
|
88
|
import { |
|
89
|
SubscriberArgs, |
|
90
|
SubscriberConfig, |
|
91
|
} from "@medusajs/framework" |
|
92
|
|
|
93
|
export default async function orderEditRequestedHandler({ |
|
94
|
event: { data }, |
|
95
|
container, |
|
96
|
}: SubscriberArgs<{ order_id: string; no_notification?: boolean }>) { |
|
97
|
if (data.no_notification) { |
|
98
|
return |
|
99
|
} |
|
100
|
|
|
101
|
// send notification to the customer |
|
102
|
} |
|
103
|
|
|
104
|
export const config: SubscriberConfig = { |
|
105
|
event: "order-edit.requested", |
|
106
|
} |
|
107
|
``` |
|
108
|
|
|
109
|
Similarly, when the order edit is confirmed, the `order-edit.confirmed` event receives a `no_notification` property that reflects the value set when the edit was originally requested. |
|
110
|
|
|
111
|
When requesting an order edit through the [JS SDK](../js-sdk/page.mdx), pass `no_notification` in the request body: |
|
112
|
|
|
113
|
```ts |
|
114
|
await sdk.admin.orderEdit.request(orderId, { |
|
115
|
no_notification: true, |
|
116
|
}) |
|
117
|
``` |