docs: improve link docs for commerce modules (#10726)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-12-24 17:19:39 +02:00
1 parent 83925f5c7a
commit 8441d2ab9d
21 files changed
+3692 -36

No files matched your search

@@ -1,3 +1,5 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = { export const metadata = {
title: `Links between API Key Module and Other Modules`, title: `Links between API Key Module and Other Modules`,
} }
@@ -6,6 +8,14 @@ export const metadata = {
This document showcases the module links defined between the API Key Module and other commerce modules. This document showcases the module links defined between the API Key Module and other commerce modules.
## Summary
The API Key Module has the following links to other modules:
- [`ApiKey` data model \<\> `SalesChannel` data model of Sales Channel Module](#sales-channel-module).
---
## Sales Channel Module ## Sales Channel Module
You can create a publishable API key and associate it with a sales channel. Medusa defines a link between the `ApiKey` and the `SalesChannel` data models. You can create a publishable API key and associate it with a sales channel. Medusa defines a link between the `ApiKey` and the `SalesChannel` data models.
@@ -15,3 +25,86 @@ You can create a publishable API key and associate it with a sales channel. Medu
This is useful to avoid passing the sales channel's ID as a parameter of every request, and instead pass the publishable API key in the header of any request to the Store API route. This is useful to avoid passing the sales channel's ID as a parameter of every request, and instead pass the publishable API key in the header of any request to the Store API route.
Learn more about this in the [Sales Channel Module's documentation](../../sales-channel/publishable-api-keys/page.mdx). Learn more about this in the [Sales Channel Module's documentation](../../sales-channel/publishable-api-keys/page.mdx).
### Retrieve with Query
To retrieve the sales channels of an API key with [Query](!docs!/learn/fundamentals/module-links/query), pass `sales_channels.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: apiKeys } = await query.graph({
entity: "api_key",
fields: [
"sales_channels.*"
]
})
// apiKeys.sales_channels
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: apiKeys } = useQueryGraphStep({
entity: "api_key",
fields: [
"sales_channels.*"
]
})
// apiKeys.sales_channels
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the sales channels of an API key, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.API_KEY]: {
api_key_id: "apk_123",
},
[Modules.SALES_CHANNEL]: {
sales_channel_id: "sc_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.API_KEY]: {
api_key_id: "apk_123",
},
[Modules.SALES_CHANNEL]: {
sales_channel_id: "sc_123",
},
})
```
</CodeTab>
</CodeTabs>
@@ -1,3 +1,5 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = { export const metadata = {
title: `Links between Cart Module and Other Modules`, title: `Links between Cart Module and Other Modules`,
} }
@@ -6,30 +8,496 @@ export const metadata = {
This document showcases the module links defined between the Cart Module and other commerce modules. This document showcases the module links defined between the Cart Module and other commerce modules.
## Payment Module ## Summary
The Payment Module handles payment processing and management. The Cart Module has the following links to other modules:
Medusa defines a link between the `Cart` and `PaymentCollection` data models. A cart has a payment collection which holds all the authorized payment sessions and payments made related to the cart. <Note title="Tip">
![A diagram showcasing an example of how data models from the Cart and Payment modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1711537849/Medusa%20Resources/cart-payment_ixziqm.jpg) Read-only links are used to query data across modules, but the relations aren't stored in a pivot table in the database.
</Note>
- [`Cart` data model \<\> `Customer` data model of Customer Module](#customer-module). (Read-only).
- [`Order` data model of Order Module \<\> `Cart` data model](#order-module).
- [`Cart` data model \<\> `PaymentCollection` data model of Payment Module](#payment-module).
- [`LineItem` data model \<\> `Product` data model of Product Module](#product-module). (Read-only).
- [`LineItem` data model \<\> `ProductVariant` data model of Product Module](#product-module). (Read-only).
- [`Cart` data model \<\> `Promotion` data model of Promotion Module](#promotion-module).
- [`Cart` data model \<\> `Region` data model of Region Module](#region-module). (Read-only).
- [`Cart` data model \<\> `SalesChannel` data model of Sales Channel Module](#sales-channel-module). (Read-only).
--- ---
## Promotion Module ## Customer Module
The Promotion Module provides discount features. Medusa defines a read-only link between the `Cart` data model and the [Customer Module](../../customer/page.mdx)'s `Customer` data model. This means you can retrieve the details of a cart's customer, but you don't manage the links in a pivot table in the database. The customer of a cart is determined by the `customer_id` property of the `Cart` data model.
Medusa defines a link between the `Cart` and `Promotion` data models. This indicates the promotions applied on a cart. ### Retrieve with Query
![A diagram showcasing an example of how data models from the Cart and Promotion modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1711538015/Medusa%20Resources/cart-promotion_kuh9vm.jpg) To retrieve the customer of a cart with [Query](!docs!/learn/fundamentals/module-links/query), pass `customer.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: carts } = await query.graph({
entity: "cart",
fields: [
"customer.*"
]
})
// carts.order
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: carts } = useQueryGraphStep({
entity: "cart",
fields: [
"customer.*"
]
})
// carts.order
```
</CodeTab>
</CodeTabs>
--- ---
## Order Module ## Order Module
The Order Module provides order-management features. The [Order Module](../../order/page.mdx) provides order-management features.
Medusa defines a link between the `Cart` and `Order` data models. The cart is linked to the order created once the cart is completed. Medusa defines a link between the `Cart` and `Order` data models. The cart is linked to the order created once the cart is completed.
![A diagram showcasing an example of how data models from the Cart and Order modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1728375735/Medusa%20Resources/cart-order_ijwmfs.jpg) ![A diagram showcasing an example of how data models from the Cart and Order modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1728375735/Medusa%20Resources/cart-order_ijwmfs.jpg)
### Retrieve with Query
To retrieve the order of a cart with [Query](!docs!/learn/fundamentals/module-links/query), pass `order.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: carts } = await query.graph({
entity: "cart",
fields: [
"order.*"
]
})
// carts.order
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: carts } = useQueryGraphStep({
entity: "cart",
fields: [
"order.*"
]
})
// carts.order
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the order of a cart, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.CART]: {
cart_id: "cart_123",
},
[Modules.ORDER]: {
order_id: "order_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.CART]: {
cart_id: "cart_123",
},
[Modules.ORDER]: {
order_id: "order_123",
},
})
```
</CodeTab>
</CodeTabs>
---
## Payment Module
The [Payment Module](../../payment/page.mdx) handles payment processing and management.
Medusa defines a link between the `Cart` and `PaymentCollection` data models. A cart has a payment collection which holds all the authorized payment sessions and payments made related to the cart.
![A diagram showcasing an example of how data models from the Cart and Payment modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1711537849/Medusa%20Resources/cart-payment_ixziqm.jpg)
### Retrieve with Query
To retrieve the payment collection of a cart with [Query](!docs!/learn/fundamentals/module-links/query), pass `payment_collection.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: carts } = await query.graph({
entity: "cart",
fields: [
"payment_collection.*"
]
})
// carts.payment_collection
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: carts } = useQueryGraphStep({
entity: "cart",
fields: [
"payment_collection.*"
]
})
// carts.payment_collection
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the payment collection of a cart, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.CART]: {
cart_id: "cart_123",
},
[Modules.PAYMENT]: {
payment_collection_id: "paycol_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.CART]: {
cart_id: "cart_123",
},
[Modules.PAYMENT]: {
payment_collection_id: "paycol_123",
},
})
```
</CodeTab>
</CodeTabs>
---
## Product Module
Medusa defines read-only links between:
- the `LineItem` data model and the [Product Module](../../product/page.mdx)'s `Product` data model. This means you can retrieve the details of a line item's product, but you don't manage the links in a pivot table in the database. The product of a line item is determined by the `product_id` property of the `LineItem` data model.
- the `LineItem` data model and the [Product Module](../../product/page.mdx)'s `ProductVariant` data model. This means you can retrieve the details of a line item's variant, but you don't manage the links in a pivot table in the database. The variant of a line item is determined by the `variant_id` property of the `LineItem` data model.
### Retrieve with Query
To retrieve the variant of a line item with [Query](!docs!/learn/fundamentals/module-links/query), pass `variant.*` in `fields`:
<Note>
To retrieve the product, pass `product.*` in `fields`.
</Note>
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: lineItems } = await query.graph({
entity: "line_item",
fields: [
"variant.*"
]
})
// lineItems.variant
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: lineItems } = useQueryGraphStep({
entity: "line_item",
fields: [
"variant.*"
]
})
// lineItems.variant
```
</CodeTab>
</CodeTabs>
---
## Promotion Module
The [Promotion Module](../../promotion/page.mdx) provides discount features.
Medusa defines a link between the `Cart` and `Promotion` data models. This indicates the promotions applied on a cart.
![A diagram showcasing an example of how data models from the Cart and Promotion modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1711538015/Medusa%20Resources/cart-promotion_kuh9vm.jpg)
Medusa also defines a read-only link between the `LineItemAdjustment` and `Promotion` data models. This means you can retrieve the details of the promotion applied on a line item, but you don't manage the links in a pivot table in the database. The promotion of a line item is determined by the `promotion_id` property of the `LineItemAdjustment` data model.
### Retrieve with Query
To retrieve the promotions of a cart with [Query](!docs!/learn/fundamentals/module-links/query), pass `promotions.*` in `fields`:
<Note>
To retrieve the promotion of a line item adjustment, pass `promotion.*` in `fields`.
</Note>
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: carts } = await query.graph({
entity: "cart",
fields: [
"promotions.*"
]
})
// carts.promotions
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: carts } = useQueryGraphStep({
entity: "cart",
fields: [
"promotions.*"
]
})
// carts.promotions
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the promotions of a cart, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.CART]: {
cart_id: "cart_123",
},
[Modules.PROMOTION]: {
promotion_id: "promo_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.CART]: {
cart_id: "cart_123",
},
[Modules.PROMOTION]: {
promotion_id: "promo_123",
},
})
```
</CodeTab>
</CodeTabs>
---
## Region Module
Medusa defines a read-only link between the `Cart` data model and the [Region Module](../../region/page.mdx)'s `Region` data model. This means you can retrieve the details of a cart's region, but you don't manage the links in a pivot table in the database. The region of a cart is determined by the `region_id` property of the `Cart` data model.
### Retrieve with Query
To retrieve the region of a cart with [Query](!docs!/learn/fundamentals/module-links/query), pass `region.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: carts } = await query.graph({
entity: "cart",
fields: [
"region.*"
]
})
// carts.region
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: carts } = useQueryGraphStep({
entity: "cart",
fields: [
"region.*"
]
})
// carts.region
```
</CodeTab>
</CodeTabs>
---
## Sales Channel Module
Medusa defines a read-only link between the `Cart` data model and the [Sales Channel Module](../../sales-channel/page.mdx)'s `SalesChannel` data model. This means you can retrieve the details of a cart's sales channel, but you don't manage the links in a pivot table in the database. The sales channel of a cart is determined by the `sales_channel_id` property of the `Cart` data model.
### Retrieve with Query
To retrieve the sales channel of a cart with [Query](!docs!/learn/fundamentals/module-links/query), pass `sales_channel.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: carts } = await query.graph({
entity: "cart",
fields: [
"sales_channel.*"
]
})
// carts.sales_channel
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: carts } = useQueryGraphStep({
entity: "cart",
fields: [
"sales_channel.*"
]
})
// carts.sales_channel
```
</CodeTab>
</CodeTabs>
@@ -0,0 +1,68 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = {
title: `Links between Currency Module and Other Modules`,
}
# {metadata.title}
This document showcases the module links defined between the Currency Module and other commerce modules.
## Summary
The Currency 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>
- [`Currency` data model of Store Module \<\> `Currency` data model of Currency Module](#store-module). (Read-only).
---
## Store Module
The Store Module has a `Currency` data model that stores the supported currencies of a store. However, these currencies don't hold all the details of a currency, such as its name or symbol.
Instead, Medusa defines a read-only link between the Currency Module's `Currency` data model and the [Store Module](../../store/page.mdx)'s `Currency` data model. This means you can retrieve the details of a store's supported currencies, but you don't manage the links in a pivot table in the database. The currencies of a store are determined by the `currency_code` of the `Currency` data model in the Store Module.
### Retrieve with Query
To retrieve the details of a store's currencies with [Query](!docs!/learn/fundamentals/module-links/query), pass `supported_currencies.currency.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: stores } = await query.graph({
entity: "store",
fields: [
"supported_currencies.currency.*"
]
})
// stores.supported_currencies
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: stores } = useQueryGraphStep({
entity: "store",
fields: [
"supported_currencies.currency.*"
]
})
// stores.supported_currencies
```
</CodeTab>
</CodeTabs>
@@ -0,0 +1,112 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = {
title: `Links between Customer Module and Other Modules`,
}
# {metadata.title}
This document showcases the module links defined between the Customer Module and other commerce modules.
## Summary
The Customer 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>
- [`Cart` data model of Cart Module \<\> `Customer` data model](#cart-module). (Read-only).
- [`Order` data model of Order Module \<\> `Customer` data model](#order-module). (Read-only).
---
## Cart Module
Medusa defines a read-only link between the `Customer` data model and the [Cart Module](../../cart/page.mdx)'s `Cart` data model. This means you can retrieve the details of a customer's carts, but you don't manage the links in a pivot table in the database. The customer of a cart is determined by the `customer_id` property of the `Cart` data model.
### Retrieve with Query
To retrieve a customer's carts with [Query](!docs!/learn/fundamentals/module-links/query), pass `carts.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: customers } = await query.graph({
entity: "customer",
fields: [
"carts.*"
]
})
// customers.carts
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: customers } = useQueryGraphStep({
entity: "customer",
fields: [
"carts.*"
]
})
// customers.carts
```
</CodeTab>
</CodeTabs>
---
## Order Module
Medusa defines a read-only link between the `Customer` data model and the [Order Module](../../order/page.mdx)'s `Order` data model. This means you can retrieve the details of a customer's orders, but you don't manage the links in a pivot table in the database. The customer of an order is determined by the `customer_id` property of the `Order` data model.
### Retrieve with Query
To retrieve a customer's orders with [Query](!docs!/learn/fundamentals/module-links/query), pass `orders.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: customers } = await query.graph({
entity: "customer",
fields: [
"orders.*"
]
})
// customers.orders
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: customers } = useQueryGraphStep({
entity: "customer",
fields: [
"orders.*"
]
})
// customers.orders
```
</CodeTab>
</CodeTabs>
@@ -1,3 +1,5 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = { export const metadata = {
title: `Links between Fulfillment Module and Other Modules`, title: `Links between Fulfillment Module and Other Modules`,
} }
@@ -6,9 +8,21 @@ export const metadata = {
This document showcases the module links defined between the Fulfillment Module and other commerce modules. This document showcases the module links defined between the Fulfillment Module and other commerce modules.
## Summary
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).
- [`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).
---
## Order Module ## Order Module
The Order Module provides order-management functionalities. The [Order Module](../../order/page.mdx) provides order-management functionalities.
Medusa defines a link between the `Fulfillment` and `Order` data models. A fulfillment is created for an orders' items. Medusa defines a link between the `Fulfillment` and `Order` data models. A fulfillment is created for an orders' items.
@@ -18,6 +32,95 @@ A fulfillment is also created for a return's items. So, Medusa defines a link be
![A diagram showcasing an example of how data models from the Fulfillment and Order modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1728399052/Medusa%20Resources/Social_Media_Graphics_2024_Order_Return_vetimk.jpg) ![A diagram showcasing an example of how data models from the Fulfillment and Order modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1728399052/Medusa%20Resources/Social_Media_Graphics_2024_Order_Return_vetimk.jpg)
### Retrieve with Query
To retrieve the order of a fulfillment with [Query](!docs!/learn/fundamentals/module-links/query), pass `order.*` in `fields`:
<Note>
To retrieve the return, pass `return.*` in `fields`.
</Note>
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: fulfillments } = await query.graph({
entity: "fulfillment",
fields: [
"order.*"
]
})
// fulfillments.order
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: fulfillments } = useQueryGraphStep({
entity: "fulfillment",
fields: [
"order.*"
]
})
// fulfillments.order
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the order of a cart, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.ORDER]: {
order_id: "order_123",
},
[Modules.FULFILLMENT]: {
fulfillment_id: "ful_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
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",
},
})
```
</CodeTab>
</CodeTabs>
--- ---
## Pricing Module ## Pricing Module
@@ -28,6 +131,89 @@ Medusa defines a link between the `PriceSet` and `ShippingOption` data models. A
![A diagram showcasing an example of how data models from the Pricing and Fulfillment modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716561747/Medusa%20Resources/pricing-fulfillment_spywwa.jpg) ![A diagram showcasing an example of how data models from the Pricing and Fulfillment modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716561747/Medusa%20Resources/pricing-fulfillment_spywwa.jpg)
### Retrieve with Query
To retrieve the price set of a shipping option with [Query](!docs!/learn/fundamentals/module-links/query), pass `price_set.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: shippingOptions } = await query.graph({
entity: "shipping_option",
fields: [
"price_set.*"
]
})
// shippingOptions.price_set
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: shippingOptions } = useQueryGraphStep({
entity: "shipping_option",
fields: [
"price_set.*"
]
})
// shippingOptions.price_set
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the price set of a shipping option, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.FULFILLMENT]: {
shipping_option_id: "so_123",
},
[Modules.PRICING]: {
price_set_id: "pset_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
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",
},
})
```
</CodeTab>
</CodeTabs>
--- ---
## Stock Location Module ## Stock Location Module
@@ -41,3 +227,92 @@ Medusa defines a link between the `FulfillmentSet` and `StockLocation` data mode
Medusa also defines a link between the `FulfillmentProvider` and `StockLocation` data models to indicate the providers that can be used in a location. 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](https://res.cloudinary.com/dza7lstvk/image/upload/v1728399492/Medusa%20Resources/fulfillment-provider-stock-location_b0mulo.jpg) ![A diagram showcasing an example of how data models from the Fulfillment and Stock Location modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1728399492/Medusa%20Resources/fulfillment-provider-stock-location_b0mulo.jpg)
### Retrieve with Query
To retrieve the stock location of a fulfillment set with [Query](!docs!/learn/fundamentals/module-links/query), pass `location.*` in `fields`:
<Note>
To retrieve the stock location of a fulfillment provider, pass `locations.*` in `fields`.
</Note>
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: fulfillmentSets } = await query.graph({
entity: "fulfillment_set",
fields: [
"location.*"
]
})
// fulfillmentSets.location
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: fulfillmentSets } = useQueryGraphStep({
entity: "fulfillment_set",
fields: [
"location.*"
]
})
// fulfillmentSets.location
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the stock location of a fulfillment set, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.STOCK_LOCATION]: {
stock_location_id: "sloc_123",
},
[Modules.FULFILLMENT]: {
fulfillment_set_id: "fset_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
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",
},
})
```
</CodeTab>
</CodeTabs>
@@ -1,3 +1,5 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = { export const metadata = {
title: `Links between Inventory Module and Other Modules`, title: `Links between Inventory Module and Other Modules`,
} }
@@ -6,6 +8,21 @@ export const metadata = {
This document showcases the module links defined between the Inventory Module and other commerce modules. This document showcases the module links defined between the Inventory Module and other commerce modules.
## Summary
The Inventory 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>
- [`ProductVariant` data model of Product Module \<\> `InventoryItem` data model](#product-module).
- [`InventoryLevel` data model \<\> `StockLocation` data model of Stock Location Module](#stock-location-module). (Read-only).
---
## Product Module ## Product Module
Each product variant has different inventory details. Medusa defines a link between the `ProductVariant` and `InventoryItem` data models. Each product variant has different inventory details. Medusa defines a link between the `ProductVariant` and `InventoryItem` data models.
@@ -13,3 +30,131 @@ Each product variant has different inventory details. Medusa defines a link betw
![A diagram showcasing an example of how data models from the Inventory and Product Module are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709658720/Medusa%20Resources/inventory-product_ejnray.jpg) ![A diagram showcasing an example of how data models from the Inventory and Product Module are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709658720/Medusa%20Resources/inventory-product_ejnray.jpg)
A product variant whose `manage_inventory` property is enabled has an associated inventory item. Through that inventory's items relations in the Inventory Module, you can manage and check the variant's inventory quantity. A product variant whose `manage_inventory` property is enabled has an associated inventory item. Through that inventory's items relations in the Inventory Module, you can manage and check the variant's inventory quantity.
### Retrieve with Query
To retrieve the product variants of an inventory item with [Query](!docs!/learn/fundamentals/module-links/query), pass `variants.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: inventoryItems } = await query.graph({
entity: "inventory_item",
fields: [
"variants.*"
]
})
// inventoryItems.variants
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: inventoryItems } = useQueryGraphStep({
entity: "inventory_item",
fields: [
"variants.*"
]
})
// inventoryItems.variants
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the variants of an inventory item, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.PRODUCT]: {
variant_id: "variant_123",
},
[Modules.INVENTORY]: {
inventory_item_id: "iitem_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.PRODUCT]: {
variant_id: "variant_123",
},
[Modules.INVENTORY]: {
inventory_item_id: "iitem_123",
},
})
```
</CodeTab>
</CodeTabs>
---
## Stock Location Module
Medusa defines a read-only link between the `InventoryLevel` data model and the [Stock Location Module](../../stock-location/page.mdx)'s `StockLocation` data model. This means you can retrieve the details of an inventory level's stock locations, 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 stock locations of an inventory level with [Query](!docs!/learn/fundamentals/module-links/query), pass `stock_locations.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: inventoryLevels } = await query.graph({
entity: "inventory_level",
fields: [
"stock_locations.*"
]
})
// inventoryLevels.stock_locations
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: inventoryLevels } = useQueryGraphStep({
entity: "inventory_level",
fields: [
"stock_locations.*"
]
})
// inventoryLevels.stock_locations
```
</CodeTab>
</CodeTabs>
@@ -1,3 +1,5 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = { export const metadata = {
title: `Links between Order Module and Other Modules`, title: `Links between Order Module and Other Modules`,
} }
@@ -6,14 +8,166 @@ export const metadata = {
This document showcases the module links defined between the Order Module and other commerce modules. This document showcases the module links defined between the Order Module and other commerce modules.
## Summary
The Order 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>
- [`Order` data model \<\> `Customer` data model of Customer Module](#customer-module). (Read-only).
- [`Order` data model \<\> `Cart` data model of Cart Module](#cart-module).
- [`Order` data model \<\> `Fulfillment` data model of Fulfillment Module](#fulfillment-module).
- [`Return` data model \<\> `Fulfillment` data model of Fulfillment Module](#fulfillment-module).
- [`Order` data model \<\> `PaymentCollection` data model of Payment Module](#payment-module).
- [`OrderClaim` data model \<\> `PaymentCollection` data model of Payment Module](#payment-module).
- [`OrderExchange` data model \<\> `PaymentCollection` data model of Payment Module](#payment-module).
- [`Order` data model \<\> `Product` data model of Product Module](#product-module). (Read-only).
- [`Order` data model \<\> `Promotion` data model of Promotion Module](#promotion-module).
- [`Order` data model \<\> `Region` data model of Region Module](#region-module). (Read-only).
- [`Order` data model \<\> `SalesChannel` data model of Sales Channel Module](#sales-channel-module). (Read-only).
---
## Customer Module
Medusa defines a read-only link between the `Order` data model and the [Customer Module](../../customer/page.mdx)'s `Customer` data model. This means you can retrieve the details of an order's customer, but you don't manage the links in a pivot table in the database. The customer of an order is determined by the `customer_id` property of the `Order` data model.
### Retrieve with Query
To retrieve the customer of an order with [Query](!docs!/learn/fundamentals/module-links/query), pass `customer.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: orders } = await query.graph({
entity: "order",
fields: [
"customer.*"
]
})
// orders.customer
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: orders } = useQueryGraphStep({
entity: "order",
fields: [
"customer.*"
]
})
// orders.customer
```
</CodeTab>
</CodeTabs>
---
## Cart Module ## Cart Module
The Cart Module provides cart-management features. The [Cart Module](../../cart/page.mdx) provides cart-management features.
Medusa defines a link between the `Order` and `Cart` data models. The order is linked to the cart used for the purchased. Medusa defines a link between the `Order` and `Cart` data models. The order is linked to the cart used for the purchased.
![A diagram showcasing an example of how data models from the Cart and Order modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1728375735/Medusa%20Resources/cart-order_ijwmfs.jpg) ![A diagram showcasing an example of how data models from the Cart and Order modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1728375735/Medusa%20Resources/cart-order_ijwmfs.jpg)
### Retrieve with Query
To retrieve the cart of an order with [Query](!docs!/learn/fundamentals/module-links/query), pass `cart.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: orders } = await query.graph({
entity: "order",
fields: [
"cart.*"
]
})
// orders.cart
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: orders } = useQueryGraphStep({
entity: "order",
fields: [
"cart.*"
]
})
// orders.cart
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the cart of an order, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.ORDER]: {
order_id: "order_123",
},
[Modules.CART]: {
cart_id: "cart_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.ORDER]: {
order_id: "order_123",
},
[Modules.CART]: {
cart_id: "cart_123",
},
})
```
</CodeTab>
</CodeTabs>
--- ---
## Fulfillment Module ## Fulfillment Module
@@ -22,11 +176,99 @@ A fulfillment is created for an orders' items. Medusa defines a link between the
![A diagram showcasing an example of how data models from the Fulfillment and Order modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716549903/Medusa%20Resources/order-fulfillment_h0vlps.jpg) ![A diagram showcasing an example of how data models from the Fulfillment and Order modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716549903/Medusa%20Resources/order-fulfillment_h0vlps.jpg)
A fulfillment is also created for a return's items. So, Medusa defines a link between the `Fulfillment` and `Return` data models. A fulfillment is also created for a return's items. So, Medusa defines a link between the `Fulfillment` and `Return` data models.
![A diagram showcasing an example of how data models from the Fulfillment and Order modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1728399052/Medusa%20Resources/Social_Media_Graphics_2024_Order_Return_vetimk.jpg) ![A diagram showcasing an example of how data models from the Fulfillment and Order modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1728399052/Medusa%20Resources/Social_Media_Graphics_2024_Order_Return_vetimk.jpg)
### Retrieve with Query
To retrieve the fulfillments of an order with [Query](!docs!/learn/fundamentals/module-links/query), pass `fulfillments.*` in `fields`:
<Note>
To retrieve the fulfillments of a return, pass `fulfillments.*` in `fields`.
</Note>
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: orders } = await query.graph({
entity: "order",
fields: [
"fulfillments.*"
]
})
// orders.fulfillments
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: orders } = useQueryGraphStep({
entity: "order",
fields: [
"fulfillments.*"
]
})
// orders.fulfillments
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the fulfillments of an order, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.ORDER]: {
order_id: "order_123",
},
[Modules.FULFILLMENT]: {
fulfillment_id: "ful_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
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",
},
})
```
</CodeTab>
</CodeTabs>
--- ---
## Payment Module ## Payment Module
@@ -37,6 +279,143 @@ So, Medusa defines links between the `PaymentCollection` data model and the `Ord
![A diagram showcasing an example of how data models from the Order and Payment modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716554726/Medusa%20Resources/order-payment_ubdwok.jpg) ![A diagram showcasing an example of how data models from the Order and Payment modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716554726/Medusa%20Resources/order-payment_ubdwok.jpg)
### Retrieve with Query
To retrieve the payment collections of an order, order exchange, or order claim with [Query](!docs!/learn/fundamentals/module-links/query), pass `payment_collections.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: orders } = await query.graph({
entity: "order",
fields: [
"payment_collections.*"
]
})
// orders.payment_collections
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: orders } = useQueryGraphStep({
entity: "order",
fields: [
"payment_collections.*"
]
})
// orders.payment_collections
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the payment collections of an order, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.ORDER]: {
order_id: "order_123",
},
[Modules.PAYMENT]: {
payment_collection_id: "paycol_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.ORDER]: {
order_id: "order_123",
},
[Modules.PAYMENT]: {
payment_collection_id: "paycol_123",
},
})
```
</CodeTab>
</CodeTabs>
---
## Product Module
Medusa defines read-only links between:
- the `OrderLineItem` data model and the [Product Module](../../product/page.mdx)'s `Product` data model. This means you can retrieve the details of a line item's product, but you don't manage the links in a pivot table in the database. The product of a line item is determined by the `product_id` property of the `OrderLineItem` data model.
- the `OrderLineItem` data model and the [Product Module](../../product/page.mdx)'s `ProductVariant` data model. This means you can retrieve the details of a line item's variant, but you don't manage the links in a pivot table in the database. The variant of a line item is determined by the `variant_id` property of the `OrderLineItem` data model.
### Retrieve with Query
To retrieve the variant of a line item with [Query](!docs!/learn/fundamentals/module-links/query), pass `variant.*` in `fields`:
<Note>
To retrieve the product, pass `product.*` in `fields`.
</Note>
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: lineItems } = await query.graph({
entity: "order_line_item",
fields: [
"variant.*"
]
})
// lineItems.variant
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: lineItems } = useQueryGraphStep({
entity: "order_line_item",
fields: [
"variant.*"
]
})
// lineItems.variant
```
</CodeTab>
</CodeTabs>
--- ---
## Promotion Module ## Promotion Module
@@ -44,3 +423,176 @@ So, Medusa defines links between the `PaymentCollection` data model and the `Ord
An order is associated with the promotion applied on it. Medusa defines a link between the `Order` and `Promotion` data models. An order is associated with the promotion applied on it. Medusa defines a link between the `Order` and `Promotion` data models.
![A diagram showcasing an example of how data models from the Order and Promotion modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716555015/Medusa%20Resources/order-promotion_dgjzzd.jpg) ![A diagram showcasing an example of how data models from the Order and Promotion modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716555015/Medusa%20Resources/order-promotion_dgjzzd.jpg)
### Retrieve with Query
To retrieve the promotion applied on an order with [Query](!docs!/learn/fundamentals/module-links/query), pass `promotion.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: orders } = await query.graph({
entity: "order",
fields: [
"promotion.*"
]
})
// orders.promotion
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: orders } = useQueryGraphStep({
entity: "order",
fields: [
"promotion.*"
]
})
// orders.promotion
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the promotion of an order, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.ORDER]: {
order_id: "order_123",
},
[Modules.PROMOTION]: {
promotion_id: "promo_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.ORDER]: {
order_id: "order_123",
},
[Modules.PROMOTION]: {
promotion_id: "promo_123",
},
})
```
</CodeTab>
</CodeTabs>
---
## Region Module
Medusa defines a read-only link between the `Order` data model and the [Region Module](../../region/page.mdx)'s `Region` data model. This means you can retrieve the details of an order's region, but you don't manage the links in a pivot table in the database. The region of an order is determined by the `region_id` property of the `Order` data model.
### Retrieve with Query
To retrieve the region of an order with [Query](!docs!/learn/fundamentals/module-links/query), pass `region.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: orders } = await query.graph({
entity: "order",
fields: [
"region.*"
]
})
// orders.region
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: orders } = useQueryGraphStep({
entity: "order",
fields: [
"region.*"
]
})
// orders.region
```
</CodeTab>
</CodeTabs>
---
## Sales Channel Module
Medusa defines a read-only link between the `Order` data model and the [Sales Channel Module](../../sales-channel/page.mdx)'s `SalesChannel` data model. This means you can retrieve the details of an order's sales channel, but you don't manage the links in a pivot table in the database. The sales channel of an order is determined by the `sales_channel_id` property of the `Order` data model.
### Retrieve with Query
To retrieve the sales channel of an order with [Query](!docs!/learn/fundamentals/module-links/query), pass `sales_channel.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: orders } = await query.graph({
entity: "order",
fields: [
"sales_channel.*"
]
})
// orders.sales_channel
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: orders } = useQueryGraphStep({
entity: "order",
fields: [
"sales_channel.*"
]
})
// orders.sales_channel
```
</CodeTab>
</CodeTabs>
@@ -1,3 +1,5 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = { export const metadata = {
title: `Links between Payment Module and Other Modules`, title: `Links between Payment Module and Other Modules`,
} }
@@ -6,6 +8,18 @@ export const metadata = {
This document showcases the module links defined between the Payment Module and other commerce modules. This document showcases the module links defined between the Payment Module and other commerce modules.
## Summary
The Payment Module has the following links to other modules:
- [`Cart` data model of Cart Module \<\> `PaymentCollection` data model](#cart-module).
- [`Order` data model of Order Module \<\> `PaymentCollection` data model](#order-module).
- [`OrderClaim` data model of Order Module \<\> `PaymentCollection` data model](#order-module).
- [`OrderExchange` data model of Order Module \<\> `PaymentCollection` data model](#order-module).
- [`Region` data model of Region Module \<\> `PaymentProvider` data model](#region-module).
---
## Cart Module ## Cart Module
The Cart Module provides cart-related features, but not payment processing. The Cart Module provides cart-related features, but not payment processing.
@@ -14,6 +28,88 @@ Medusa defines a link between the `Cart` and `PaymentCollection` data models. A
Learn more about this relation in [this documentation](../payment-collection/page.mdx#usage-with-the-cart-module). Learn more about this relation in [this documentation](../payment-collection/page.mdx#usage-with-the-cart-module).
### Retrieve with Query
To retrieve the cart associated with the payment collection with [Query](!docs!/learn/fundamentals/module-links/query), pass `cart.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: paymentCollections } = await query.graph({
entity: "payment_collection",
fields: [
"cart.*"
]
})
// paymentCollections.cart
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: paymentCollections } = useQueryGraphStep({
entity: "payment_collection",
fields: [
"cart.*"
]
})
// paymentCollections.cart
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the payment collection of a cart, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.CART]: {
cart_id: "cart_123",
},
[Modules.PAYMENT]: {
payment_collection_id: "paycol_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.CART]: {
cart_id: "cart_123",
},
[Modules.PAYMENT]: {
payment_collection_id: "paycol_123",
},
})
```
</CodeTab>
</CodeTabs>
--- ---
## Order Module ## Order Module
@@ -24,6 +120,89 @@ So, Medusa defines links between the `PaymentCollection` data model and the `Ord
![A diagram showcasing an example of how data models from the Order and Payment modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716554726/Medusa%20Resources/order-payment_ubdwok.jpg) ![A diagram showcasing an example of how data models from the Order and Payment modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716554726/Medusa%20Resources/order-payment_ubdwok.jpg)
### Retrieve with Query
To retrieve the order of a payment collection with [Query](!docs!/learn/fundamentals/module-links/query), pass `order.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: paymentCollections } = await query.graph({
entity: "payment_collection",
fields: [
"order.*"
]
})
// paymentCollections.order
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: paymentCollections } = useQueryGraphStep({
entity: "payment_collection",
fields: [
"order.*"
]
})
// paymentCollections.order
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the payment collections of an order, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.ORDER]: {
order_id: "order_123",
},
[Modules.PAYMENT]: {
payment_collection_id: "paycol_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.ORDER]: {
order_id: "order_123",
},
[Modules.PAYMENT]: {
payment_collection_id: "paycol_123",
},
})
```
</CodeTab>
</CodeTabs>
--- ---
## Region Module ## Region Module
@@ -33,3 +212,86 @@ You can specify for each region which payment providers are available. The Medus
![A diagram showcasing an example of how resources from the Payment and Region modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1711569520/Medusa%20Resources/payment-region_jyo2dz.jpg) ![A diagram showcasing an example of how resources from the Payment and Region modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1711569520/Medusa%20Resources/payment-region_jyo2dz.jpg)
This increases the flexibility of your store. For example, you only show during checkout the payment providers associated with the cart's region. This increases the flexibility of your store. For example, you only show during checkout the payment providers associated with the cart's region.
### Retrieve with Query
To retrieve the regions of a payment provider with [Query](!docs!/learn/fundamentals/module-links/query), pass `regions.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: paymentProviders } = await query.graph({
entity: "payment_provider",
fields: [
"regions.*"
]
})
// paymentProviders.regions
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: paymentProviders } = useQueryGraphStep({
entity: "payment_provider",
fields: [
"regions.*"
]
})
// paymentProviders.regions
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the payment providers in a region, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.REGION]: {
region_id: "reg_123",
},
[Modules.PAYMENT]: {
payment_provider_id: "pp_stripe_stripe",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.REGION]: {
region_id: "reg_123",
},
[Modules.PAYMENT]: {
payment_provider_id: "pp_stripe_stripe",
},
})
```
</CodeTab>
</CodeTabs>
@@ -1,3 +1,5 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = { export const metadata = {
title: `Links between Pricing Module and Other Modules`, title: `Links between Pricing Module and Other Modules`,
} }
@@ -6,6 +8,15 @@ export const metadata = {
This document showcases the module links defined between the Pricing Module and other commerce modules. This document showcases the module links defined between the Pricing Module and other commerce modules.
## Summary
The Pricing Module has the following links to other modules:
- [`ShippingOption` data model of Fulfillment Module \<\> `PriceSet` data model](#fulfillment-module).
- [`ProductVariant` data model of Product Module \<\> `PriceSet` data model](#product-module).
---
## Fulfillment Module ## Fulfillment Module
The Fulfillment Module provides fulfillment-related functionalities, including shipping options that the customer chooses from when they place their order. However, it doesn't provide pricing-related functionalities for these options. The Fulfillment Module provides fulfillment-related functionalities, including shipping options that the customer chooses from when they place their order. However, it doesn't provide pricing-related functionalities for these options.
@@ -14,6 +25,89 @@ Medusa defines a link between the `PriceSet` and `ShippingOption` data models. A
![A diagram showcasing an example of how data models from the Pricing and Fulfillment modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716561747/Medusa%20Resources/pricing-fulfillment_spywwa.jpg) ![A diagram showcasing an example of how data models from the Pricing and Fulfillment modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716561747/Medusa%20Resources/pricing-fulfillment_spywwa.jpg)
### Retrieve with Query
To retrieve the shipping option of a price set with [Query](!docs!/learn/fundamentals/module-links/query), pass `shipping_option.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: priceSets } = await query.graph({
entity: "price_set",
fields: [
"shipping_option.*"
]
})
// priceSets.shipping_option
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: priceSets } = useQueryGraphStep({
entity: "price_set",
fields: [
"shipping_option.*"
]
})
// priceSets.shipping_option
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the price set of a shipping option, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.FULFILLMENT]: {
shipping_option_id: "so_123",
},
[Modules.PRICING]: {
price_set_id: "pset_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
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",
},
})
```
</CodeTab>
</CodeTabs>
--- ---
## Product Module ## Product Module
@@ -27,3 +121,86 @@ Medusa defines a link between the `ProductVariant` and the `PriceSet`. A product
So, when you want to add prices for a product variant, you create a price set and add the prices to it. So, when you want to add prices for a product variant, you create a price set and add the prices to it.
You can then benefit from adding rules to prices or using the `calculatePrices` method to retrieve the price of a product variant within a specified context. You can then benefit from adding rules to prices or using the `calculatePrices` method to retrieve the price of a product variant within a specified context.
### Retrieve with Query
To retrieve the variant of a price set with [Query](!docs!/learn/fundamentals/module-links/query), pass `variant.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: priceSets } = await query.graph({
entity: "price_set",
fields: [
"variant.*"
]
})
// priceSets.variant
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: priceSets } = useQueryGraphStep({
entity: "price_set",
fields: [
"variant.*"
]
})
// priceSets.variant
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the price set of a variant, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.PRODUCT]: {
variant_id: "variant_123",
},
[Modules.PRICING]: {
price_set_id: "pset_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.PRODUCT]: {
variant_id: "variant_123",
},
[Modules.PRICING]: {
price_set_id: "pset_123",
},
})
```
</CodeTab>
</CodeTabs>
@@ -1,3 +1,5 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = { export const metadata = {
title: `Links between Product Module and Other Modules`, title: `Links between Product Module and Other Modules`,
} }
@@ -6,25 +8,75 @@ export const metadata = {
This document showcases the module links defined between the Product Module and other commerce modules. This document showcases the module links defined between the Product Module and other commerce modules.
## Pricing Module ## Summary
The Product Module doesn't provide pricing-related features. The Product Module has the following links to other modules:
Instead, Medusa defines a link between the `ProductVariant` and the `PriceSet` data models. A product variant’s prices are stored belonging to a price set. <Note title="Tip">
![A diagram showcasing an example of how data models from the Pricing and Product Module are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709651464/Medusa%20Resources/product-pricing_vlxsiq.jpg) Read-only links are used to query data across modules, but the relations aren't stored in a pivot table in the database.
So, to add prices for a product variant, create a price set and add the prices to it. </Note>
- [`Product` data model \<\> `Cart` data model of Cart Module](#cart-module). (Read-only).
- [`Product` 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).
- [`Product` data model \<\> `SalesChannel` data model of Sales Channel Module](#sales-channel-module).
--- ---
## Sales Channel Module ## Cart Module
The Sales Channel Module provides functionalities to manage multiple selling channels in your store. Medusa defines read-only links between:
Medusa defines a link between the `Product` and `SalesChannel` data models. A product can have different availability in different sales channels. - The `Product` data model and the [Cart Module](../../cart/page.mdx)'s `LineItem` data model. This means you can retrieve the details of a line item's product, but you don't manage the links in a pivot table in the database. The product of a line item is determined by the `product_id` property of the `LineItem` data model.
- The `ProductVariant` data model and the [Cart Module](../../cart/page.mdx)'s `LineItem` data model. This means you can retrieve the details of a line item's variant, but you don't manage the links in a pivot table in the database. The variant of a line item is determined by the `variant_id` property of the `LineItem` data model.
![A diagram showcasing an example of how data models from the Product and Sales Channel modules are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709651840/Medusa%20Resources/product-sales-channel_t848ik.jpg) ### Retrieve with Query
To retrieve the line items of a variant with [Query](!docs!/learn/fundamentals/module-links/query), pass `line_items.*` in `fields`:
<Note>
To retrieve the line items of a product, pass `line_items.*` in `fields`.
</Note>
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: variants } = await query.graph({
entity: "variant",
fields: [
"line_items.*"
]
})
// variants.line_items
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: variants } = useQueryGraphStep({
entity: "variant",
fields: [
"line_items.*"
]
})
// variants.line_items
```
</CodeTab>
</CodeTabs>
--- ---
@@ -37,3 +89,328 @@ Medusa defines a link between the `ProductVariant` and `InventoryItem` data mode
![A diagram showcasing an example of how data models from the Product and Inventory modules are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709652779/Medusa%20Resources/product-inventory_kmjnud.jpg) ![A diagram showcasing an example of how data models from the Product and Inventory modules are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709652779/Medusa%20Resources/product-inventory_kmjnud.jpg)
When the `manage_inventory` property of a product variant is enabled, you can manage the variant's inventory in different locations through this relation. When the `manage_inventory` property of a product variant is enabled, you can manage the variant's inventory in different locations through this relation.
### Retrieve with Query
To retrieve the inventory items of a product variant with [Query](!docs!/learn/fundamentals/module-links/query), pass `inventory_items.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: variants } = await query.graph({
entity: "variant",
fields: [
"inventory_items.*"
]
})
// variants.inventory_items
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: variants } = useQueryGraphStep({
entity: "variant",
fields: [
"inventory_items.*"
]
})
// variants.inventory_items
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the inventory items of a variant, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.PRODUCT]: {
variant_id: "variant_123",
},
[Modules.INVENTORY]: {
inventory_item_id: "iitem_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.PRODUCT]: {
variant_id: "variant_123",
},
[Modules.INVENTORY]: {
inventory_item_id: "iitem_123",
},
})
```
</CodeTab>
</CodeTabs>
---
## Order Module
Medusa defines read-only links between:
- the `Product` data model and the [Order Module](../../order/page.mdx)'s `OrderLineItem` data model. This means you can retrieve the details of a line item's product, but you don't manage the links in a pivot table in the database. The product of a line item is determined by the `product_id` property of the `OrderLineItem` data model.
- the `ProductVariant` data model and the [Order Module](../../order/page.mdx)'s `OrderLineItem` data model. This means you can retrieve the details of a line item's variant, but you don't manage the links in a pivot table in the database. The variant of a line item is determined by the `variant_id` property of the `OrderLineItem` data model.
### Retrieve with Query
To retrieve the order line items of a variant with [Query](!docs!/learn/fundamentals/module-links/query), pass `order_items.*` in `fields`:
<Note>
To retrieve a product's order line items, pass `order_items.*` in `fields`.
</Note>
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: variants } = await query.graph({
entity: "variant",
fields: [
"order_items.*"
]
})
// variants.order_items
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: variants } = useQueryGraphStep({
entity: "variant",
fields: [
"order_items.*"
]
})
// variants.order_items
```
</CodeTab>
</CodeTabs>
---
## Pricing Module
The Product Module doesn't provide pricing-related features.
Instead, Medusa defines a link between the `ProductVariant` and the `PriceSet` data models. A product variant’s prices are stored belonging to a price set.
![A diagram showcasing an example of how data models from the Pricing and Product Module are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709651464/Medusa%20Resources/product-pricing_vlxsiq.jpg)
So, to add prices for a product variant, create a price set and add the prices to it.
### Retrieve with Query
To retrieve the price set of a variant with [Query](!docs!/learn/fundamentals/module-links/query), pass `price_set.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: variants } = await query.graph({
entity: "variant",
fields: [
"price_set.*"
]
})
// variants.price_set
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: variants } = useQueryGraphStep({
entity: "variant",
fields: [
"price_set.*"
]
})
// variants.price_set
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the price set of a variant, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.PRODUCT]: {
variant_id: "variant_123",
},
[Modules.PRICING]: {
price_set_id: "pset_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.PRODUCT]: {
variant_id: "variant_123",
},
[Modules.PRICING]: {
price_set_id: "pset_123",
},
})
```
</CodeTab>
</CodeTabs>
---
## Sales Channel Module
The Sales Channel Module provides functionalities to manage multiple selling channels in your store.
Medusa defines a link between the `Product` and `SalesChannel` data models. A product can have different availability in different sales channels.
![A diagram showcasing an example of how data models from the Product and Sales Channel modules are linked.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709651840/Medusa%20Resources/product-sales-channel_t848ik.jpg)
### Retrieve with Query
To retrieve the sales channels of a product with [Query](!docs!/learn/fundamentals/module-links/query), pass `sales_channels.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: products } = await query.graph({
entity: "product",
fields: [
"sales_channels.*"
]
})
// products.sales_channels
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: products } = useQueryGraphStep({
entity: "product",
fields: [
"sales_channels.*"
]
})
// products.sales_channels
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the sales channels of a product, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.PRODUCT]: {
product_id: "prod_123",
},
[Modules.SALES_CHANNEL]: {
sales_channel_id: "sc_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.SALES_CHANNEL]: {
sales_channel_id: "sc_123",
},
})
```
</CodeTab>
</CodeTabs>
@@ -1,3 +1,5 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = { export const metadata = {
title: `Links between Promotion Module and Other Modules`, title: `Links between Promotion Module and Other Modules`,
} }
@@ -6,12 +8,119 @@ export const metadata = {
This document showcases the module links defined between the Promotion Module and other commerce modules. This document showcases the module links defined between the Promotion Module and other commerce modules.
## Summary
The Promotion 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>
- [`Cart` data model of the Cart Module \<\> `Promotion` data model](#cart-module).
- [`LineItemAdjustment` data model of the Cart Module \<\> `Promotion` data model](#cart-module). (Read-only).
- [`Order` data model of the Order Module \<\> `Promotion` data model](#order-module).
---
## Cart Module ## Cart Module
A promotion can be applied on line items and shipping methods of a cart. Medusa defines a link between the `Cart`, `LineItemAdjustment`, and `Promotion` data models. A promotion can be applied on line items and shipping methods of a cart. Medusa defines a link between the `Cart` and `Promotion` data models.
![A diagram showcasing an example of how data models from the Cart and Promotion modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1711538015/Medusa%20Resources/cart-promotion_kuh9vm.jpg) ![A diagram showcasing an example of how data models from the Cart and Promotion modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1711538015/Medusa%20Resources/cart-promotion_kuh9vm.jpg)
Medusa also defines a read-only link between the `Promotion` data model and the [Cart Module](../../cart/page.mdx)'s `LineItemAdjustment` data model. This means you can retrieve the details of the promotion applied on a line item, but you don't manage the links in a pivot table in the database. The promotion of a line item is determined by the `promotion_id` property of the `LineItemAdjustment` data model.
### Retrieve with Query
To retrieve the carts that a promotion is applied on with [Query](!docs!/learn/fundamentals/module-links/query), pass `carts.*` in `fields`:
<Note>
To retrieve the line item adjustments of a promotion, pass `line_item_adjustments.*` in `fields`.
</Note>
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: promotions } = await query.graph({
entity: "promotion",
fields: [
"carts.*"
]
})
// promotions.carts
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: promotions } = useQueryGraphStep({
entity: "promotion",
fields: [
"carts.*"
]
})
// promotions.carts
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the promotions of a cart, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.CART]: {
cart_id: "cart_123",
},
[Modules.PROMOTION]: {
promotion_id: "promo_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.CART]: {
cart_id: "cart_123",
},
[Modules.PROMOTION]: {
promotion_id: "promo_123",
},
})
```
</CodeTab>
</CodeTabs>
--- ---
## Order Module ## Order Module
@@ -19,3 +128,86 @@ A promotion can be applied on line items and shipping methods of a cart. Medusa
An order is associated with the promotion applied on it. Medusa defines a link between the `Order` and `Promotion` data models. An order is associated with the promotion applied on it. Medusa defines a link between the `Order` and `Promotion` data models.
![A diagram showcasing an example of how data models from the Order and Promotion modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716555015/Medusa%20Resources/order-promotion_dgjzzd.jpg) ![A diagram showcasing an example of how data models from the Order and Promotion modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716555015/Medusa%20Resources/order-promotion_dgjzzd.jpg)
### Retrieve with Query
To retrieve the orders a promotion is applied on with [Query](!docs!/learn/fundamentals/module-links/query), pass `orders.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: promotions } = await query.graph({
entity: "promotion",
fields: [
"orders.*"
]
})
// promotions.orders
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: promotions } = useQueryGraphStep({
entity: "promotion",
fields: [
"orders.*"
]
})
// promotions.orders
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the promotion of an order, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.ORDER]: {
order_id: "order_123",
},
[Modules.PROMOTION]: {
promotion_id: "promo_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.ORDER]: {
order_id: "order_123",
},
[Modules.PROMOTION]: {
promotion_id: "promo_123",
},
})
```
</CodeTab>
</CodeTabs>
@@ -1,3 +1,5 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = { export const metadata = {
title: `Links between Region Module and Other Modules`, title: `Links between Region Module and Other Modules`,
} }
@@ -6,6 +8,112 @@ export const metadata = {
This document showcases the module links defined between the Region Module and other commerce modules. This document showcases the module links defined between the Region Module and other commerce modules.
## Summary
The Region 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>
- [`Region` data model \<\> `Cart` data model of the Cart Module](#cart-module). (Read-only)
- [`Region` data model \<\> `Order` data model of the Order Module](#order-module). (Read-only)
- [`Region` data model \<\> `PaymentProvider` data model of the Payment Module](#payment-module).
---
## Cart Module
Medusa defines a read-only link between the `Region` data model and the [Cart Module](../../cart/page.mdx)'s `Cart` data model. This means you can retrieve the details of a region's carts, but you don't manage the links in a pivot table in the database. The region of a cart is determined by the `region_id` property of the `Cart` data model.
### Retrieve with Query
To retrieve the carts of a region with [Query](!docs!/learn/fundamentals/module-links/query), pass `carts.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: regions } = await query.graph({
entity: "region",
fields: [
"carts.*"
]
})
// regions.carts
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: regions } = useQueryGraphStep({
entity: "region",
fields: [
"carts.*"
]
})
// regions.carts
```
</CodeTab>
</CodeTabs>
---
## Order Module
Medusa defines a read-only link between the `Region` data model and the [Cart Module](../../cart/page.mdx)'s `Cart` data model. This means you can retrieve the details of a region's orders, but you don't manage the links in a pivot table in the database. The region of an order is determined by the `region_id` property of the `Order` data model.
### Retrieve with Query
To retrieve the orders of a region with [Query](!docs!/learn/fundamentals/module-links/query), pass `orders.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: regions } = await query.graph({
entity: "region",
fields: [
"orders.*"
]
})
// regions.orders
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: regions } = useQueryGraphStep({
entity: "region",
fields: [
"orders.*"
]
})
// regions.orders
```
</CodeTab>
</CodeTabs>
---
## Payment Module ## Payment Module
You can specify for each region which payment providers are available for use. You can specify for each region which payment providers are available for use.
@@ -13,3 +121,86 @@ You can specify for each region which payment providers are available for use.
Medusa defines a module link between the `PaymentProvider` and the `Region` data models. Medusa defines a module link between the `PaymentProvider` and the `Region` data models.
![A diagram showcasing an example of how resources from the Payment and Region modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1711569520/Medusa%20Resources/payment-region_jyo2dz.jpg) ![A diagram showcasing an example of how resources from the Payment and Region modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1711569520/Medusa%20Resources/payment-region_jyo2dz.jpg)
### Retrieve with Query
To retrieve the payment providers of a region with [Query](!docs!/learn/fundamentals/module-links/query), pass `payment_providers.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: regions } = await query.graph({
entity: "region",
fields: [
"payment_providers.*"
]
})
// regions.payment_providers
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: regions } = useQueryGraphStep({
entity: "region",
fields: [
"payment_providers.*"
]
})
// regions.payment_providers
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the payment providers in a region, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.REGION]: {
region_id: "reg_123",
},
[Modules.PAYMENT]: {
payment_provider_id: "pp_stripe_stripe",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.REGION]: {
region_id: "reg_123",
},
[Modules.PAYMENT]: {
payment_provider_id: "pp_stripe_stripe",
},
})
```
</CodeTab>
</CodeTabs>
@@ -1,3 +1,5 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = { export const metadata = {
title: `Links between Sales Channel Module and Other Modules`, title: `Links between Sales Channel Module and Other Modules`,
} }
@@ -6,6 +8,24 @@ export const metadata = {
This document showcases the module links defined between the Sales Channel Module and other commerce modules. This document showcases the module links defined between the Sales Channel Module and other commerce modules.
## Summary
The Sales Channel 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>
- [`ApiKey` data model of the API Key Module \<\> `SalesChannel` data model](#api-key-module).
- [`SalesChannel` data model \<\> `Cart` data model of the Cart Module](#cart-module). (Read-only)
- [`SalesChannel` data model \<\> `Order` data model of the Order Module](#order-module). (Read-only)
- [`Product` data model of the Product Module \<\> `SalesChannel` data model](#product-module).
- [`SalesChannel` data model \<\> `StockLocation` data model of the Stock Location Module](#stock-location-module).
---
## API Key Module ## API Key Module
A publishable API key allows you to easily specify the sales channel scope in a client request. A publishable API key allows you to easily specify the sales channel scope in a client request.
@@ -14,6 +34,179 @@ Medusa defines a link between the `ApiKey` and the `SalesChannel` data models.
![A diagram showcasing an example of how resources from the Sales Channel and API Key modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1709812064/Medusa%20Resources/sales-channel-api-key_zmqi2l.jpg) ![A diagram showcasing an example of how resources from the Sales Channel and API Key modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1709812064/Medusa%20Resources/sales-channel-api-key_zmqi2l.jpg)
### Retrieve with Query
To retrieve the API keys associated with a sales channel with [Query](!docs!/learn/fundamentals/module-links/query), pass `publishable_api_keys.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: salesChannels } = await query.graph({
entity: "sales_channel",
fields: [
"publishable_api_keys.*"
]
})
// salesChannels.publishable_api_keys
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: salesChannels } = useQueryGraphStep({
entity: "sales_channel",
fields: [
"publishable_api_keys.*"
]
})
// salesChannels.publishable_api_keys
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the sales channels of an API key, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.API_KEY]: {
api_key_id: "apk_123",
},
[Modules.SALES_CHANNEL]: {
sales_channel_id: "sc_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"
// ...
createRemoteLinkStep({
[Modules.API_KEY]: {
api_key_id: "apk_123",
},
[Modules.SALES_CHANNEL]: {
sales_channel_id: "sc_123",
},
})
```
</CodeTab>
</CodeTabs>
---
## Cart Module
Medusa defines a read-only link between the `SalesChannel` data model and the [Cart Module](../../cart/page.mdx)'s `SalesChannel` data model. This means you can retrieve the details of a sales channel's carts, but you don't manage the links in a pivot table in the database. The sales channel of a cart is determined by the `sales_channel_id` property of the `Cart` data model.
### Retrieve with Query
To retrieve the carts of a sales channel with [Query](!docs!/learn/fundamentals/module-links/query), pass `carts.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: salesChannels } = await query.graph({
entity: "sales_channel",
fields: [
"carts.*"
]
})
// salesChannels.carts
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: salesChannels } = useQueryGraphStep({
entity: "sales_channel",
fields: [
"carts.*"
]
})
// salesChannels.carts
```
</CodeTab>
</CodeTabs>
---
## Order Module
Medusa defines a read-only link between the `SalesChannel` data model and the [Order Module](../../order/page.mdx)'s `Order` data model. This means you can retrieve the details of a sales channel's orders, but you don't manage the links in a pivot table in the database. The sales channel of an order is determined by the `sales_channel_id` property of the `Order` data model.
### Retrieve with Query
To retrieve the orders of a sales channel with [Query](!docs!/learn/fundamentals/module-links/query), pass `orders.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: salesChannels } = await query.graph({
entity: "sales_channel",
fields: [
"orders.*"
]
})
// salesChannels.orders
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: salesChannels } = useQueryGraphStep({
entity: "sales_channel",
fields: [
"orders.*"
]
})
// salesChannels.orders
```
</CodeTab>
</CodeTabs>
--- ---
## Product Module ## Product Module
@@ -24,6 +217,89 @@ A product has different availability for different sales channels. Medusa define
A product can be available in more than one sales channel. You can retrieve only the products of a sales channel. A product can be available in more than one sales channel. You can retrieve only the products of a sales channel.
### Retrieve with Query
To retrieve the products of a sales channel 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: salesChannels } = await query.graph({
entity: "sales_channel",
fields: [
"products.*"
]
})
// salesChannels.products
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: salesChannels } = useQueryGraphStep({
entity: "sales_channel",
fields: [
"products.*"
]
})
// salesChannels.products
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the sales channels of a product, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.PRODUCT]: {
product_id: "prod_123",
},
[Modules.SALES_CHANNEL]: {
sales_channel_id: "sc_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.SALES_CHANNEL]: {
sales_channel_id: "sc_123",
},
})
```
</CodeTab>
</CodeTabs>
--- ---
## Stock Location Module ## Stock Location Module
@@ -33,3 +309,86 @@ A stock location is associated with a sales channel. This scopes inventory quant
Medusa defines a link between the `SalesChannel` and `StockLocation` data models. 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](https://res.cloudinary.com/dza7lstvk/image/upload/v1716796872/Medusa%20Resources/sales-channel-location_cqrih1.jpg) ![A diagram showcasing an example of how resources from the Sales Channel and Stock Location modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716796872/Medusa%20Resources/sales-channel-location_cqrih1.jpg)
### Retrieve with Query
To retrieve the stock locations of a sales channel with [Query](!docs!/learn/fundamentals/module-links/query), pass `stock_locations.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: salesChannels } = await query.graph({
entity: "sales_channel",
fields: [
"stock_locations.*"
]
})
// salesChannels.stock_locations
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: salesChannels } = useQueryGraphStep({
entity: "sales_channel",
fields: [
"stock_locations.*"
]
})
// salesChannels.stock_locations
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the stock locations of a sales channel, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.SALES_CHANNEL]: {
sales_channel_id: "sc_123",
},
[Modules.STOCK_LOCATION]: {
sales_channel_id: "sloc_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
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",
},
})
```
</CodeTab>
</CodeTabs>
@@ -1,3 +1,5 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = { export const metadata = {
title: `Links between Stock Location Module and Other Modules`, title: `Links between Stock Location Module and Other Modules`,
} }
@@ -6,6 +8,23 @@ export const metadata = {
This document showcases the module links defined between the Stock Location Module and other commerce 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:
<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>
- [`FulfillmentSet` data model of the Fulfillment Module \<\> `StockLocation` data model](#fulfillment-module).
- [`FulfillmentProvider` data model of the Fulfillment Module \<\> `StockLocation` data model](#fulfillment-module).
- [`StockLocation` data model \<\> `Inventory` data model of the Inventory Module](#inventory-module).
- [`SalesChannel` data model of the Sales Channel Module \<\> `StockLocation` data model](#sales-channel-module).
---
## Fulfillment Module ## Fulfillment Module
A fulfillment set can be conditioned to a specific stock location. A fulfillment set can be conditioned to a specific stock location.
@@ -18,6 +37,140 @@ Medusa also defines a link between the `FulfillmentProvider` and `StockLocation`
![A diagram showcasing an example of how data models from the Fulfillment and Stock Location modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1728399492/Medusa%20Resources/fulfillment-provider-stock-location_b0mulo.jpg) ![A diagram showcasing an example of how data models from the Fulfillment and Stock Location modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1728399492/Medusa%20Resources/fulfillment-provider-stock-location_b0mulo.jpg)
### Retrieve with Query
To retrieve the fulfillment sets of a stock location with [Query](!docs!/learn/fundamentals/module-links/query), pass `fulfillment_sets.*` in `fields`:
<Note>
To retrieve the fulfillment providers, pass `fulfillment_providers.*` in `fields`.
</Note>
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: stockLocations } = await query.graph({
entity: "stock_location",
fields: [
"fulfillment_sets.*"
]
})
// stockLocations.fulfillment_sets
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: stockLocations } = useQueryGraphStep({
entity: "stock_location",
fields: [
"fulfillment_sets.*"
]
})
// stockLocations.fulfillment_sets
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the stock location of a fulfillment set, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.STOCK_LOCATION]: {
stock_location_id: "sloc_123",
},
[Modules.FULFILLMENT]: {
fulfillment_set_id: "fset_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
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",
},
})
```
</CodeTab>
</CodeTabs>
---
## Inventory Module
Medusa defines a read-only link between the `StockLocation` data model and the [Inventory Module](../../inventory/page.mdx)'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](!docs!/learn/fundamentals/module-links/query), pass `inventory_levels.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: stockLocations } = await query.graph({
entity: "stock_location",
fields: [
"inventory_levels.*"
]
})
// stockLocations.inventory_levels
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: stockLocations } = useQueryGraphStep({
entity: "stock_location",
fields: [
"inventory_levels.*"
]
})
// stockLocations.inventory_levels
```
</CodeTab>
</CodeTabs>
--- ---
## Sales Channel Module ## Sales Channel Module
@@ -27,3 +180,86 @@ A stock location is associated with a sales channel. This scopes inventory quant
Medusa defines a link between the `SalesChannel` and `StockLocation` data models. 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](https://res.cloudinary.com/dza7lstvk/image/upload/v1716796872/Medusa%20Resources/sales-channel-location_cqrih1.jpg) ![A diagram showcasing an example of how resources from the Sales Channel and Stock Location modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1716796872/Medusa%20Resources/sales-channel-location_cqrih1.jpg)
### Retrieve with Query
To retrieve the sales channels of a stock location with [Query](!docs!/learn/fundamentals/module-links/query), pass `sales_channels.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: stockLocations } = await query.graph({
entity: "stock_location",
fields: [
"sales_channels.*"
]
})
// stockLocations.sales_channels
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: stockLocations } = useQueryGraphStep({
entity: "stock_location",
fields: [
"sales_channels.*"
]
})
// stockLocations.sales_channels
```
</CodeTab>
</CodeTabs>
### Manage with Remote Link
To manage the stock locations of a sales channel, use [Remote Link](!docs!/learn/fundamentals/module-links/remote-link):
<CodeTabs group="relation-link">
<CodeTab label="remoteLink.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await remoteLink.create({
[Modules.SALES_CHANNEL]: {
sales_channel_id: "sc_123",
},
[Modules.STOCK_LOCATION]: {
sales_channel_id: "sloc_123",
},
})
```
</CodeTab>
<CodeTab label="createRemoteLinkStep" value="step">
```ts
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",
},
})
```
</CodeTab>
</CodeTabs>
@@ -0,0 +1,68 @@
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = {
title: `Links between Store Module and Other Modules`,
}
# {metadata.title}
This document showcases the module links defined between the Store Module and other commerce modules.
## Summary
The Store 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>
- [`Currency` data model \<\> `Currency` data model of Currency Module](#currency-module). (Read-only).
---
## Currency Module
The Store Module has a `Currency` data model that stores the supported currencies of a store. However, these currencies don't hold all the details of a currency, such as its name or symbol.
Instead, Medusa defines a read-only link between the [Currency Module](../../currency/page.mdx)'s `Currency` data model and the Store Module's `Currency` data model. This means you can retrieve the details of a store's supported currencies, but you don't manage the links in a pivot table in the database. The currencies of a store are determined by the `currency_code` of the `Currency` data model in the Store Module.
### Retrieve with Query
To retrieve the details of a store's currencies with [Query](!docs!/learn/fundamentals/module-links/query), pass `supported_currencies.currency.*` in `fields`:
<CodeTabs group="relation-query">
<CodeTab label="query.graph" value="method">
```ts
const { data: stores } = await query.graph({
entity: "store",
fields: [
"supported_currencies.currency.*"
]
})
// stores.supported_currencies
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: stores } = useQueryGraphStep({
entity: "store",
fields: [
"supported_currencies.currency.*"
]
})
// stores.supported_currencies
```
</CodeTab>
</CodeTabs>
+16 -14
View File
@@ -2148,21 +2148,21 @@ export const generatedEditDates = {
"app/admin-components/components/forms/page.mdx": "2024-10-09T12:48:04.229Z", "app/admin-components/components/forms/page.mdx": "2024-10-09T12:48:04.229Z",
"app/commerce-modules/auth/reset-password/page.mdx": "2024-11-27T13:33:55.940Z", "app/commerce-modules/auth/reset-password/page.mdx": "2024-11-27T13:33:55.940Z",
"app/storefront-development/customers/reset-password/page.mdx": "2024-12-19T16:32:00.724Z", "app/storefront-development/customers/reset-password/page.mdx": "2024-12-19T16:32:00.724Z",
"app/commerce-modules/api-key/links-to-other-modules/page.mdx": "2024-10-08T08:05:36.596Z", "app/commerce-modules/api-key/links-to-other-modules/page.mdx": "2024-12-24T14:36:06.109Z",
"app/commerce-modules/cart/extend/page.mdx": "2024-12-11T09:05:37.041Z", "app/commerce-modules/cart/extend/page.mdx": "2024-12-11T09:05:37.041Z",
"app/commerce-modules/cart/links-to-other-modules/page.mdx": "2024-10-08T08:22:35.190Z", "app/commerce-modules/cart/links-to-other-modules/page.mdx": "2024-12-24T14:46:49.847Z",
"app/commerce-modules/customer/extend/page.mdx": "2024-12-16T14:11:47.517Z", "app/commerce-modules/customer/extend/page.mdx": "2024-12-16T14:11:47.517Z",
"app/commerce-modules/fulfillment/links-to-other-modules/page.mdx": "2024-10-08T14:58:24.935Z", "app/commerce-modules/fulfillment/links-to-other-modules/page.mdx": "2024-12-24T14:49:54.535Z",
"app/commerce-modules/inventory/links-to-other-modules/page.mdx": "2024-10-08T15:18:30.109Z", "app/commerce-modules/inventory/links-to-other-modules/page.mdx": "2024-12-24T14:50:25.574Z",
"app/commerce-modules/pricing/links-to-other-modules/page.mdx": "2024-10-09T13:51:49.986Z", "app/commerce-modules/pricing/links-to-other-modules/page.mdx": "2024-12-24T14:53:39.198Z",
"app/commerce-modules/product/extend/page.mdx": "2024-12-11T09:07:25.252Z", "app/commerce-modules/product/extend/page.mdx": "2024-12-11T09:07:25.252Z",
"app/commerce-modules/product/links-to-other-modules/page.mdx": "2024-10-09T14:14:09.401Z", "app/commerce-modules/product/links-to-other-modules/page.mdx": "2024-12-24T14:55:21.779Z",
"app/commerce-modules/promotion/extend/page.mdx": "2024-12-11T09:07:24.137Z", "app/commerce-modules/promotion/extend/page.mdx": "2024-12-11T09:07:24.137Z",
"app/commerce-modules/promotion/links-to-other-modules/page.mdx": "2024-10-09T14:51:37.194Z", "app/commerce-modules/promotion/links-to-other-modules/page.mdx": "2024-12-24T14:56:11.410Z",
"app/commerce-modules/order/edit/page.mdx": "2024-10-09T08:50:05.334Z", "app/commerce-modules/order/edit/page.mdx": "2024-10-09T08:50:05.334Z",
"app/commerce-modules/order/links-to-other-modules/page.mdx": "2024-10-09T11:23:05.488Z", "app/commerce-modules/order/links-to-other-modules/page.mdx": "2024-12-24T14:52:22.813Z",
"app/commerce-modules/order/order-change/page.mdx": "2024-10-09T09:59:40.745Z", "app/commerce-modules/order/order-change/page.mdx": "2024-10-09T09:59:40.745Z",
"app/commerce-modules/payment/links-to-other-modules/page.mdx": "2024-10-09T11:23:02.023Z", "app/commerce-modules/payment/links-to-other-modules/page.mdx": "2024-12-24T14:53:08.217Z",
"references/core_flows/Common/Steps_Common/functions/core_flows.Common.Steps_Common.useQueryGraphStep/page.mdx": "2024-12-23T12:30:23.699Z", "references/core_flows/Common/Steps_Common/functions/core_flows.Common.Steps_Common.useQueryGraphStep/page.mdx": "2024-12-23T12:30:23.699Z",
"references/core_flows/Payment/Workflows_Payment/functions/core_flows.Payment.Workflows_Payment.processPaymentWorkflow/page.mdx": "2024-12-23T12:30:26.014Z", "references/core_flows/Payment/Workflows_Payment/functions/core_flows.Payment.Workflows_Payment.processPaymentWorkflow/page.mdx": "2024-12-23T12:30:26.014Z",
"references/helper_steps/functions/helper_steps.useQueryGraphStep/page.mdx": "2024-12-10T14:55:09.191Z", "references/helper_steps/functions/helper_steps.useQueryGraphStep/page.mdx": "2024-12-10T14:55:09.191Z",
@@ -2211,10 +2211,10 @@ export const generatedEditDates = {
"references/fulfillment/interfaces/fulfillment.IFulfillmentModuleService/page.mdx": "2024-12-17T16:57:25.097Z", "references/fulfillment/interfaces/fulfillment.IFulfillmentModuleService/page.mdx": "2024-12-17T16:57:25.097Z",
"references/types/CommonTypes/interfaces/types.CommonTypes.RequestQueryFields/page.mdx": "2024-12-09T13:21:32.865Z", "references/types/CommonTypes/interfaces/types.CommonTypes.RequestQueryFields/page.mdx": "2024-12-09T13:21:32.865Z",
"references/utils/utils.ProductUtils/page.mdx": "2024-12-10T14:54:57.156Z", "references/utils/utils.ProductUtils/page.mdx": "2024-12-10T14:54:57.156Z",
"app/commerce-modules/region/links-to-other-modules/page.mdx": "2024-10-15T14:10:50.853Z", "app/commerce-modules/region/links-to-other-modules/page.mdx": "2024-12-24T14:56:43.092Z",
"app/commerce-modules/sales-channel/links-to-other-modules/page.mdx": "2024-10-15T14:25:29.097Z", "app/commerce-modules/sales-channel/links-to-other-modules/page.mdx": "2024-12-24T14:57:34.314Z",
"app/commerce-modules/stock-location/links-to-other-modules/page.mdx": "2024-10-15T14:33:11.483Z", "app/commerce-modules/stock-location/links-to-other-modules/page.mdx": "2024-12-24T14:58:09.715Z",
"app/commerce-modules/store/links-to-other-modules/page.mdx": "2024-06-26T07:19:49.931Z", "app/commerce-modules/store/links-to-other-modules/page.mdx": "2024-12-24T14:58:24.038Z",
"app/examples/page.mdx": "2024-12-11T09:07:47.589Z", "app/examples/page.mdx": "2024-12-11T09:07:47.589Z",
"app/medusa-cli/commands/build/page.mdx": "2024-11-11T11:00:49.665Z", "app/medusa-cli/commands/build/page.mdx": "2024-11-11T11:00:49.665Z",
"app/js-sdk/page.mdx": "2024-12-12T11:41:51.152Z", "app/js-sdk/page.mdx": "2024-12-12T11:41:51.152Z",
@@ -5779,5 +5779,7 @@ export const generatedEditDates = {
"app/commerce-modules/stock-location/admin-widget-zones/page.mdx": "2024-12-24T08:38:38.403Z", "app/commerce-modules/stock-location/admin-widget-zones/page.mdx": "2024-12-24T08:38:38.403Z",
"app/commerce-modules/store/admin-widget-zones/page.mdx": "2024-12-24T08:46:28.646Z", "app/commerce-modules/store/admin-widget-zones/page.mdx": "2024-12-24T08:46:28.646Z",
"app/commerce-modules/tax/admin-widget-zones/page.mdx": "2024-12-24T08:47:13.176Z", "app/commerce-modules/tax/admin-widget-zones/page.mdx": "2024-12-24T08:47:13.176Z",
"app/commerce-modules/user/admin-widget-zones/page.mdx": "2024-12-24T08:48:14.186Z" "app/commerce-modules/user/admin-widget-zones/page.mdx": "2024-12-24T08:48:14.186Z",
"app/commerce-modules/currency/links-to-other-modules/page.mdx": "2024-12-24T14:47:10.556Z",
"app/commerce-modules/customer/links-to-other-modules/page.mdx": "2024-12-24T14:48:54.689Z"
} }
@@ -231,6 +231,10 @@ export const filesMap = [
"filePath": "/www/apps/resources/app/commerce-modules/currency/examples/page.mdx", "filePath": "/www/apps/resources/app/commerce-modules/currency/examples/page.mdx",
"pathname": "/commerce-modules/currency/examples" "pathname": "/commerce-modules/currency/examples"
}, },
{
"filePath": "/www/apps/resources/app/commerce-modules/currency/links-to-other-modules/page.mdx",
"pathname": "/commerce-modules/currency/links-to-other-modules"
},
{ {
"filePath": "/www/apps/resources/app/commerce-modules/currency/page.mdx", "filePath": "/www/apps/resources/app/commerce-modules/currency/page.mdx",
"pathname": "/commerce-modules/currency" "pathname": "/commerce-modules/currency"
@@ -255,6 +259,10 @@ export const filesMap = [
"filePath": "/www/apps/resources/app/commerce-modules/customer/extend/page.mdx", "filePath": "/www/apps/resources/app/commerce-modules/customer/extend/page.mdx",
"pathname": "/commerce-modules/customer/extend" "pathname": "/commerce-modules/customer/extend"
}, },
{
"filePath": "/www/apps/resources/app/commerce-modules/customer/links-to-other-modules/page.mdx",
"pathname": "/commerce-modules/customer/links-to-other-modules"
},
{ {
"filePath": "/www/apps/resources/app/commerce-modules/customer/page.mdx", "filePath": "/www/apps/resources/app/commerce-modules/customer/page.mdx",
"pathname": "/commerce-modules/customer" "pathname": "/commerce-modules/customer"
@@ -591,6 +599,10 @@ export const filesMap = [
"filePath": "/www/apps/resources/app/commerce-modules/store/examples/page.mdx", "filePath": "/www/apps/resources/app/commerce-modules/store/examples/page.mdx",
"pathname": "/commerce-modules/store/examples" "pathname": "/commerce-modules/store/examples"
}, },
{
"filePath": "/www/apps/resources/app/commerce-modules/store/links-to-other-modules/page.mdx",
"pathname": "/commerce-modules/store/links-to-other-modules"
},
{ {
"filePath": "/www/apps/resources/app/commerce-modules/store/page.mdx", "filePath": "/www/apps/resources/app/commerce-modules/store/page.mdx",
"pathname": "/commerce-modules/store" "pathname": "/commerce-modules/store"
+40
View File
@@ -1324,6 +1324,22 @@ export const generatedSidebar = [
"title": "Examples", "title": "Examples",
"children": [] "children": []
}, },
{
"loaded": true,
"isPathHref": true,
"type": "sub-category",
"title": "Concepts",
"children": [
{
"loaded": true,
"isPathHref": true,
"type": "link",
"path": "/commerce-modules/currency/links-to-other-modules",
"title": "Link to Modules",
"children": []
}
]
},
{ {
"loaded": true, "loaded": true,
"isPathHref": true, "isPathHref": true,
@@ -1450,6 +1466,14 @@ export const generatedSidebar = [
"path": "/commerce-modules/customer/customer-accounts", "path": "/commerce-modules/customer/customer-accounts",
"title": "Customer Accounts", "title": "Customer Accounts",
"children": [] "children": []
},
{
"loaded": true,
"isPathHref": true,
"type": "link",
"path": "/commerce-modules/customer/links-to-other-modules",
"title": "Link to Modules",
"children": []
} }
] ]
}, },
@@ -7215,6 +7239,22 @@ export const generatedSidebar = [
"title": "Examples", "title": "Examples",
"children": [] "children": []
}, },
{
"loaded": true,
"isPathHref": true,
"type": "sub-category",
"title": "Concepts",
"children": [
{
"loaded": true,
"isPathHref": true,
"type": "link",
"path": "/commerce-modules/store/links-to-other-modules",
"title": "Link to Modules",
"children": []
}
]
},
{ {
"loaded": true, "loaded": true,
"isPathHref": true, "isPathHref": true,
+11
View File
@@ -15,6 +15,17 @@ export const currencySidebar = [
path: "/commerce-modules/currency/examples", path: "/commerce-modules/currency/examples",
title: "Examples", title: "Examples",
}, },
{
type: "sub-category",
title: "Concepts",
children: [
{
type: "link",
path: "/commerce-modules/currency/links-to-other-modules",
title: "Link to Modules",
},
],
},
{ {
type: "sub-category", type: "sub-category",
title: "References", title: "References",
+5
View File
@@ -29,6 +29,11 @@ export const customerSidebar = [
path: "/commerce-modules/customer/customer-accounts", path: "/commerce-modules/customer/customer-accounts",
title: "Customer Accounts", title: "Customer Accounts",
}, },
{
type: "link",
path: "/commerce-modules/customer/links-to-other-modules",
title: "Link to Modules",
},
], ],
}, },
{ {
+11
View File
@@ -15,6 +15,17 @@ export const storeSidebar = [
path: "/commerce-modules/store/examples", path: "/commerce-modules/store/examples",
title: "Examples", title: "Examples",
}, },
{
type: "sub-category",
title: "Concepts",
children: [
{
type: "link",
path: "/commerce-modules/store/links-to-other-modules",
title: "Link to Modules",
},
],
},
{ {
type: "sub-category", type: "sub-category",
title: "References", title: "References",