www/apps/resources/app/commerce-modules/stock-location/links-to-other-modules/page.mdx
import { CodeTabs, CodeTab, Table } from "docs-ui"
export const metadata = {
title: Links between Stock Location Module and Other Modules,
}
This document showcases the module links defined between the Stock Location Module and other Commerce Modules.
The Stock Location Module has the following links to other modules:
<Note title="Tip">Read-only links are used to query data across modules, but the relations aren't stored in a pivot table in the database.
</Note> <Table> <Table.Header> <Table.Row> <Table.HeaderCell> First Data Model </Table.HeaderCell> <Table.HeaderCell> Second Data Model </Table.HeaderCell> <Table.HeaderCell> Type </Table.HeaderCell> <Table.HeaderCell> Description </Table.HeaderCell> </Table.Row> </Table.Header> <Table.Body> <Table.Row> <Table.Cell> [FulfillmentSet](/references/fulfillment/models/FulfillmentSet) in [Fulfillment Module](../../fulfillment/page.mdx) </Table.Cell> <Table.Cell> [StockLocation](/references/stock-location-next/models/StockLocation) </Table.Cell> <Table.Cell> Stored - many-to-one </Table.Cell> <Table.Cell> [Learn more](#fulfillment-module) </Table.Cell> </Table.Row> <Table.Row> <Table.Cell> [FulfillmentProvider](/references/fulfillment/models/FulfillmentProvider) in [Fulfillment Module](../../fulfillment/page.mdx) </Table.Cell> <Table.Cell> [StockLocation](/references/stock-location-next/models/StockLocation) </Table.Cell> <Table.Cell> Stored - many-to-many </Table.Cell> <Table.Cell> [Learn more](#fulfillment-module) </Table.Cell> </Table.Row> <Table.Row> <Table.Cell> [InventoryLevel](/references/inventory-next/models/InventoryLevel) in [Inventory Module](../../inventory/page.mdx) </Table.Cell> <Table.Cell> [StockLocation](/references/stock-location-next/models/StockLocation) </Table.Cell> <Table.Cell> Read-only - has many </Table.Cell> <Table.Cell> [Learn more](#inventory-module) </Table.Cell> </Table.Row> <Table.Row> <Table.Cell> [SalesChannel](/references/sales-channel/models/SalesChannel) in [Sales Channel Module](../../sales-channel/page.mdx) </Table.Cell> <Table.Cell> [StockLocation](/references/stock-location-next/models/StockLocation) </Table.Cell> <Table.Cell> Stored - many-to-many </Table.Cell> <Table.Cell> [Learn more](#sales-channel-module) </Table.Cell> </Table.Row> </Table.Body> </Table>A fulfillment set can be conditioned to a specific stock location.
Medusa defines a link between the FulfillmentSet and StockLocation data models.
Medusa also defines a link between the FulfillmentProvider and StockLocation data models to indicate the providers that can be used in a location.
To retrieve the fulfillment sets of a stock location with Query, pass fulfillment_sets.* in fields:
To retrieve the fulfillment providers, pass fulfillment_providers.* in fields.
const { data: stockLocations } = await query.graph({
entity: "stock_location",
fields: [
"fulfillment_sets.*",
],
})
// stockLocations[0].fulfillment_sets
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: stockLocations } = useQueryGraphStep({
entity: "stock_location",
fields: [
"fulfillment_sets.*",
],
})
// stockLocations[0].fulfillment_sets
To manage the stock location of a fulfillment set, use Link:
<CodeTabs group="relation-link"> <CodeTab label="link.create" value="method">import { Modules } from "@medusajs/framework/utils"
// ...
await link.create({
[Modules.STOCK_LOCATION]: {
stock_location_id: "sloc_123",
},
[Modules.FULFILLMENT]: {
fulfillment_set_id: "fset_123",
},
})
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.STOCK_LOCATION]: {
stock_location_id: "sloc_123",
},
[Modules.FULFILLMENT]: {
fulfillment_set_id: "fset_123",
},
})
Medusa defines a read-only link between the Inventory Module'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.
To retrieve the stock locations of an inventory level with Query, pass stock_locations.* in fields:
const { data: inventoryLevels } = await query.graph({
entity: "inventory_level",
fields: [
"stock_locations.*",
],
})
// inventoryLevels[0].stock_locations
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: inventoryLevels } = useQueryGraphStep({
entity: "inventory_level",
fields: [
"stock_locations.*",
],
})
// inventoryLevels[0].stock_locations
A stock location is associated with a sales channel. This scopes inventory quantities in a stock location by the associated sales channel.
Medusa defines a link between the SalesChannel and StockLocation data models.
To retrieve the sales channels of a stock location with Query, pass sales_channels.* in fields:
const { data: stockLocations } = await query.graph({
entity: "stock_location",
fields: [
"sales_channels.*",
],
})
// stockLocations[0].sales_channels
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: stockLocations } = useQueryGraphStep({
entity: "stock_location",
fields: [
"sales_channels.*",
],
})
// stockLocations[0].sales_channels
To manage the stock locations of a sales channel, use Link:
<CodeTabs group="relation-link"> <CodeTab label="link.create" value="method">import { Modules } from "@medusajs/framework/utils"
// ...
await link.create({
[Modules.SALES_CHANNEL]: {
sales_channel_id: "sc_123",
},
[Modules.STOCK_LOCATION]: {
sales_channel_id: "sloc_123",
},
})
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.SALES_CHANNEL]: {
sales_channel_id: "sc_123",
},
[Modules.STOCK_LOCATION]: {
sales_channel_id: "sloc_123",
},
})