docs: add documentation for product <> shipping profile link (#11397)

This commit is contained in:
Shahed Nasser
2025-02-11 14:46:03 +02:00
committed by GitHub
parent 1bf8766826
commit 7ba178e2d6
4 changed files with 8265 additions and 7682 deletions
@@ -15,6 +15,7 @@ The Fulfillment Module has the following links to other modules:
- [`Order` data model of the Order Module \<\> `Fulfillment` data model](#order-module).
- [`Return` data model of the Order Module \<\> `Fulfillment` data model](#order-module).
- [`PriceSet` data model of the Pricing Module \<\> `ShippingOption` data model](#pricing-module).
- [`Product` data model of the Product Module \<\> `ShippingProfile` data model](#product-module).
- [`StockLocation` data model of the Stock Location Module \<\> `FulfillmentProvider` data model](#stock-location-module).
- [`StockLocation` data model of the Stock Location Module \<\> `FulfillmentSet` data model](#stock-location-module).
@@ -216,6 +217,101 @@ createRemoteLinkStep({
---
## Product Module
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.
<Note>
This link is introduced in [Medusa v2.5.0](https://github.com/medusajs/medusa/releases/tag/v2.5.0).
</Note>
### Retrieve with Query
To retrieve the products of a shipping profile with [Query](!docs!/learn/fundamentals/module-links/query), pass `products.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: shippingProfiles } = await query.graph({
entity: "shipping_profile",
fields: [
"products.*",
],
})
// shippingProfiles.products
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: shippingProfiles } = useQueryGraphStep({
entity: "shipping_profile",
fields: [
"products.*",
],
})
// shippingProfiles.products
```
</CodeTab>
</CodeTabs>
### Manage with Link
To manage the shipping profile of a product, use [Link](!docs!/learn/fundamentals/module-links/link):
<CodeTabs group="relation-link">
<CodeTab label="link.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await link.create({
[Modules.PRODUCT]: {
product_id: "prod_123",
},
[Modules.FULFILLMENT]: {
shipping_profile_id: "sp_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
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",
},
})
```
</CodeTab>
</CodeTabs>
---
## Stock Location Module
The Stock Location Module provides features to manage stock locations in a store.
@@ -19,6 +19,7 @@ Read-only links are used to query data across modules, but the relations aren't
</Note>
- [`Product` data model \<\> `Cart` data model of Cart Module](#cart-module). (Read-only).
- [`Product` data model \<\> `ShippingProfile` data model of Fulfillment Module](#fulfillment-module).
- [`ProductVariant` data model \<\> `InventoryItem` data model of Inventory Module](#inventory-module).
- [`Product` data model \<\> `Order` data model of Order Module](#order-module). (Read-only).
- [`ProductVariant` data model \<\> `PriceSet` data model of Pricing Module](#pricing-module).
@@ -80,6 +81,101 @@ const { data: variants } = useQueryGraphStep({
---
## Fulfillment Module
Medusa defines a link between the `Product` data model and the `ShippingProfile` data model of the Fulfillment Module. Each product must belong to a shipping profile.
<Note>
This link is introduced in [Medusa v2.5.0](https://github.com/medusajs/medusa/releases/tag/v2.5.0).
</Note>
### Retrieve with Query
To retrieve the shipping profile of a product with [Query](!docs!/learn/fundamentals/module-links/query), pass `shipping_profile.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: products } = await query.graph({
entity: "product",
fields: [
"shipping_profile.*",
],
})
// products.shipping_profile
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: products } = useQueryGraphStep({
entity: "product",
fields: [
"shipping_profile.*",
],
})
// products.shipping_profile
```
</CodeTab>
</CodeTabs>
### Manage with Link
To manage the shipping profile of a product, use [Link](!docs!/learn/fundamentals/module-links/link):
<CodeTabs group="relation-link">
<CodeTab label="link.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await link.create({
[Modules.PRODUCT]: {
product_id: "prod_123",
},
[Modules.FULFILLMENT]: {
shipping_profile_id: "sp_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
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",
},
})
```
</CodeTab>
</CodeTabs>
---
## Inventory Module
The Inventory Module provides inventory-management features for any stock-kept item.