Files
medusa-store/www/apps/resources/app/commerce-modules/pricing/links-to-other-modules/page.mdx
Shahed Nasser 38223e5104 docs: rename remoteLink and remoteQueryConfig (#10836)
* docs: rename remoteLink and remoteQueryConfig

* change version number
2025-01-07 14:43:12 +02:00

206 lines
4.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = {
title: `Links between Pricing Module and Other Modules`,
}
# {metadata.title}
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
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.
Medusa defines a link between the `PriceSet` and `ShippingOption` data models. A shipping option's price is stored as a price set.
![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 Link
To manage the price set of a shipping option, 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.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
The Product Module doesn't store or manage the prices of product variants.
Medusa defines a link between the `ProductVariant` and the `PriceSet`. A product variants prices are stored as prices belonging to a price set.
![A diagram showcasing an example of how data models from the Pricing and Product Module are linked. The PriceSet is linked to the ProductVariant of the Product Module.](https://res.cloudinary.com/dza7lstvk/image/upload/v1709651039/Medusa%20Resources/pricing-product_m4xaut.jpg)
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.
### 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 Link
To manage the price set of a variant, use [Link](!docs!/learn/fundamentals/module-links/link):
<CodeTabs group="relation-link">
<CodeTab label="link.create" value="method">
```ts
import { Modules } from "@medusajs/framework/utils"
// ...
await link.create({
[Modules.PRODUCT]: {
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>