www/apps/resources/app/commerce-modules/fulfillment/links-to-other-modules/page.mdx
import { CodeTabs, CodeTab, Table } from "docs-ui"
export const metadata = {
title: Links between Fulfillment Module and Other Modules,
}
This document showcases the module links defined between the Fulfillment Module and other Commerce Modules.
The Fulfillment Module has the following links to other modules:
<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> [ShippingMethod](/references/cart/models/ShippingMethod) in [Cart Module](../../cart/page.mdx) </Table.Cell> <Table.Cell> [ShippingOption](/references/fulfillment/models/ShippingOption) </Table.Cell> <Table.Cell> Read-only - has one </Table.Cell> <Table.Cell> [Learn more](#cart-module) </Table.Cell> </Table.Row> <Table.Row> <Table.Cell> [Order](/references/order/models/Order) in [Order Module](../../order/page.mdx) </Table.Cell> <Table.Cell> [Fulfillment](/references/fulfillment/models/Fulfillment) </Table.Cell> <Table.Cell> Stored - one-to-many </Table.Cell> <Table.Cell> [Learn more](#order-module) </Table.Cell> </Table.Row> <Table.Row> <Table.Cell> [Return](/references/order/models/Return) in [Order Module](../../order/page.mdx) </Table.Cell> <Table.Cell> [Fulfillment](/references/fulfillment/models/Fulfillment) </Table.Cell> <Table.Cell> Stored - one-to-many </Table.Cell> <Table.Cell> [Learn more](#order-module) </Table.Cell> </Table.Row> <Table.Row> <Table.Cell> [PriceSet](/references/pricing/models/PriceSet) in [Pricing Module](../../pricing/page.mdx) </Table.Cell> <Table.Cell> [ShippingOption](/references/fulfillment/models/ShippingOption) </Table.Cell> <Table.Cell> Stored - many-to-one </Table.Cell> <Table.Cell> [Learn more](#pricing-module) </Table.Cell> </Table.Row> <Table.Row> <Table.Cell> [Product](/references/product/models/Product) in [Product Module](../../product/page.mdx) </Table.Cell> <Table.Cell> [ShippingProfile](/references/fulfillment/models/ShippingProfile) </Table.Cell> <Table.Cell> Stored - many-to-one </Table.Cell> <Table.Cell> [Learn more](#product-module) </Table.Cell> </Table.Row> <Table.Row> <Table.Cell> [StockLocation](/references/stock-location-next/models/StockLocation) in [Stock Location Module](../../stock-location/page.mdx) </Table.Cell> <Table.Cell> [FulfillmentProvider](/references/fulfillment/models/FulfillmentProvider) </Table.Cell> <Table.Cell> Stored - one-to-many </Table.Cell> <Table.Cell> [Learn more](#stock-location-module) </Table.Cell> </Table.Row> <Table.Row> <Table.Cell> [StockLocation](/references/stock-location-next/models/StockLocation) in [Stock Location Module](../../stock-location/page.mdx) </Table.Cell> <Table.Cell> [FulfillmentSet](/references/fulfillment/models/FulfillmentSet) </Table.Cell> <Table.Cell> Stored - one-to-many </Table.Cell> <Table.Cell> [Learn more](#stock-location-module) </Table.Cell> </Table.Row> </Table.Body> </Table>Medusa defines a read-only link between the ShippingMethod data model of the Cart Module and the ShippingOption data model. This means you can retrieve the details of a shipping method's shipping option, but you don't manage the links in a pivot table in the database. The shipping option of a shipping method is determined by the shipping_option_id property of the ShippingMethod data model.
This link allows you to retrieve the shipping option that a shipping method was created from.
<Note>This read-only link was added in Medusa v2.10.0
</Note>To retrieve the shipping option of a shipping method with Query, pass shipping_option.* in fields:
const { data: shippingMethods } = await query.graph({
entity: "shipping_method",
fields: [
"shipping_option.*",
],
})
// shippingMethods[0].shipping_option
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: shippingMethods } = useQueryGraphStep({
entity: "shipping_method",
fields: [
"shipping_option.*",
],
})
// shippingMethods[0].shipping_option
The Order Module provides order-management functionalities.
Medusa defines a link between the Fulfillment and Order data models. A fulfillment is created for an orders' items.
A fulfillment is also created for a return's items. So, Medusa defines a link between the Fulfillment and Return data models.
To retrieve the order of a fulfillment with Query, pass order.* in fields:
To retrieve the return, pass return.* in fields.
const { data: fulfillments } = await query.graph({
entity: "fulfillment",
fields: [
"order.*",
],
})
// fulfillments.order
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: fulfillments } = useQueryGraphStep({
entity: "fulfillment",
fields: [
"order.*",
],
})
// fulfillments.order
To manage the order of a cart, use Link:
<CodeTabs group="relation-link"> <CodeTab label="link.create" value="method">import { Modules } from "@medusajs/framework/utils"
// ...
await link.create({
[Modules.ORDER]: {
order_id: "order_123",
},
[Modules.FULFILLMENT]: {
fulfillment_id: "ful_123",
},
})
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.ORDER]: {
order_id: "order_123",
},
[Modules.FULFILLMENT]: {
fulfillment_id: "ful_123",
},
})
The Pricing Module provides features to store, manage, and retrieve the best prices in a specified context.
Medusa defines a link between the PriceSet and ShippingOption data models. A shipping option's price is stored as a price set.
To retrieve the price set of a shipping option with Query, pass price_set.* in fields:
const { data: shippingOptions } = await query.graph({
entity: "shipping_option",
fields: [
"price_set_link.*",
],
})
// shippingOptions[0].price_set_link?.price_set_id
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: shippingOptions } = useQueryGraphStep({
entity: "shipping_option",
fields: [
"price_set_link.*",
],
})
// shippingOptions[0].price_set_link?.price_set_id
To manage the price set of a shipping option, use Link:
<CodeTabs group="relation-link"> <CodeTab label="link.create" value="method">import { Modules } from "@medusajs/framework/utils"
// ...
await link.create({
[Modules.FULFILLMENT]: {
shipping_option_id: "so_123",
},
[Modules.PRICING]: {
price_set_id: "pset_123",
},
})
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.FULFILLMENT]: {
shipping_option_id: "so_123",
},
[Modules.PRICING]: {
price_set_id: "pset_123",
},
})
Medusa defines a link between the ShippingProfile data model and the Product data model of the Product Module. Each product must belong to a shipping profile.
This link is introduced in Medusa v2.5.0.
</Note>To retrieve the products of a shipping profile with Query, pass products.* in fields:
const { data: shippingProfiles } = await query.graph({
entity: "shipping_profile",
fields: [
"products.*",
],
})
// shippingProfiles[0].products
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: shippingProfiles } = useQueryGraphStep({
entity: "shipping_profile",
fields: [
"products.*",
],
})
// shippingProfiles[0].products
To manage the shipping profile of a product, use Link:
<CodeTabs group="relation-link"> <CodeTab label="link.create" value="method">import { Modules } from "@medusajs/framework/utils"
// ...
await link.create({
[Modules.PRODUCT]: {
product_id: "prod_123",
},
[Modules.FULFILLMENT]: {
shipping_profile_id: "sp_123",
},
})
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.PRODUCT]: {
product_id: "prod_123",
},
[Modules.FULFILLMENT]: {
shipping_profile_id: "sp_123",
},
})
The Stock Location Module provides features to manage stock locations in a store.
Medusa defines a link between the FulfillmentSet and StockLocation data models. A fulfillment set can be conditioned to a specific stock location.
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 stock location of a fulfillment set with Query, pass location.* in fields:
To retrieve the stock location of a fulfillment provider, pass locations.* in fields.
const { data: fulfillmentSets } = await query.graph({
entity: "fulfillment_set",
fields: [
"location.*",
],
})
// fulfillmentSets[0].location
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: fulfillmentSets } = useQueryGraphStep({
entity: "fulfillment_set",
fields: [
"location.*",
],
})
// fulfillmentSets[0].location
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",
},
})