Files
Shahed Nasser 009d00f27d docs: redesign table of content (#12647)
* implement toc

* added to projects

* fixes and adapt for references

* added product frontmatter

* remove action menu from 404 pages
2025-05-30 16:55:36 +03:00

272 lines
5.8 KiB
Plaintext

---
products:
- cart
- order
- payment
---
import { CodeTabs, CodeTab, Table } from "docs-ui"
export const metadata = {
title: `Links between Region Module and Other Modules`,
}
# {metadata.title}
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>
<Table>
<Table.Header>
<Table.Row>
<Table.HeaderCell>
First Data Model
</Table.HeaderCell>
<Table.HeaderCell>
Second Data Model
</Table.HeaderCell>
<Table.HeaderCell>
Type
</Table.HeaderCell>
<Table.HeaderCell>
Description
</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>
[Cart](/references/cart/models/Cart) in [Cart Module](../../cart/page.mdx)
</Table.Cell>
<Table.Cell>
[Region](/references/region/models/Region)
</Table.Cell>
<Table.Cell>
Read-only - has one
</Table.Cell>
<Table.Cell>
[Learn more](#cart-module)
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
[Order](/references/order/models/Order) in [Order Module](../../order/page.mdx)
</Table.Cell>
<Table.Cell>
[Region](/references/region/models/Region)
</Table.Cell>
<Table.Cell>
Read-only - has one
</Table.Cell>
<Table.Cell>
[Learn more](#order-module)
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
[Region](/references/region/models/Region)
</Table.Cell>
<Table.Cell>
[PaymentProvider](/references/payment/models/PaymentProvider) in [Payment Module](../../payment/page.mdx)
</Table.Cell>
<Table.Cell>
Stored - many-to-many
</Table.Cell>
<Table.Cell>
[Learn more](#payment-module)
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
---
## Cart Module
Medusa defines a read-only link between the [Cart Module](../../cart/page.mdx)'s `Cart` data model and the `Region` data model. Because the link is read-only from the `Cart`'s side, you can only retrieve the region of a cart, and not the other way around.
### 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[0].region
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: carts } = useQueryGraphStep({
entity: "cart",
fields: [
"region.*",
],
})
// carts[0].region
```
</CodeTab>
</CodeTabs>
---
## Order Module
Medusa defines a read-only link between the [Order Module](../../order/page.mdx)'s `Order` data model and the `Region` data model. Because the link is read-only from the `Order`'s side, you can only retrieve the region of an order, and not the other way around.
### 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[0].region
```
</CodeTab>
<CodeTab label="useQueryGraphStep" value="step">
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: orders } = useQueryGraphStep({
entity: "order",
fields: [
"region.*",
],
})
// orders[0].region
```
</CodeTab>
</CodeTabs>
---
## Payment Module
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.
![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[0].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[0].payment_providers
```
</CodeTab>
</CodeTabs>
### Manage with Link
To manage the payment providers in a region, use [Link](!docs!/learn/fundamentals/module-links/link):
<CodeTabs group="relation-link">
<CodeTab label="link.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await link.create({
[Modules.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>