|
1
|
--- |
|
2
|
products: |
|
3
|
- product |
|
4
|
- store |
|
5
|
--- |
|
6
|
|
|
7
|
import { CodeTabs, CodeTab, Table } from "docs-ui" |
|
8
|
|
|
9
|
export const metadata = { |
|
10
|
title: `Links between Translation Module and Other Modules`, |
|
11
|
} |
|
12
|
|
|
13
|
# {metadata.title} |
|
14
|
|
|
15
|
This document showcases the module links that Medusa defines between the Translation Module and other Commerce Modules. |
|
16
|
|
|
17
|
## Summary |
|
18
|
|
|
19
|
Medusa defines the following links between the Translation Module and other Commerce 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
|
[Product](/references/product/models/Product) in [Product Module](../../product/page.mdx) |
|
42
|
</Table.Cell> |
|
43
|
<Table.Cell> |
|
44
|
[Translation](/references/translation/models/Translation) |
|
45
|
</Table.Cell> |
|
46
|
<Table.Cell> |
|
47
|
Read-only - one-to-many |
|
48
|
</Table.Cell> |
|
49
|
<Table.Cell> |
|
50
|
[Learn more](#product-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
|
[Translation](/references/translation/models/Translation) |
|
59
|
</Table.Cell> |
|
60
|
<Table.Cell> |
|
61
|
Read-only - one-to-many |
|
62
|
</Table.Cell> |
|
63
|
<Table.Cell> |
|
64
|
[Learn more](#product-module) |
|
65
|
</Table.Cell> |
|
66
|
</Table.Row> |
|
67
|
<Table.Row> |
|
68
|
<Table.Cell> |
|
69
|
[ProductCategory](/references/product/models/ProductCategory) in [Product Module](../../product/page.mdx) |
|
70
|
</Table.Cell> |
|
71
|
<Table.Cell> |
|
72
|
[Translation](/references/translation/models/Translation) |
|
73
|
</Table.Cell> |
|
74
|
<Table.Cell> |
|
75
|
Read-only - one-to-many |
|
76
|
</Table.Cell> |
|
77
|
<Table.Cell> |
|
78
|
[Learn more](#product-module) |
|
79
|
</Table.Cell> |
|
80
|
</Table.Row> |
|
81
|
<Table.Row> |
|
82
|
<Table.Cell> |
|
83
|
[ProductCollection](/references/product/models/ProductCollection) in [Product Module](../../product/page.mdx) |
|
84
|
</Table.Cell> |
|
85
|
<Table.Cell> |
|
86
|
[Translation](/references/translation/models/Translation) |
|
87
|
</Table.Cell> |
|
88
|
<Table.Cell> |
|
89
|
Read-only - one-to-many |
|
90
|
</Table.Cell> |
|
91
|
<Table.Cell> |
|
92
|
[Learn more](#product-module) |
|
93
|
</Table.Cell> |
|
94
|
</Table.Row> |
|
95
|
<Table.Row> |
|
96
|
<Table.Cell> |
|
97
|
[ProductTag](/references/product/models/ProductTag) in [Product Module](../../product/page.mdx) |
|
98
|
</Table.Cell> |
|
99
|
<Table.Cell> |
|
100
|
[Translation](/references/translation/models/Translation) |
|
101
|
</Table.Cell> |
|
102
|
<Table.Cell> |
|
103
|
Read-only - one-to-many |
|
104
|
</Table.Cell> |
|
105
|
<Table.Cell> |
|
106
|
[Learn more](#product-module) |
|
107
|
</Table.Cell> |
|
108
|
</Table.Row> |
|
109
|
<Table.Row> |
|
110
|
<Table.Cell> |
|
111
|
[ProductType](/references/product/models/ProductType) in [Product Module](../../product/page.mdx) |
|
112
|
</Table.Cell> |
|
113
|
<Table.Cell> |
|
114
|
[Translation](/references/translation/models/Translation) |
|
115
|
</Table.Cell> |
|
116
|
<Table.Cell> |
|
117
|
Read-only - one-to-many |
|
118
|
</Table.Cell> |
|
119
|
<Table.Cell> |
|
120
|
[Learn more](#product-module) |
|
121
|
</Table.Cell> |
|
122
|
</Table.Row> |
|
123
|
<Table.Row> |
|
124
|
<Table.Cell> |
|
125
|
[ProductOption](/references/product/models/ProductOption) in [Product Module](../../product/page.mdx) |
|
126
|
</Table.Cell> |
|
127
|
<Table.Cell> |
|
128
|
[Translation](/references/translation/models/Translation) |
|
129
|
</Table.Cell> |
|
130
|
<Table.Cell> |
|
131
|
Read-only - one-to-many |
|
132
|
</Table.Cell> |
|
133
|
<Table.Cell> |
|
134
|
[Learn more](#product-module) |
|
135
|
</Table.Cell> |
|
136
|
</Table.Row> |
|
137
|
<Table.Row> |
|
138
|
<Table.Cell> |
|
139
|
[ProductOptionValue](/references/product/models/ProductOptionValue) in [Product Module](../../product/page.mdx) |
|
140
|
</Table.Cell> |
|
141
|
<Table.Cell> |
|
142
|
[Translation](/references/translation/models/Translation) |
|
143
|
</Table.Cell> |
|
144
|
<Table.Cell> |
|
145
|
Read-only - one-to-many |
|
146
|
</Table.Cell> |
|
147
|
<Table.Cell> |
|
148
|
[Learn more](#product-module) |
|
149
|
</Table.Cell> |
|
150
|
</Table.Row> |
|
151
|
<Table.Row> |
|
152
|
<Table.Cell> |
|
153
|
[StoreLocale](/references/store/models/StoreLocale) in [Store Module](../../store/page.mdx) |
|
154
|
</Table.Cell> |
|
155
|
<Table.Cell> |
|
156
|
[Locale](/references/translation/models/Locale) |
|
157
|
</Table.Cell> |
|
158
|
<Table.Cell> |
|
159
|
Read-only - has many |
|
160
|
</Table.Cell> |
|
161
|
<Table.Cell> |
|
162
|
[Learn more](#store-module) |
|
163
|
</Table.Cell> |
|
164
|
</Table.Row> |
|
165
|
</Table.Body> |
|
166
|
</Table> |
|
167
|
|
|
168
|
--- |
|
169
|
|
|
170
|
## Product Module |
|
171
|
|
|
172
|
Medusa defines the following read-only links between the Translation and Product Modules: |
|
173
|
|
|
174
|
<Table> |
|
175
|
<Table.Header> |
|
176
|
<Table.Row> |
|
177
|
<Table.HeaderCell> |
|
178
|
Data Model |
|
179
|
</Table.HeaderCell> |
|
180
|
<Table.HeaderCell> |
|
181
|
Link Type |
|
182
|
</Table.HeaderCell> |
|
183
|
<Table.HeaderCell> |
|
184
|
Description |
|
185
|
</Table.HeaderCell> |
|
186
|
</Table.Row> |
|
187
|
</Table.Header> |
|
188
|
<Table.Body> |
|
189
|
<Table.Row> |
|
190
|
<Table.Cell> |
|
191
|
[Product](/references/product/models/Product) \<-\> [Translation](/references/translation/models/Translation) |
|
192
|
</Table.Cell> |
|
193
|
<Table.Cell> |
|
194
|
One-to-many (bidirectional) |
|
195
|
</Table.Cell> |
|
196
|
<Table.Cell> |
|
197
|
Retrieve translations associated with a product and vice versa. |
|
198
|
</Table.Cell> |
|
199
|
</Table.Row> |
|
200
|
<Table.Row> |
|
201
|
<Table.Cell> |
|
202
|
[ProductVariant](/references/product/models/ProductVariant) -> [Translation](/references/translation/models/Translation) |
|
203
|
</Table.Cell> |
|
204
|
<Table.Cell> |
|
205
|
One-to-many (read-only) |
|
206
|
</Table.Cell> |
|
207
|
<Table.Cell> |
|
208
|
Retrieve translations of a product variant only. |
|
209
|
</Table.Cell> |
|
210
|
</Table.Row> |
|
211
|
<Table.Row> |
|
212
|
<Table.Cell> |
|
213
|
[ProductCategory](/references/product/models/ProductCategory) -> [Translation](/references/translation/models/Translation) |
|
214
|
</Table.Cell> |
|
215
|
<Table.Cell> |
|
216
|
One-to-many (read-only) |
|
217
|
</Table.Cell> |
|
218
|
<Table.Cell> |
|
219
|
Retrieve translations of a product category only. |
|
220
|
</Table.Cell> |
|
221
|
</Table.Row> |
|
222
|
<Table.Row> |
|
223
|
<Table.Cell> |
|
224
|
[ProductCollection](/references/product/models/ProductCollection) -> [Translation](/references/translation/models/Translation) |
|
225
|
</Table.Cell> |
|
226
|
<Table.Cell> |
|
227
|
One-to-many (read-only) |
|
228
|
</Table.Cell> |
|
229
|
<Table.Cell> |
|
230
|
Retrieve translations of a product collection only. |
|
231
|
</Table.Cell> |
|
232
|
</Table.Row> |
|
233
|
<Table.Row> |
|
234
|
<Table.Cell> |
|
235
|
[ProductTag](/references/product/models/ProductTag) -> [Translation](/references/translation/models/Translation) |
|
236
|
</Table.Cell> |
|
237
|
<Table.Cell> |
|
238
|
One-to-many (read-only) |
|
239
|
</Table.Cell> |
|
240
|
<Table.Cell> |
|
241
|
Retrieve translations of a product tag only. |
|
242
|
</Table.Cell> |
|
243
|
</Table.Row> |
|
244
|
<Table.Row> |
|
245
|
<Table.Cell> |
|
246
|
[ProductType](/references/product/models/ProductType) -> [Translation](/references/translation/models/Translation) |
|
247
|
</Table.Cell> |
|
248
|
<Table.Cell> |
|
249
|
One-to-many (read-only) |
|
250
|
</Table.Cell> |
|
251
|
<Table.Cell> |
|
252
|
Retrieve translations of a product type only. |
|
253
|
</Table.Cell> |
|
254
|
</Table.Row> |
|
255
|
<Table.Row> |
|
256
|
<Table.Cell> |
|
257
|
[ProductOption](/references/product/models/ProductOption) -> [Translation](/references/translation/models/Translation) |
|
258
|
</Table.Cell> |
|
259
|
<Table.Cell> |
|
260
|
One-to-many (read-only) |
|
261
|
</Table.Cell> |
|
262
|
<Table.Cell> |
|
263
|
Retrieve translations of a product option only. |
|
264
|
</Table.Cell> |
|
265
|
</Table.Row> |
|
266
|
<Table.Row> |
|
267
|
<Table.Cell> |
|
268
|
[ProductOptionValue](/references/product/models/ProductOptionValue) -> [Translation](/references/translation/models/Translation) |
|
269
|
</Table.Cell> |
|
270
|
<Table.Cell> |
|
271
|
One-to-many (read-only) |
|
272
|
</Table.Cell> |
|
273
|
<Table.Cell> |
|
274
|
Retrieve translations of a product option value only. |
|
275
|
</Table.Cell> |
|
276
|
</Table.Row> |
|
277
|
</Table.Body> |
|
278
|
</Table> |
|
279
|
|
|
280
|
### Retrieve with Query |
|
281
|
|
|
282
|
To retrieve the translations of a product with [Query](!docs!/learn/fundamentals/query), pass `translations.*` in `fields`: |
|
283
|
|
|
284
|
<Note> |
|
285
|
|
|
286
|
You can pass the `translations.*` field when querying any of the above-mentioned data models to retrieve their associated translations. |
|
287
|
|
|
288
|
</Note> |
|
289
|
|
|
290
|
<CodeTabs group="relation-query"> |
|
291
|
<CodeTab label="query.graph" value="method"> |
|
292
|
|
|
293
|
```ts |
|
294
|
const { data: products } = await query.graph({ |
|
295
|
entity: "product", |
|
296
|
fields: [ |
|
297
|
"translations.*", |
|
298
|
], |
|
299
|
}) |
|
300
|
|
|
301
|
// products[0].translations |
|
302
|
``` |
|
303
|
|
|
304
|
</CodeTab> |
|
305
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
306
|
|
|
307
|
```ts |
|
308
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
309
|
|
|
310
|
// ... |
|
311
|
|
|
312
|
const { data: products } = useQueryGraphStep({ |
|
313
|
entity: "product", |
|
314
|
fields: [ |
|
315
|
"translations.*", |
|
316
|
], |
|
317
|
}) |
|
318
|
|
|
319
|
// products[0].translations |
|
320
|
``` |
|
321
|
|
|
322
|
</CodeTab> |
|
323
|
</CodeTabs> |
|
324
|
|
|
325
|
--- |
|
326
|
|
|
327
|
## Store Module |
|
328
|
|
|
329
|
The [Store Module](../../store/page.mdx) has a `StoreLocale` data model that stores the supported locales of a store. However, these locales don't hold all the details of a locale, such as its name. |
|
330
|
|
|
331
|
Instead, Medusa defines a read-only link from the Store Module's `StoreLocale` data model to the Translation Module's `Locale` data model. This means you can retrieve the details of a store's supported locales, but you don't manage the links in a pivot table in the database. |
|
332
|
|
|
333
|
### Retrieve with Query |
|
334
|
|
|
335
|
To retrieve the details of a store's locales with [Query](!docs!/learn/fundamentals/query), pass `supported_locales.locale.*` in `fields`: |
|
336
|
|
|
337
|
<CodeTabs group="relation-query"> |
|
338
|
<CodeTab label="query.graph" value="method"> |
|
339
|
|
|
340
|
```ts |
|
341
|
const { data: stores } = await query.graph({ |
|
342
|
entity: "store", |
|
343
|
fields: [ |
|
344
|
"supported_locales.locale.*", |
|
345
|
], |
|
346
|
}) |
|
347
|
|
|
348
|
// stores[0].supported_locales[0].locale |
|
349
|
``` |
|
350
|
|
|
351
|
</CodeTab> |
|
352
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
353
|
|
|
354
|
```ts |
|
355
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
356
|
|
|
357
|
// ... |
|
358
|
|
|
359
|
const { data: stores } = useQueryGraphStep({ |
|
360
|
entity: "store", |
|
361
|
fields: [ |
|
362
|
"supported_locales.locale.*", |
|
363
|
], |
|
364
|
}) |
|
365
|
|
|
366
|
// stores[0].supported_locales[0].locale |
|
367
|
``` |
|
368
|
|
|
369
|
</CodeTab> |
|
370
|
</CodeTabs> |