|
1
|
--- |
|
2
|
products: |
|
3
|
- fulfillment |
|
4
|
- inventory |
|
5
|
- sales channel |
|
6
|
--- |
|
7
|
|
|
8
|
import { CodeTabs, CodeTab, Table } from "docs-ui" |
|
9
|
|
|
10
|
export const metadata = { |
|
11
|
title: `Links between Stock Location Module and Other Modules`, |
|
12
|
} |
|
13
|
|
|
14
|
# {metadata.title} |
|
15
|
|
|
16
|
This document showcases the module links defined between the Stock Location Module and other Commerce Modules. |
|
17
|
|
|
18
|
## Summary |
|
19
|
|
|
20
|
The Stock Location 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
|
[FulfillmentSet](/references/fulfillment/models/FulfillmentSet) in [Fulfillment Module](../../fulfillment/page.mdx) |
|
49
|
</Table.Cell> |
|
50
|
<Table.Cell> |
|
51
|
[StockLocation](/references/stock-location-next/models/StockLocation) |
|
52
|
</Table.Cell> |
|
53
|
<Table.Cell> |
|
54
|
Stored - many-to-one |
|
55
|
</Table.Cell> |
|
56
|
<Table.Cell> |
|
57
|
[Learn more](#fulfillment-module) |
|
58
|
</Table.Cell> |
|
59
|
</Table.Row> |
|
60
|
<Table.Row> |
|
61
|
<Table.Cell> |
|
62
|
[FulfillmentProvider](/references/fulfillment/models/FulfillmentProvider) in [Fulfillment Module](../../fulfillment/page.mdx) |
|
63
|
</Table.Cell> |
|
64
|
<Table.Cell> |
|
65
|
[StockLocation](/references/stock-location-next/models/StockLocation) |
|
66
|
</Table.Cell> |
|
67
|
<Table.Cell> |
|
68
|
Stored - many-to-many |
|
69
|
</Table.Cell> |
|
70
|
<Table.Cell> |
|
71
|
[Learn more](#fulfillment-module) |
|
72
|
</Table.Cell> |
|
73
|
</Table.Row> |
|
74
|
<Table.Row> |
|
75
|
<Table.Cell> |
|
76
|
[InventoryLevel](/references/inventory-next/models/InventoryLevel) in [Inventory Module](../../inventory/page.mdx) |
|
77
|
</Table.Cell> |
|
78
|
<Table.Cell> |
|
79
|
[StockLocation](/references/stock-location-next/models/StockLocation) |
|
80
|
</Table.Cell> |
|
81
|
<Table.Cell> |
|
82
|
Read-only - has many |
|
83
|
</Table.Cell> |
|
84
|
<Table.Cell> |
|
85
|
[Learn more](#inventory-module) |
|
86
|
</Table.Cell> |
|
87
|
</Table.Row> |
|
88
|
<Table.Row> |
|
89
|
<Table.Cell> |
|
90
|
[SalesChannel](/references/sales-channel/models/SalesChannel) in [Sales Channel Module](../../sales-channel/page.mdx) |
|
91
|
</Table.Cell> |
|
92
|
<Table.Cell> |
|
93
|
[StockLocation](/references/stock-location-next/models/StockLocation) |
|
94
|
</Table.Cell> |
|
95
|
<Table.Cell> |
|
96
|
Stored - many-to-many |
|
97
|
</Table.Cell> |
|
98
|
<Table.Cell> |
|
99
|
[Learn more](#sales-channel-module) |
|
100
|
</Table.Cell> |
|
101
|
</Table.Row> |
|
102
|
</Table.Body> |
|
103
|
</Table> |
|
104
|
|
|
105
|
--- |
|
106
|
|
|
107
|
## Fulfillment Module |
|
108
|
|
|
109
|
A fulfillment set can be conditioned to a specific stock location. |
|
110
|
|
|
111
|
Medusa defines a link between the `FulfillmentSet` and `StockLocation` data models. |
|
112
|
|
|
113
|
 |
|
114
|
|
|
115
|
Medusa also defines a link between the `FulfillmentProvider` and `StockLocation` data models to indicate the providers that can be used in a location. |
|
116
|
|
|
117
|
 |
|
118
|
|
|
119
|
### Retrieve with Query |
|
120
|
|
|
121
|
To retrieve the fulfillment sets of a stock location with [Query](!docs!/learn/fundamentals/query), pass `fulfillment_sets.*` in `fields`: |
|
122
|
|
|
123
|
<Note> |
|
124
|
|
|
125
|
To retrieve the fulfillment providers, pass `fulfillment_providers.*` in `fields`. |
|
126
|
|
|
127
|
</Note> |
|
128
|
|
|
129
|
<CodeTabs group="relation-query"> |
|
130
|
<CodeTab label="query.graph" value="method"> |
|
131
|
|
|
132
|
```ts |
|
133
|
const { data: stockLocations } = await query.graph({ |
|
134
|
entity: "stock_location", |
|
135
|
fields: [ |
|
136
|
"fulfillment_sets.*", |
|
137
|
], |
|
138
|
}) |
|
139
|
|
|
140
|
// stockLocations[0].fulfillment_sets |
|
141
|
``` |
|
142
|
|
|
143
|
</CodeTab> |
|
144
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
145
|
|
|
146
|
```ts |
|
147
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
148
|
|
|
149
|
// ... |
|
150
|
|
|
151
|
const { data: stockLocations } = useQueryGraphStep({ |
|
152
|
entity: "stock_location", |
|
153
|
fields: [ |
|
154
|
"fulfillment_sets.*", |
|
155
|
], |
|
156
|
}) |
|
157
|
|
|
158
|
// stockLocations[0].fulfillment_sets |
|
159
|
``` |
|
160
|
|
|
161
|
</CodeTab> |
|
162
|
</CodeTabs> |
|
163
|
|
|
164
|
### Manage with Link |
|
165
|
|
|
166
|
To manage the stock location of a fulfillment set, use [Link](!docs!/learn/fundamentals/module-links/link): |
|
167
|
|
|
168
|
<CodeTabs group="relation-link"> |
|
169
|
<CodeTab label="link.create" value="method"> |
|
170
|
|
|
171
|
```ts |
|
172
|
import { Modules } from "@medusajs/framework/utils" |
|
173
|
|
|
174
|
// ... |
|
175
|
|
|
176
|
await link.create({ |
|
177
|
[Modules.STOCK_LOCATION]: { |
|
178
|
stock_location_id: "sloc_123", |
|
179
|
}, |
|
180
|
[Modules.FULFILLMENT]: { |
|
181
|
fulfillment_set_id: "fset_123", |
|
182
|
}, |
|
183
|
}) |
|
184
|
``` |
|
185
|
|
|
186
|
</CodeTab> |
|
187
|
<CodeTab label="createRemoteLinkStep" value="step"> |
|
188
|
|
|
189
|
```ts |
|
190
|
import { Modules } from "@medusajs/framework/utils" |
|
191
|
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows" |
|
192
|
|
|
193
|
// ... |
|
194
|
|
|
195
|
createRemoteLinkStep({ |
|
196
|
[Modules.STOCK_LOCATION]: { |
|
197
|
stock_location_id: "sloc_123", |
|
198
|
}, |
|
199
|
[Modules.FULFILLMENT]: { |
|
200
|
fulfillment_set_id: "fset_123", |
|
201
|
}, |
|
202
|
}) |
|
203
|
``` |
|
204
|
|
|
205
|
</CodeTab> |
|
206
|
</CodeTabs> |
|
207
|
|
|
208
|
--- |
|
209
|
|
|
210
|
## Inventory Module |
|
211
|
|
|
212
|
Medusa defines a read-only link between the [Inventory Module](../../inventory/page.mdx)'s `InventoryLevel` data model and the `StockLocation` data model. Because the link is read-only from the `InventoryLevel`'s side, you can only retrieve the stock location of an inventory level, and not the other way around. |
|
213
|
|
|
214
|
### Retrieve with Query |
|
215
|
|
|
216
|
To retrieve the stock locations of an inventory level with [Query](!docs!/learn/fundamentals/query), pass `stock_locations.*` in `fields`: |
|
217
|
|
|
218
|
<CodeTabs group="relation-query"> |
|
219
|
<CodeTab label="query.graph" value="method"> |
|
220
|
|
|
221
|
```ts |
|
222
|
const { data: inventoryLevels } = await query.graph({ |
|
223
|
entity: "inventory_level", |
|
224
|
fields: [ |
|
225
|
"stock_locations.*", |
|
226
|
], |
|
227
|
}) |
|
228
|
|
|
229
|
// inventoryLevels[0].stock_locations |
|
230
|
``` |
|
231
|
|
|
232
|
</CodeTab> |
|
233
|
<CodeTab label="useQueryGraphStep" value="step"> |
|
234
|
|
|
235
|
```ts |
|
236
|
import { useQueryGraphStep } from "@medusajs/medusa/core-flows" |
|
237
|
|
|
238
|
// ... |
|
239
|
|
|
240
|
const { data: inventoryLevels } = useQueryGraphStep({ |
|
241
|
entity: "inventory_level", |
|
242
|
fields: [ |
|
243
|
"stock_locations.*", |
|
244
|
], |
|
245
|
}) |
|
246
|
|
|
247
|
// inventoryLevels[0].stock_locations |
|
248
|
``` |
|
249
|
|
|
250
|
</CodeTab> |
|
251
|
</CodeTabs> |
|
252
|
|
|
253
|
--- |
|
254
|
|
|
255
|
## Sales Channel Module |
|
256
|
|
|
257
|
A stock location is associated with a sales channel. This scopes inventory quantities in a stock location by the associated sales channel. |
|
258
|
|
|
259
|
Medusa defines a link between the `SalesChannel` and `StockLocation` data models. |
|
260
|
|
|
261
|
 |
|
262
|
|
|
263
|
### Retrieve with Query |
|
264
|
|
|
265
|
To retrieve the sales channels of a stock location with [Query](!docs!/learn/fundamentals/query), pass `sales_channels.*` in `fields`: |
|
266
|
|
|
267
|
<CodeTabs group="relation-query"> |
|
268
|
<CodeTab label="query.graph" value="method"> |
|
269
|
|
|
270
|
```ts |
|
271
|
const { data: stockLocations } = await query.graph({ |
|
272
|
entity: "stock_location", |
|
273
|
fields: [ |
|
274
|
"sales_channels.*", |
|
275
|
], |
|
276
|
}) |
|
277
|
|
|
278
|
// stockLocations[0].sales_channels |
|
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: stockLocations } = useQueryGraphStep({ |
|
290
|
entity: "stock_location", |
|
291
|
fields: [ |
|
292
|
"sales_channels.*", |
|
293
|
], |
|
294
|
}) |
|
295
|
|
|
296
|
// stockLocations[0].sales_channels |
|
297
|
``` |
|
298
|
|
|
299
|
</CodeTab> |
|
300
|
</CodeTabs> |
|
301
|
|
|
302
|
### Manage with Link |
|
303
|
|
|
304
|
To manage the stock locations of a sales channel, use [Link](!docs!/learn/fundamentals/module-links/link): |
|
305
|
|
|
306
|
<CodeTabs group="relation-link"> |
|
307
|
<CodeTab label="link.create" value="method"> |
|
308
|
|
|
309
|
```ts |
|
310
|
import { Modules } from "@medusajs/framework/utils" |
|
311
|
|
|
312
|
// ... |
|
313
|
|
|
314
|
await link.create({ |
|
315
|
[Modules.SALES_CHANNEL]: { |
|
316
|
sales_channel_id: "sc_123", |
|
317
|
}, |
|
318
|
[Modules.STOCK_LOCATION]: { |
|
319
|
sales_channel_id: "sloc_123", |
|
320
|
}, |
|
321
|
}) |
|
322
|
``` |
|
323
|
|
|
324
|
</CodeTab> |
|
325
|
<CodeTab label="createRemoteLinkStep" value="step"> |
|
326
|
|
|
327
|
```ts |
|
328
|
import { Modules } from "@medusajs/framework/utils" |
|
329
|
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows" |
|
330
|
|
|
331
|
// ... |
|
332
|
|
|
333
|
createRemoteLinkStep({ |
|
334
|
[Modules.SALES_CHANNEL]: { |
|
335
|
sales_channel_id: "sc_123", |
|
336
|
}, |
|
337
|
[Modules.STOCK_LOCATION]: { |
|
338
|
sales_channel_id: "sloc_123", |
|
339
|
}, |
|
340
|
}) |
|
341
|
``` |
|
342
|
|
|
343
|
</CodeTab> |
|
344
|
</CodeTabs> |