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