|
1
|
--- |
|
2
|
products: |
|
3
|
- customer |
|
4
|
- cart |
|
5
|
- fulfillment |
|
6
|
- payment |
|
7
|
- product |
|
8
|
- promotion |
|
9
|
- region |
|
10
|
- sales channel |
|
11
|
--- |
|
12
|
|
|
13
|
import { CodeTabs, CodeTab, Table } from "docs-ui" |
|
14
|
|
|
15
|
export const metadata = { |
|
16
|
title: `Links between Order Module and Other Modules`, |
|
17
|
} |
|
18
|
|
|
19
|
# {metadata.title} |
|
20
|
|
|
21
|
This document showcases the module links defined between the Order Module and other Commerce Modules. |
|
22
|
|
|
23
|
## Summary |
|
24
|
|
|
25
|
The Order Module has the following links to other modules: |
|
26
|
|
|
27
|
<Note title="Tip"> |
|
28
|
|
|
29
|
Read-only links are used to query data across modules, but the relations aren't stored in a pivot table in the database. |
|
30
|
|
|
31
|
</Note> |
|
32
|
|
|
33
|
<Table> |
|
34
|
<Table.Header> |
|
35
|
<Table.Row> |
|
36
|
<Table.HeaderCell> |
|
37
|
First Data Model |
|
38
|
</Table.HeaderCell> |
|
39
|
<Table.HeaderCell> |
|
40
|
Second Data Model |
|
41
|
</Table.HeaderCell> |
|
42
|
<Table.HeaderCell> |
|
43
|
Type |
|
44
|
</Table.HeaderCell> |
|
45
|
<Table.HeaderCell> |
|
46
|
Description |
|
47
|
</Table.HeaderCell> |
|
48
|
</Table.Row> |
|
49
|
</Table.Header> |
|
50
|
<Table.Body> |
|
51
|
<Table.Row> |
|
52
|
<Table.Cell> |
|
53
|
[OrderShippingMethod](/references/order/models/OrderShippingMethod) |
|
54
|
</Table.Cell> |
|
55
|
<Table.Cell> |
|
56
|
[ShippingOption](/references/fulfillment/models/ShippingOption) in [Fulfillment Module](../../fulfillment/page.mdx) |
|
57
|
</Table.Cell> |
|
58
|
<Table.Cell> |
|
59
|
Read-only - has one |
|
60
|
</Table.Cell> |
|
61
|
<Table.Cell> |
|
62
|
[Learn more](#link-to-shipping-option) |
|
63
|
</Table.Cell> |
|
64
|
</Table.Row> |
|
65
|
<Table.Row> |
|
66
|
<Table.Cell> |
|
67
|
[Order](/references/order/models/Order) |
|
68
|
</Table.Cell> |
|
69
|
<Table.Cell> |
|
70
|
[Customer](/references/customer/models/Customer) in [Customer Module](../../customer/page.mdx) |
|
71
|
</Table.Cell> |
|
72
|
<Table.Cell> |
|
73
|
Read-only - has one |
|
74
|
</Table.Cell> |
|
75
|
<Table.Cell> |
|
76
|
[Learn more](#customer-module) |
|
77
|
</Table.Cell> |
|
78
|
</Table.Row> |
|
79
|
<Table.Row> |
|
80
|
<Table.Cell> |
|
81
|
[Order](/references/order/models/Order) |
|
82
|
</Table.Cell> |
|
83
|
<Table.Cell> |
|
84
|
[Cart](/references/cart/models/Cart) in [Cart Module](../../cart/page.mdx) |
|
85
|
</Table.Cell> |
|
86
|
<Table.Cell> |
|
87
|
Stored - one-to-one |
|
88
|
</Table.Cell> |
|
89
|
<Table.Cell> |
|
90
|
[Learn more](#cart-module) |
|
91
|
</Table.Cell> |
|
92
|
</Table.Row> |
|
93
|
<Table.Row> |
|
94
|
<Table.Cell> |
|
95
|
[Order](/references/order/models/Order) |
|
96
|
</Table.Cell> |
|
97
|
<Table.Cell> |
|
98
|
[Fulfillment](/references/fulfillment/models/Fulfillment) in [Fulfillment Module](../../fulfillment/page.mdx) |
|
99
|
</Table.Cell> |
|
100
|
<Table.Cell> |
|
101
|
Stored - one-to-many |
|
102
|
</Table.Cell> |
|
103
|
<Table.Cell> |
|
104
|
[Learn more](#fulfillment-module) |
|
105
|
</Table.Cell> |
|
106
|
</Table.Row> |
|
107
|
<Table.Row> |
|
108
|
<Table.Cell> |
|
109
|
[Return](/references/order/models/Return) |
|
110
|
</Table.Cell> |
|
111
|
<Table.Cell> |
|
112
|
[Fulfillment](/references/fulfillment/models/Fulfillment) in [Fulfillment Module](../../fulfillment/page.mdx) |
|
113
|
</Table.Cell> |
|
114
|
<Table.Cell> |
|
115
|
Stored - one-to-many |
|
116
|
</Table.Cell> |
|
117
|
<Table.Cell> |
|
118
|
[Learn more](#fulfillment-module) |
|
119
|
</Table.Cell> |
|
120
|
</Table.Row> |
|
121
|
<Table.Row> |
|
122
|
<Table.Cell> |
|
123
|
[Order](/references/order/models/Order) |
|
124
|
</Table.Cell> |
|
125
|
<Table.Cell> |
|
126
|
[PaymentCollection](/references/payment/models/PaymentCollection) in [Payment Module](../../payment/page.mdx) |
|
127
|
</Table.Cell> |
|
128
|
<Table.Cell> |
|
129
|
Stored - one-to-many |
|
130
|
</Table.Cell> |
|
131
|
<Table.Cell> |
|
132
|
[Learn more](#payment-module) |
|
133
|
</Table.Cell> |
|
134
|
</Table.Row> |
|
135
|
<Table.Row> |
|
136
|
<Table.Cell> |
|
137
|
[OrderClaim](/references/order/models/OrderClaim) |
|
138
|
</Table.Cell> |
|
139
|
<Table.Cell> |
|
140
|
[PaymentCollection](/references/payment/models/PaymentCollection) in [Payment Module](../../payment/page.mdx) |
|
141
|
</Table.Cell> |
|
142
|
<Table.Cell> |
|
143
|
Stored - one-to-many |
|
144
|
</Table.Cell> |
|
145
|
<Table.Cell> |
|
146
|
[Learn more](#payment-module) |
|
147
|
</Table.Cell> |
|
148
|
</Table.Row> |
|
149
|
<Table.Row> |
|
150
|
<Table.Cell> |
|
151
|
[OrderExchange](/references/order/models/OrderExchange) |
|
152
|
</Table.Cell> |
|
153
|
<Table.Cell> |
|
154
|
[PaymentCollection](/references/payment/models/PaymentCollection) in [Payment Module](../../payment/page.mdx) |
|
155
|
</Table.Cell> |
|
156
|
<Table.Cell> |
|
157
|
Stored - one-to-many |
|
158
|
</Table.Cell> |
|
159
|
<Table.Cell> |
|
160
|
[Learn more](#payment-module) |
|
161
|
</Table.Cell> |
|
162
|
</Table.Row> |
|
163
|
<Table.Row> |
|
164
|
<Table.Cell> |
|
165
|
[OrderLineItem](/references/order/models/OrderLineItem) |
|
166
|
</Table.Cell> |
|
167
|
<Table.Cell> |
|
168
|
[Product](/references/product/models/Product) in [Product Module](../../product/page.mdx) |
|
169
|
</Table.Cell> |
|
170
|
<Table.Cell> |
|
171
|
Read-only - has many |
|
172
|
</Table.Cell> |
|
173
|
<Table.Cell> |
|
174
|
[Learn more](#product-module) |
|
175
|
</Table.Cell> |
|
176
|
</Table.Row> |
|
177
|
<Table.Row> |
|
178
|
<Table.Cell> |
|
179
|
[Order](/references/order/models/Order) |
|
180
|
</Table.Cell> |
|
181
|
<Table.Cell> |
|
182
|
[Promotion](/references/promotion/models/Promotion) in [Promotion Module](../../promotion/page.mdx) |
|
183
|
</Table.Cell> |
|
184
|
<Table.Cell> |
|
185
|
Stored - many-to-many |
|
186
|
</Table.Cell> |
|
187
|
<Table.Cell> |
|
188
|
[Learn more](#promotion-module) |
|
189
|
</Table.Cell> |
|
190
|
</Table.Row> |
|
191
|
<Table.Row> |
|
192
|
<Table.Cell> |
|
193
|
[Order](/references/order/models/Order) |
|
194
|
</Table.Cell> |
|
195
|
<Table.Cell> |
|
196
|
[Region](/references/region/models/Region) in [Region Module](../../region/page.mdx) |
|
197
|
</Table.Cell> |
|
198
|
<Table.Cell> |
|
199
|
Read-only - has one |
|
200
|
</Table.Cell> |
|
201
|
<Table.Cell> |
|
202
|
[Learn more](#region-module) |
|
203
|
</Table.Cell> |
|
204
|
</Table.Row> |
|
205
|
<Table.Row> |
|
206
|
<Table.Cell> |
|
207
|
[Order](/references/order/models/Order) |
|
208
|
</Table.Cell> |
|
209
|
<Table.Cell> |
|
210
|
[SalesChannel](/references/sales-channel/models/SalesChannel) in [Sales Channel Module](../../sales-channel/page.mdx) |
|
211
|
</Table.Cell> |
|
212
|
<Table.Cell> |
|
213
|
Read-only - has one |
|
214
|
</Table.Cell> |
|
215
|
<Table.Cell> |
|
216
|
[Learn more](#sales-channel-module) |
|
217
|
</Table.Cell> |
|
218
|
</Table.Row> |
|
219
|
</Table.Body> |
|
220
|
</Table> |
|
221
|
|
|
222
|
--- |
|
223
|
|
|
224
|
## Customer Module |
|
225
|
|
|
226
|
Medusa defines a read-only link between the `Order` data model and the [Customer Module](../../customer/page.mdx)'s `Customer` data model. This means you can retrieve the details of an order's customer, but you don't manage the links in a pivot table in the database. The customer of an order is determined by the `customer_id` property of the `Order` data model. |
|
227
|
|
|
228
|
### Retrieve with Query |
|
229
|
|
|
230
|
To retrieve the customer of an order with [Query](!docs!/learn/fundamentals/query), pass `customer.*` in `fields`: |
|
231
|
|
|
232
|
<CodeTabs group="relation-query"> |
|
233
|
<CodeTab label="query.graph" value="method"> |
|
234
|
|
|
235
|
```ts |
|
236
|
const { data: orders } = await query.graph({ |
|
237
|
entity: "order", |
|
238
|
fields: [ |
|
239
|
"customer.*", |
|
240
|
], |
|
241
|
}) |
|
242
|
|
|
243
|
// orders[0].customer |
|
244
|
``` |
|
245
|
|
|
246
|
</CodeTab> |
|
247
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
248
|
|
|
249
|
```ts |
|
250
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
251
|
|
|
252
|
// ... |
|
253
|
|
|
254
|
const { data: orders } = useQueryGraphStep({ |
|
255
|
entity: "order", |
|
256
|
fields: [ |
|
257
|
"customer.*", |
|
258
|
], |
|
259
|
}) |
|
260
|
|
|
261
|
// orders[0].customer |
|
262
|
``` |
|
263
|
|
|
264
|
</CodeTab> |
|
265
|
</CodeTabs> |
|
266
|
|
|
267
|
--- |
|
268
|
|
|
269
|
## Cart Module |
|
270
|
|
|
271
|
The [Cart Module](../../cart/page.mdx) provides cart-management features. |
|
272
|
|
|
273
|
Medusa defines a link between the `Order` and `Cart` data models. The order is linked to the cart used for the purchased. |
|
274
|
|
|
275
|
 |
|
276
|
|
|
277
|
### Retrieve with Query |
|
278
|
|
|
279
|
To retrieve the cart of an order with [Query](!docs!/learn/fundamentals/query), pass `cart.*` in `fields`: |
|
280
|
|
|
281
|
<CodeTabs group="relation-query"> |
|
282
|
<CodeTab label="query.graph" value="method"> |
|
283
|
|
|
284
|
```ts |
|
285
|
const { data: orders } = await query.graph({ |
|
286
|
entity: "order", |
|
287
|
fields: [ |
|
288
|
"cart.*", |
|
289
|
], |
|
290
|
}) |
|
291
|
|
|
292
|
// orders[0].cart |
|
293
|
``` |
|
294
|
|
|
295
|
</CodeTab> |
|
296
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
297
|
|
|
298
|
```ts |
|
299
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
300
|
|
|
301
|
// ... |
|
302
|
|
|
303
|
const { data: orders } = useQueryGraphStep({ |
|
304
|
entity: "order", |
|
305
|
fields: [ |
|
306
|
"cart.*", |
|
307
|
], |
|
308
|
}) |
|
309
|
|
|
310
|
// orders[0].cart |
|
311
|
``` |
|
312
|
|
|
313
|
</CodeTab> |
|
314
|
</CodeTabs> |
|
315
|
|
|
316
|
### Manage with Link |
|
317
|
|
|
318
|
To manage the cart of an order, use [Link](!docs!/learn/fundamentals/module-links/link): |
|
319
|
|
|
320
|
<CodeTabs group="relation-link"> |
|
321
|
<CodeTab label="link.create" value="method"> |
|
322
|
|
|
323
|
```ts |
|
324
|
import { Modules } from "@medusajs/framework/utils" |
|
325
|
|
|
326
|
// ... |
|
327
|
|
|
328
|
await link.create({ |
|
329
|
[Modules.ORDER]: { |
|
330
|
order_id: "order_123", |
|
331
|
}, |
|
332
|
[Modules.CART]: { |
|
333
|
cart_id: "cart_123", |
|
334
|
}, |
|
335
|
}) |
|
336
|
``` |
|
337
|
|
|
338
|
</CodeTab> |
|
339
|
<CodeTab label="createRemoteLinkStep" value="step"> |
|
340
|
|
|
341
|
```ts |
|
342
|
import { Modules } from "@medusajs/framework/utils" |
|
343
|
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows" |
|
344
|
|
|
345
|
// ... |
|
346
|
|
|
347
|
createRemoteLinkStep({ |
|
348
|
[Modules.ORDER]: { |
|
349
|
order_id: "order_123", |
|
350
|
}, |
|
351
|
[Modules.CART]: { |
|
352
|
cart_id: "cart_123", |
|
353
|
}, |
|
354
|
}) |
|
355
|
``` |
|
356
|
|
|
357
|
</CodeTab> |
|
358
|
</CodeTabs> |
|
359
|
|
|
360
|
--- |
|
361
|
|
|
362
|
## Fulfillment Module |
|
363
|
|
|
364
|
### Link to Fulfillment |
|
365
|
|
|
366
|
A fulfillment is created for an orders' items. Medusa defines a link between the `Fulfillment` and `Order` data models. |
|
367
|
|
|
368
|
 |
|
369
|
|
|
370
|
A fulfillment is also created for a return's items. So, Medusa defines a link between the `Fulfillment` and `Return` data models. |
|
371
|
|
|
372
|
 |
|
373
|
|
|
374
|
#### Retrieve with Query |
|
375
|
|
|
376
|
To retrieve the fulfillments of an order with [Query](!docs!/learn/fundamentals/query), pass `fulfillments.*` in `fields`: |
|
377
|
|
|
378
|
<Note> |
|
379
|
|
|
380
|
To retrieve the fulfillments of a return, pass `fulfillments.*` in `fields`. |
|
381
|
|
|
382
|
</Note> |
|
383
|
|
|
384
|
<CodeTabs group="relation-query"> |
|
385
|
<CodeTab label="query.graph" value="method"> |
|
386
|
|
|
387
|
```ts |
|
388
|
const { data: orders } = await query.graph({ |
|
389
|
entity: "order", |
|
390
|
fields: [ |
|
391
|
"fulfillments.*", |
|
392
|
], |
|
393
|
}) |
|
394
|
|
|
395
|
// orders[0].fulfillments |
|
396
|
``` |
|
397
|
|
|
398
|
</CodeTab> |
|
399
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
400
|
|
|
401
|
```ts |
|
402
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
403
|
|
|
404
|
// ... |
|
405
|
|
|
406
|
const { data: orders } = useQueryGraphStep({ |
|
407
|
entity: "order", |
|
408
|
fields: [ |
|
409
|
"fulfillments.*", |
|
410
|
], |
|
411
|
}) |
|
412
|
|
|
413
|
// orders[0].fulfillments |
|
414
|
``` |
|
415
|
|
|
416
|
</CodeTab> |
|
417
|
</CodeTabs> |
|
418
|
|
|
419
|
#### Manage with Link |
|
420
|
|
|
421
|
To manage the fulfillments of an order, use [Link](!docs!/learn/fundamentals/module-links/link): |
|
422
|
|
|
423
|
<CodeTabs group="relation-link"> |
|
424
|
<CodeTab label="link.create" value="method"> |
|
425
|
|
|
426
|
```ts |
|
427
|
import { Modules } from "@medusajs/framework/utils" |
|
428
|
|
|
429
|
// ... |
|
430
|
|
|
431
|
await link.create({ |
|
432
|
[Modules.ORDER]: { |
|
433
|
order_id: "order_123", |
|
434
|
}, |
|
435
|
[Modules.FULFILLMENT]: { |
|
436
|
fulfillment_id: "ful_123", |
|
437
|
}, |
|
438
|
}) |
|
439
|
``` |
|
440
|
|
|
441
|
</CodeTab> |
|
442
|
<CodeTab label="createRemoteLinkStep" value="step"> |
|
443
|
|
|
444
|
```ts |
|
445
|
import { Modules } from "@medusajs/framework/utils" |
|
446
|
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows" |
|
447
|
|
|
448
|
// ... |
|
449
|
|
|
450
|
createRemoteLinkStep({ |
|
451
|
[Modules.ORDER]: { |
|
452
|
order_id: "order_123", |
|
453
|
}, |
|
454
|
[Modules.FULFILLMENT]: { |
|
455
|
fulfillment_id: "ful_123", |
|
456
|
}, |
|
457
|
}) |
|
458
|
``` |
|
459
|
|
|
460
|
</CodeTab> |
|
461
|
</CodeTabs> |
|
462
|
|
|
463
|
### Link to Shipping Option |
|
464
|
|
|
465
|
Medusa defines a read-only link between the `OrderShippingMethod` data model and the [Fulfillment Module](../../fulfillment/page.mdx)'s `ShippingOption` data model. This means you can retrieve the details of an order shipping method's shipping option, but you don't manage the links in a pivot table in the database. The shipping option of an order shipping method is determined by the `shipping_option_id` property of the `OrderShippingMethod` data model. |
|
466
|
|
|
467
|
<Note> |
|
468
|
|
|
469
|
This link is available since [Medusa v2.21.1](https://github.com/medusajs/medusa/releases/tag/v2.21.1). |
|
470
|
|
|
471
|
</Note> |
|
472
|
|
|
473
|
#### Retrieve with Query |
|
474
|
|
|
475
|
To retrieve the shipping option of an order shipping method with [Query](!docs!/learn/fundamentals/query), pass `shipping_option.*` in `fields`: |
|
476
|
|
|
477
|
<CodeTabs group="relation-query"> |
|
478
|
<CodeTab label="query.graph" value="method"> |
|
479
|
|
|
480
|
```ts |
|
481
|
const { data: orderShippingMethods } = await query.graph({ |
|
482
|
entity: "order_shipping_method", |
|
483
|
fields: [ |
|
484
|
"shipping_option.*", |
|
485
|
], |
|
486
|
}) |
|
487
|
|
|
488
|
// orderShippingMethods[0].shipping_option |
|
489
|
``` |
|
490
|
|
|
491
|
</CodeTab> |
|
492
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
493
|
|
|
494
|
```ts |
|
495
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
496
|
|
|
497
|
// ... |
|
498
|
|
|
499
|
const { data: orderShippingMethods } = useQueryGraphStep({ |
|
500
|
entity: "order_shipping_method", |
|
501
|
fields: [ |
|
502
|
"shipping_option.*", |
|
503
|
], |
|
504
|
}) |
|
505
|
|
|
506
|
// orderShippingMethods[0].shipping_option |
|
507
|
``` |
|
508
|
|
|
509
|
</CodeTab> |
|
510
|
</CodeTabs> |
|
511
|
|
|
512
|
--- |
|
513
|
|
|
514
|
## Payment Module |
|
515
|
|
|
516
|
An order's payment details are stored in a payment collection. This also applies for claims and exchanges. |
|
517
|
|
|
518
|
So, Medusa defines links between the `PaymentCollection` data model and the `Order`, `OrderClaim`, and `OrderExchange` data models. |
|
519
|
|
|
520
|
 |
|
521
|
|
|
522
|
### Retrieve with Query |
|
523
|
|
|
524
|
To retrieve the payment collections of an order, order exchange, or order claim with [Query](!docs!/learn/fundamentals/query), pass `payment_collections.*` in `fields`: |
|
525
|
|
|
526
|
<CodeTabs group="relation-query"> |
|
527
|
<CodeTab label="query.graph" value="method"> |
|
528
|
|
|
529
|
```ts |
|
530
|
const { data: orders } = await query.graph({ |
|
531
|
entity: "order", |
|
532
|
fields: [ |
|
533
|
"payment_collections.*", |
|
534
|
], |
|
535
|
}) |
|
536
|
|
|
537
|
// orders[0].payment_collections |
|
538
|
``` |
|
539
|
|
|
540
|
</CodeTab> |
|
541
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
542
|
|
|
543
|
```ts |
|
544
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
545
|
|
|
546
|
// ... |
|
547
|
|
|
548
|
const { data: orders } = useQueryGraphStep({ |
|
549
|
entity: "order", |
|
550
|
fields: [ |
|
551
|
"payment_collections.*", |
|
552
|
], |
|
553
|
}) |
|
554
|
|
|
555
|
// orders[0].payment_collections |
|
556
|
``` |
|
557
|
|
|
558
|
</CodeTab> |
|
559
|
</CodeTabs> |
|
560
|
|
|
561
|
### Manage with Link |
|
562
|
|
|
563
|
To manage the payment collections of an order, use [Link](!docs!/learn/fundamentals/module-links/link): |
|
564
|
|
|
565
|
<CodeTabs group="relation-link"> |
|
566
|
<CodeTab label="link.create" value="method"> |
|
567
|
|
|
568
|
```ts |
|
569
|
import { Modules } from "@medusajs/framework/utils" |
|
570
|
|
|
571
|
// ... |
|
572
|
|
|
573
|
await link.create({ |
|
574
|
[Modules.ORDER]: { |
|
575
|
order_id: "order_123", |
|
576
|
}, |
|
577
|
[Modules.PAYMENT]: { |
|
578
|
payment_collection_id: "paycol_123", |
|
579
|
}, |
|
580
|
}) |
|
581
|
``` |
|
582
|
|
|
583
|
</CodeTab> |
|
584
|
<CodeTab label="createRemoteLinkStep" value="step"> |
|
585
|
|
|
586
|
```ts |
|
587
|
import { Modules } from "@medusajs/framework/utils" |
|
588
|
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows" |
|
589
|
|
|
590
|
// ... |
|
591
|
|
|
592
|
createRemoteLinkStep({ |
|
593
|
[Modules.ORDER]: { |
|
594
|
order_id: "order_123", |
|
595
|
}, |
|
596
|
[Modules.PAYMENT]: { |
|
597
|
payment_collection_id: "paycol_123", |
|
598
|
}, |
|
599
|
}) |
|
600
|
``` |
|
601
|
|
|
602
|
</CodeTab> |
|
603
|
</CodeTabs> |
|
604
|
|
|
605
|
--- |
|
606
|
|
|
607
|
## Product Module |
|
608
|
|
|
609
|
Medusa defines read-only links between: |
|
610
|
|
|
611
|
- the `OrderLineItem` data model and the [Product Module](../../product/page.mdx)'s `Product` data model. This means you can retrieve the details of a line item's product, but you don't manage the links in a pivot table in the database. The product of a line item is determined by the `product_id` property of the `OrderLineItem` data model. |
|
612
|
- the `OrderLineItem` data model and the [Product Module](../../product/page.mdx)'s `ProductVariant` data model. This means you can retrieve the details of a line item's variant, but you don't manage the links in a pivot table in the database. The variant of a line item is determined by the `variant_id` property of the `OrderLineItem` data model. |
|
613
|
|
|
614
|
### Retrieve with Query |
|
615
|
|
|
616
|
To retrieve the variant of a line item with [Query](!docs!/learn/fundamentals/query), pass `variant.*` in `fields`: |
|
617
|
|
|
618
|
<Note> |
|
619
|
|
|
620
|
To retrieve the product, pass `product.*` in `fields`. |
|
621
|
|
|
622
|
</Note> |
|
623
|
|
|
624
|
<CodeTabs group="relation-query"> |
|
625
|
<CodeTab label="query.graph" value="method"> |
|
626
|
|
|
627
|
```ts |
|
628
|
const { data: lineItems } = await query.graph({ |
|
629
|
entity: "order_line_item", |
|
630
|
fields: [ |
|
631
|
"variant.*", |
|
632
|
], |
|
633
|
}) |
|
634
|
|
|
635
|
// lineItems.variant |
|
636
|
``` |
|
637
|
|
|
638
|
</CodeTab> |
|
639
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
640
|
|
|
641
|
```ts |
|
642
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
643
|
|
|
644
|
// ... |
|
645
|
|
|
646
|
const { data: lineItems } = useQueryGraphStep({ |
|
647
|
entity: "order_line_item", |
|
648
|
fields: [ |
|
649
|
"variant.*", |
|
650
|
], |
|
651
|
}) |
|
652
|
|
|
653
|
// lineItems.variant |
|
654
|
``` |
|
655
|
|
|
656
|
</CodeTab> |
|
657
|
</CodeTabs> |
|
658
|
|
|
659
|
--- |
|
660
|
|
|
661
|
## Promotion Module |
|
662
|
|
|
663
|
An order is associated with the promotion applied on it. Medusa defines a link between the `Order` and `Promotion` data models. |
|
664
|
|
|
665
|
 |
|
666
|
|
|
667
|
### Retrieve with Query |
|
668
|
|
|
669
|
To retrieve the promotion applied on an order with [Query](!docs!/learn/fundamentals/query), pass `promotion.*` in `fields`: |
|
670
|
|
|
671
|
<CodeTabs group="relation-query"> |
|
672
|
<CodeTab label="query.graph" value="method"> |
|
673
|
|
|
674
|
```ts |
|
675
|
const { data: orders } = await query.graph({ |
|
676
|
entity: "order", |
|
677
|
fields: [ |
|
678
|
"promotions.*", |
|
679
|
], |
|
680
|
}) |
|
681
|
|
|
682
|
// orders[0].promotions |
|
683
|
``` |
|
684
|
|
|
685
|
</CodeTab> |
|
686
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
687
|
|
|
688
|
```ts |
|
689
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
690
|
|
|
691
|
// ... |
|
692
|
|
|
693
|
const { data: orders } = useQueryGraphStep({ |
|
694
|
entity: "order", |
|
695
|
fields: [ |
|
696
|
"promotions.*", |
|
697
|
], |
|
698
|
}) |
|
699
|
|
|
700
|
// orders[0].promotions |
|
701
|
``` |
|
702
|
|
|
703
|
</CodeTab> |
|
704
|
</CodeTabs> |
|
705
|
|
|
706
|
### Manage with Link |
|
707
|
|
|
708
|
To manage the promotion of an order, use [Link](!docs!/learn/fundamentals/module-links/link): |
|
709
|
|
|
710
|
<CodeTabs group="relation-link"> |
|
711
|
<CodeTab label="link.create" value="method"> |
|
712
|
|
|
713
|
```ts |
|
714
|
import { Modules } from "@medusajs/framework/utils" |
|
715
|
|
|
716
|
// ... |
|
717
|
|
|
718
|
await link.create({ |
|
719
|
[Modules.ORDER]: { |
|
720
|
order_id: "order_123", |
|
721
|
}, |
|
722
|
[Modules.PROMOTION]: { |
|
723
|
promotion_id: "promo_123", |
|
724
|
}, |
|
725
|
}) |
|
726
|
``` |
|
727
|
|
|
728
|
</CodeTab> |
|
729
|
<CodeTab label="createRemoteLinkStep" value="step"> |
|
730
|
|
|
731
|
```ts |
|
732
|
import { Modules } from "@medusajs/framework/utils" |
|
733
|
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows" |
|
734
|
|
|
735
|
// ... |
|
736
|
|
|
737
|
createRemoteLinkStep({ |
|
738
|
[Modules.ORDER]: { |
|
739
|
order_id: "order_123", |
|
740
|
}, |
|
741
|
[Modules.PROMOTION]: { |
|
742
|
promotion_id: "promo_123", |
|
743
|
}, |
|
744
|
}) |
|
745
|
``` |
|
746
|
|
|
747
|
</CodeTab> |
|
748
|
</CodeTabs> |
|
749
|
|
|
750
|
--- |
|
751
|
|
|
752
|
## Region Module |
|
753
|
|
|
754
|
Medusa defines a read-only link between the `Order` data model and the [Region Module](../../region/page.mdx)'s `Region` data model. This means you can retrieve the details of an order's region, but you don't manage the links in a pivot table in the database. The region of an order is determined by the `region_id` property of the `Order` data model. |
|
755
|
|
|
756
|
### Retrieve with Query |
|
757
|
|
|
758
|
To retrieve the region of an order with [Query](!docs!/learn/fundamentals/query), pass `region.*` in `fields`: |
|
759
|
|
|
760
|
<CodeTabs group="relation-query"> |
|
761
|
<CodeTab label="query.graph" value="method"> |
|
762
|
|
|
763
|
```ts |
|
764
|
const { data: orders } = await query.graph({ |
|
765
|
entity: "order", |
|
766
|
fields: [ |
|
767
|
"region.*", |
|
768
|
], |
|
769
|
}) |
|
770
|
|
|
771
|
// orders[0].region |
|
772
|
``` |
|
773
|
|
|
774
|
</CodeTab> |
|
775
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
776
|
|
|
777
|
```ts |
|
778
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
779
|
|
|
780
|
// ... |
|
781
|
|
|
782
|
const { data: orders } = useQueryGraphStep({ |
|
783
|
entity: "order", |
|
784
|
fields: [ |
|
785
|
"region.*", |
|
786
|
], |
|
787
|
}) |
|
788
|
|
|
789
|
// orders[0].region |
|
790
|
``` |
|
791
|
|
|
792
|
</CodeTab> |
|
793
|
</CodeTabs> |
|
794
|
|
|
795
|
--- |
|
796
|
|
|
797
|
## Sales Channel Module |
|
798
|
|
|
799
|
Medusa defines a read-only link between the `Order` data model and the [Sales Channel Module](../../sales-channel/page.mdx)'s `SalesChannel` data model. This means you can retrieve the details of an order's sales channel, but you don't manage the links in a pivot table in the database. The sales channel of an order is determined by the `sales_channel_id` property of the `Order` data model. |
|
800
|
|
|
801
|
### Retrieve with Query |
|
802
|
|
|
803
|
To retrieve the sales channel of an order with [Query](!docs!/learn/fundamentals/query), pass `sales_channel.*` in `fields`: |
|
804
|
|
|
805
|
<CodeTabs group="relation-query"> |
|
806
|
<CodeTab label="query.graph" value="method"> |
|
807
|
|
|
808
|
```ts |
|
809
|
const { data: orders } = await query.graph({ |
|
810
|
entity: "order", |
|
811
|
fields: [ |
|
812
|
"sales_channel.*", |
|
813
|
], |
|
814
|
}) |
|
815
|
|
|
816
|
// orders[0].sales_channel |
|
817
|
``` |
|
818
|
|
|
819
|
</CodeTab> |
|
820
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
821
|
|
|
822
|
```ts |
|
823
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
824
|
|
|
825
|
// ... |
|
826
|
|
|
827
|
const { data: orders } = useQueryGraphStep({ |
|
828
|
entity: "order", |
|
829
|
fields: [ |
|
830
|
"sales_channel.*", |
|
831
|
], |
|
832
|
}) |
|
833
|
|
|
834
|
// orders[0].sales_channel |
|
835
|
``` |
|
836
|
|
|
837
|
</CodeTab> |
|
838
|
</CodeTabs> |