Links between Stock Location Module and Other Modules

This document showcases the module links defined between the Stock Location Module and other commerce modules.

Summary#

The Stock Location Module has the following links to other modules:

TipRead-only links are used to query data across modules, but the relations aren't stored in a pivot table in the database.

Fulfillment Module#

A fulfillment set can be conditioned to a specific stock location.

Medusa defines a link between the FulfillmentSet and StockLocation data models.

A diagram showcasing an example of how data models from the Fulfillment and Stock Location modules are linked

Medusa also defines a link between the FulfillmentProvider and StockLocation data models to indicate the providers that can be used in a location.

A diagram showcasing an example of how data models from the Fulfillment and Stock Location modules are linked

Retrieve with Query#

To retrieve the fulfillment sets of a stock location with Query, pass fulfillment_sets.* in fields:

NoteTo retrieve the fulfillment providers, pass fulfillment_providers.* in fields.
1const { data: stockLocations } = await query.graph({2  entity: "stock_location",3  fields: [4    "fulfillment_sets.*",5  ],6})7
8// stockLocations.fulfillment_sets

To manage the stock location of a fulfillment set, use Link:

1import { Modules } from "@medusajs/framework/utils"2
3// ...4
5await link.create({6  [Modules.STOCK_LOCATION]: {7    stock_location_id: "sloc_123",8  },9  [Modules.FULFILLMENT]: {10    fulfillment_set_id: "fset_123",11  },12})

Inventory Module#

Medusa defines a read-only link between the StockLocation data model and the Inventory Module's InventoryLevel data model. This means you can retrieve the details of a stock location's inventory levels, but you don't manage the links in a pivot table in the database. The stock location of an inventory level is determined by the location_id property of the InventoryLevel data model.

Retrieve with Query#

To retrieve the inventory levels of a stock location with Query, pass inventory_levels.* in fields:

1const { data: stockLocations } = await query.graph({2  entity: "stock_location",3  fields: [4    "inventory_levels.*",5  ],6})7
8// stockLocations.inventory_levels

Sales Channel Module#

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.

A diagram showcasing an example of how resources from the Sales Channel and Stock Location modules are linked

Retrieve with Query#

To retrieve the sales channels of a stock location with Query, pass sales_channels.* in fields:

1const { data: stockLocations } = await query.graph({2  entity: "stock_location",3  fields: [4    "sales_channels.*",5  ],6})7
8// stockLocations.sales_channels

To manage the stock locations of a sales channel, use Link:

1import { Modules } from "@medusajs/framework/utils"2
3// ...4
5await link.create({6  [Modules.SALES_CHANNEL]: {7    sales_channel_id: "sc_123",8  },9  [Modules.STOCK_LOCATION]: {10    sales_channel_id: "sloc_123",11  },12})
Was this page helpful?
Edit this page
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break