|
1
|
--- |
|
2
|
products: |
|
3
|
- fulfillment |
|
4
|
- product |
|
5
|
--- |
|
6
|
|
|
7
|
import { CodeTabs, CodeTab, Table } from "docs-ui" |
|
8
|
|
|
9
|
export const metadata = { |
|
10
|
title: `Links between Pricing Module and Other Modules`, |
|
11
|
} |
|
12
|
|
|
13
|
# {metadata.title} |
|
14
|
|
|
15
|
This document showcases the module links defined between the Pricing Module and other Commerce Modules. |
|
16
|
|
|
17
|
## Summary |
|
18
|
|
|
19
|
The Pricing Module has the following links to other modules: |
|
20
|
|
|
21
|
<Table> |
|
22
|
<Table.Header> |
|
23
|
<Table.Row> |
|
24
|
<Table.HeaderCell> |
|
25
|
First Data Model |
|
26
|
</Table.HeaderCell> |
|
27
|
<Table.HeaderCell> |
|
28
|
Second Data Model |
|
29
|
</Table.HeaderCell> |
|
30
|
<Table.HeaderCell> |
|
31
|
Type |
|
32
|
</Table.HeaderCell> |
|
33
|
<Table.HeaderCell> |
|
34
|
Description |
|
35
|
</Table.HeaderCell> |
|
36
|
</Table.Row> |
|
37
|
</Table.Header> |
|
38
|
<Table.Body> |
|
39
|
<Table.Row> |
|
40
|
<Table.Cell> |
|
41
|
[ShippingOption](/references/fulfillment/models/ShippingOption) in [Fulfillment Module](../../fulfillment/page.mdx) |
|
42
|
</Table.Cell> |
|
43
|
<Table.Cell> |
|
44
|
[PriceSet](/references/pricing/models/PriceSet) |
|
45
|
</Table.Cell> |
|
46
|
<Table.Cell> |
|
47
|
Stored - one-to-one |
|
48
|
</Table.Cell> |
|
49
|
<Table.Cell> |
|
50
|
[Learn more](#fulfillment-module) |
|
51
|
</Table.Cell> |
|
52
|
</Table.Row> |
|
53
|
<Table.Row> |
|
54
|
<Table.Cell> |
|
55
|
[ProductVariant](/references/product/models/ProductVariant) in [Product Module](../../product/page.mdx) |
|
56
|
</Table.Cell> |
|
57
|
<Table.Cell> |
|
58
|
[PriceSet](/references/pricing/models/PriceSet) |
|
59
|
</Table.Cell> |
|
60
|
<Table.Cell> |
|
61
|
Stored - one-to-one |
|
62
|
</Table.Cell> |
|
63
|
<Table.Cell> |
|
64
|
[Learn more](#product-module) |
|
65
|
</Table.Cell> |
|
66
|
</Table.Row> |
|
67
|
</Table.Body> |
|
68
|
</Table> |
|
69
|
|
|
70
|
--- |
|
71
|
|
|
72
|
## Fulfillment Module |
|
73
|
|
|
74
|
The Fulfillment Module provides fulfillment-related functionalities, including shipping options that the customer chooses from when they place their order. However, it doesn't provide pricing-related functionalities for these options. |
|
75
|
|
|
76
|
Medusa defines a link between the `PriceSet` and `ShippingOption` data models. A shipping option's price is stored as a price set. |
|
77
|
|
|
78
|
 |
|
79
|
|
|
80
|
### Retrieve with Query |
|
81
|
|
|
82
|
To retrieve the shipping option of a price set with [Query](!docs!/learn/fundamentals/query), pass `shipping_option.*` in `fields`: |
|
83
|
|
|
84
|
<CodeTabs group="relation-query"> |
|
85
|
<CodeTab label="query.graph" value="method"> |
|
86
|
|
|
87
|
```ts |
|
88
|
const { data: priceSets } = await query.graph({ |
|
89
|
entity: "price_set", |
|
90
|
fields: [ |
|
91
|
"shipping_option.*", |
|
92
|
], |
|
93
|
}) |
|
94
|
|
|
95
|
// priceSets[0].shipping_option |
|
96
|
``` |
|
97
|
|
|
98
|
</CodeTab> |
|
99
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
100
|
|
|
101
|
```ts |
|
102
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
103
|
|
|
104
|
// ... |
|
105
|
|
|
106
|
const { data: priceSets } = useQueryGraphStep({ |
|
107
|
entity: "price_set", |
|
108
|
fields: [ |
|
109
|
"shipping_option.*", |
|
110
|
], |
|
111
|
}) |
|
112
|
|
|
113
|
// priceSets[0].shipping_option |
|
114
|
``` |
|
115
|
|
|
116
|
</CodeTab> |
|
117
|
</CodeTabs> |
|
118
|
|
|
119
|
### Manage with Link |
|
120
|
|
|
121
|
To manage the price set of a shipping option, use [Link](!docs!/learn/fundamentals/module-links/link): |
|
122
|
|
|
123
|
<CodeTabs group="relation-link"> |
|
124
|
<CodeTab label="link.create" value="method"> |
|
125
|
|
|
126
|
```ts |
|
127
|
import { Modules } from "@medusajs/framework/utils" |
|
128
|
|
|
129
|
// ... |
|
130
|
|
|
131
|
await link.create({ |
|
132
|
[Modules.FULFILLMENT]: { |
|
133
|
shipping_option_id: "so_123", |
|
134
|
}, |
|
135
|
[Modules.PRICING]: { |
|
136
|
price_set_id: "pset_123", |
|
137
|
}, |
|
138
|
}) |
|
139
|
``` |
|
140
|
|
|
141
|
</CodeTab> |
|
142
|
<CodeTab label="createRemoteLinkStep" value="step"> |
|
143
|
|
|
144
|
```ts |
|
145
|
import { Modules } from "@medusajs/framework/utils" |
|
146
|
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows" |
|
147
|
|
|
148
|
// ... |
|
149
|
|
|
150
|
createRemoteLinkStep({ |
|
151
|
[Modules.FULFILLMENT]: { |
|
152
|
shipping_option_id: "so_123", |
|
153
|
}, |
|
154
|
[Modules.PRICING]: { |
|
155
|
price_set_id: "pset_123", |
|
156
|
}, |
|
157
|
}) |
|
158
|
``` |
|
159
|
|
|
160
|
</CodeTab> |
|
161
|
</CodeTabs> |
|
162
|
|
|
163
|
--- |
|
164
|
|
|
165
|
## Product Module |
|
166
|
|
|
167
|
The Product Module doesn't store or manage the prices of product variants. |
|
168
|
|
|
169
|
Medusa defines a link between the `ProductVariant` and the `PriceSet`. A product variant's prices are stored as prices belonging to a price set. |
|
170
|
|
|
171
|
 |
|
172
|
|
|
173
|
So, when you want to add prices for a product variant, you create a price set and add the prices to it. |
|
174
|
|
|
175
|
You can then benefit from adding rules to prices or using the `calculatePrices` method to retrieve the price of a product variant within a specified context. |
|
176
|
|
|
177
|
<Note title="Warning" type="warning"> |
|
178
|
|
|
179
|
When you retrieve variant prices through `variants.prices.*` using Query, only prices that are not part of a price list are returned. Prices belonging to a price list (those with a non-null `price_list_id`) are excluded. Refer to the [Get Variant Prices guide](../../product/guides/price/page.mdx) for how to retrieve price-list prices. |
|
180
|
|
|
181
|
</Note> |
|
182
|
|
|
183
|
### Retrieve with Query |
|
184
|
|
|
185
|
To retrieve the variant of a price set with [Query](!docs!/learn/fundamentals/query), pass `variant.*` in `fields`: |
|
186
|
|
|
187
|
<CodeTabs group="relation-query"> |
|
188
|
<CodeTab label="query.graph" value="method"> |
|
189
|
|
|
190
|
```ts |
|
191
|
const { data: priceSets } = await query.graph({ |
|
192
|
entity: "price_set", |
|
193
|
fields: [ |
|
194
|
"variant.*", |
|
195
|
], |
|
196
|
}) |
|
197
|
|
|
198
|
// priceSets[0].variant |
|
199
|
``` |
|
200
|
|
|
201
|
</CodeTab> |
|
202
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
203
|
|
|
204
|
```ts |
|
205
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
206
|
|
|
207
|
// ... |
|
208
|
|
|
209
|
const { data: priceSets } = useQueryGraphStep({ |
|
210
|
entity: "price_set", |
|
211
|
fields: [ |
|
212
|
"variant.*", |
|
213
|
], |
|
214
|
}) |
|
215
|
|
|
216
|
// priceSets[0].variant |
|
217
|
``` |
|
218
|
|
|
219
|
</CodeTab> |
|
220
|
</CodeTabs> |
|
221
|
|
|
222
|
### Manage with Link |
|
223
|
|
|
224
|
To manage the price set of a variant, use [Link](!docs!/learn/fundamentals/module-links/link): |
|
225
|
|
|
226
|
<CodeTabs group="relation-link"> |
|
227
|
<CodeTab label="link.create" value="method"> |
|
228
|
|
|
229
|
```ts |
|
230
|
import { Modules } from "@medusajs/framework/utils" |
|
231
|
|
|
232
|
// ... |
|
233
|
|
|
234
|
await link.create({ |
|
235
|
[Modules.PRODUCT]: { |
|
236
|
variant_id: "variant_123", |
|
237
|
}, |
|
238
|
[Modules.PRICING]: { |
|
239
|
price_set_id: "pset_123", |
|
240
|
}, |
|
241
|
}) |
|
242
|
``` |
|
243
|
|
|
244
|
</CodeTab> |
|
245
|
<CodeTab label="createRemoteLinkStep" value="step"> |
|
246
|
|
|
247
|
```ts |
|
248
|
import { Modules } from "@medusajs/framework/utils" |
|
249
|
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows" |
|
250
|
|
|
251
|
// ... |
|
252
|
|
|
253
|
createRemoteLinkStep({ |
|
254
|
[Modules.PRODUCT]: { |
|
255
|
variant_id: "variant_123", |
|
256
|
}, |
|
257
|
[Modules.PRICING]: { |
|
258
|
price_set_id: "pset_123", |
|
259
|
}, |
|
260
|
}) |
|
261
|
``` |
|
262
|
|
|
263
|
</CodeTab> |
|
264
|
</CodeTabs> |