|
1
|
--- |
|
2
|
products: |
|
3
|
- cart |
|
4
|
- order |
|
5
|
- payment |
|
6
|
--- |
|
7
|
|
|
8
|
import { CodeTabs, CodeTab, Table } from "docs-ui" |
|
9
|
|
|
10
|
export const metadata = { |
|
11
|
title: `Links between Region Module and Other Modules`, |
|
12
|
} |
|
13
|
|
|
14
|
# {metadata.title} |
|
15
|
|
|
16
|
This document showcases the module links defined between the Region Module and other Commerce Modules. |
|
17
|
|
|
18
|
## Summary |
|
19
|
|
|
20
|
The Region Module has the following links to other modules: |
|
21
|
|
|
22
|
<Note title="Tip"> |
|
23
|
|
|
24
|
Read-only links are used to query data across modules, but the relations aren't stored in a pivot table in the database. |
|
25
|
|
|
26
|
</Note> |
|
27
|
|
|
28
|
<Table> |
|
29
|
<Table.Header> |
|
30
|
<Table.Row> |
|
31
|
<Table.HeaderCell> |
|
32
|
First Data Model |
|
33
|
</Table.HeaderCell> |
|
34
|
<Table.HeaderCell> |
|
35
|
Second Data Model |
|
36
|
</Table.HeaderCell> |
|
37
|
<Table.HeaderCell> |
|
38
|
Type |
|
39
|
</Table.HeaderCell> |
|
40
|
<Table.HeaderCell> |
|
41
|
Description |
|
42
|
</Table.HeaderCell> |
|
43
|
</Table.Row> |
|
44
|
</Table.Header> |
|
45
|
<Table.Body> |
|
46
|
<Table.Row> |
|
47
|
<Table.Cell> |
|
48
|
[Cart](/references/cart/models/Cart) in [Cart Module](../../cart/page.mdx) |
|
49
|
</Table.Cell> |
|
50
|
<Table.Cell> |
|
51
|
[Region](/references/region/models/Region) |
|
52
|
</Table.Cell> |
|
53
|
<Table.Cell> |
|
54
|
Read-only - has one |
|
55
|
</Table.Cell> |
|
56
|
<Table.Cell> |
|
57
|
[Learn more](#cart-module) |
|
58
|
</Table.Cell> |
|
59
|
</Table.Row> |
|
60
|
<Table.Row> |
|
61
|
<Table.Cell> |
|
62
|
[Order](/references/order/models/Order) in [Order Module](../../order/page.mdx) |
|
63
|
</Table.Cell> |
|
64
|
<Table.Cell> |
|
65
|
[Region](/references/region/models/Region) |
|
66
|
</Table.Cell> |
|
67
|
<Table.Cell> |
|
68
|
Read-only - has one |
|
69
|
</Table.Cell> |
|
70
|
<Table.Cell> |
|
71
|
[Learn more](#order-module) |
|
72
|
</Table.Cell> |
|
73
|
</Table.Row> |
|
74
|
<Table.Row> |
|
75
|
<Table.Cell> |
|
76
|
[Region](/references/region/models/Region) |
|
77
|
</Table.Cell> |
|
78
|
<Table.Cell> |
|
79
|
[PaymentProvider](/references/payment/models/PaymentProvider) in [Payment Module](../../payment/page.mdx) |
|
80
|
</Table.Cell> |
|
81
|
<Table.Cell> |
|
82
|
Stored - many-to-many |
|
83
|
</Table.Cell> |
|
84
|
<Table.Cell> |
|
85
|
[Learn more](#payment-module) |
|
86
|
</Table.Cell> |
|
87
|
</Table.Row> |
|
88
|
</Table.Body> |
|
89
|
</Table> |
|
90
|
|
|
91
|
--- |
|
92
|
|
|
93
|
## Cart Module |
|
94
|
|
|
95
|
Medusa defines a read-only link between the [Cart Module](../../cart/page.mdx)'s `Cart` data model and the `Region` data model. Because the link is read-only from the `Cart`'s side, you can only retrieve the region of a cart, and not the other way around. |
|
96
|
|
|
97
|
### Retrieve with Query |
|
98
|
|
|
99
|
To retrieve the region of a cart with [Query](!docs!/learn/fundamentals/query), pass `region.*` in `fields`: |
|
100
|
|
|
101
|
<CodeTabs group="relation-query"> |
|
102
|
<CodeTab label="query.graph" value="method"> |
|
103
|
|
|
104
|
```ts |
|
105
|
const { data: carts } = await query.graph({ |
|
106
|
entity: "cart", |
|
107
|
fields: [ |
|
108
|
"region.*", |
|
109
|
], |
|
110
|
}) |
|
111
|
|
|
112
|
// carts[0].region |
|
113
|
``` |
|
114
|
|
|
115
|
</CodeTab> |
|
116
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
117
|
|
|
118
|
```ts |
|
119
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
120
|
|
|
121
|
// ... |
|
122
|
|
|
123
|
const { data: carts } = useQueryGraphStep({ |
|
124
|
entity: "cart", |
|
125
|
fields: [ |
|
126
|
"region.*", |
|
127
|
], |
|
128
|
}) |
|
129
|
|
|
130
|
// carts[0].region |
|
131
|
``` |
|
132
|
|
|
133
|
</CodeTab> |
|
134
|
</CodeTabs> |
|
135
|
|
|
136
|
--- |
|
137
|
|
|
138
|
## Order Module |
|
139
|
|
|
140
|
Medusa defines a read-only link between the [Order Module](../../order/page.mdx)'s `Order` data model and the `Region` data model. Because the link is read-only from the `Order`'s side, you can only retrieve the region of an order, and not the other way around. |
|
141
|
|
|
142
|
### Retrieve with Query |
|
143
|
|
|
144
|
To retrieve the region of an order with [Query](!docs!/learn/fundamentals/query), pass `region.*` in `fields`: |
|
145
|
|
|
146
|
<CodeTabs group="relation-query"> |
|
147
|
<CodeTab label="query.graph" value="method"> |
|
148
|
|
|
149
|
```ts |
|
150
|
const { data: orders } = await query.graph({ |
|
151
|
entity: "order", |
|
152
|
fields: [ |
|
153
|
"region.*", |
|
154
|
], |
|
155
|
}) |
|
156
|
|
|
157
|
// orders[0].region |
|
158
|
``` |
|
159
|
|
|
160
|
</CodeTab> |
|
161
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
162
|
|
|
163
|
```ts |
|
164
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
165
|
|
|
166
|
// ... |
|
167
|
|
|
168
|
const { data: orders } = useQueryGraphStep({ |
|
169
|
entity: "order", |
|
170
|
fields: [ |
|
171
|
"region.*", |
|
172
|
], |
|
173
|
}) |
|
174
|
|
|
175
|
// orders[0].region |
|
176
|
``` |
|
177
|
|
|
178
|
</CodeTab> |
|
179
|
</CodeTabs> |
|
180
|
|
|
181
|
--- |
|
182
|
|
|
183
|
## Payment Module |
|
184
|
|
|
185
|
You can specify for each region which payment providers are available for use. |
|
186
|
|
|
187
|
Medusa defines a module link between the `PaymentProvider` and the `Region` data models. |
|
188
|
|
|
189
|
 |
|
190
|
|
|
191
|
### Retrieve with Query |
|
192
|
|
|
193
|
To retrieve the payment providers of a region with [Query](!docs!/learn/fundamentals/query), pass `payment_providers.*` in `fields`: |
|
194
|
|
|
195
|
<CodeTabs group="relation-query"> |
|
196
|
<CodeTab label="query.graph" value="method"> |
|
197
|
|
|
198
|
```ts |
|
199
|
const { data: regions } = await query.graph({ |
|
200
|
entity: "region", |
|
201
|
fields: [ |
|
202
|
"payment_providers.*", |
|
203
|
], |
|
204
|
}) |
|
205
|
|
|
206
|
// regions[0].payment_providers |
|
207
|
``` |
|
208
|
|
|
209
|
</CodeTab> |
|
210
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
211
|
|
|
212
|
```ts |
|
213
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
214
|
|
|
215
|
// ... |
|
216
|
|
|
217
|
const { data: regions } = useQueryGraphStep({ |
|
218
|
entity: "region", |
|
219
|
fields: [ |
|
220
|
"payment_providers.*", |
|
221
|
], |
|
222
|
}) |
|
223
|
|
|
224
|
// regions[0].payment_providers |
|
225
|
``` |
|
226
|
|
|
227
|
</CodeTab> |
|
228
|
</CodeTabs> |
|
229
|
|
|
230
|
### Manage with Link |
|
231
|
|
|
232
|
To manage the payment providers in a region, use [Link](!docs!/learn/fundamentals/module-links/link): |
|
233
|
|
|
234
|
<CodeTabs group="relation-link"> |
|
235
|
<CodeTab label="link.create" value="method"> |
|
236
|
|
|
237
|
```ts |
|
238
|
import { Modules } from "@medusajs/framework/utils" |
|
239
|
|
|
240
|
// ... |
|
241
|
|
|
242
|
await link.create({ |
|
243
|
[Modules.REGION]: { |
|
244
|
region_id: "reg_123", |
|
245
|
}, |
|
246
|
[Modules.PAYMENT]: { |
|
247
|
payment_provider_id: "pp_stripe_stripe", |
|
248
|
}, |
|
249
|
}) |
|
250
|
``` |
|
251
|
|
|
252
|
</CodeTab> |
|
253
|
<CodeTab label="createRemoteLinkStep" value="step"> |
|
254
|
|
|
255
|
```ts |
|
256
|
import { Modules } from "@medusajs/framework/utils" |
|
257
|
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows" |
|
258
|
|
|
259
|
// ... |
|
260
|
|
|
261
|
createRemoteLinkStep({ |
|
262
|
[Modules.REGION]: { |
|
263
|
region_id: "reg_123", |
|
264
|
}, |
|
265
|
[Modules.PAYMENT]: { |
|
266
|
payment_provider_id: "pp_stripe_stripe", |
|
267
|
}, |
|
268
|
}) |
|
269
|
``` |
|
270
|
|
|
271
|
</CodeTab> |
|
272
|
</CodeTabs> |