docs: improved commerce module docs [2/n] (#9501)
Improve + add docs for commerce modules from currency to inventory [2/n]
This commit is contained in:
@@ -13,16 +13,15 @@ In this guide, you’ll find common examples of how you can use the Currency Mod
|
||||
<CodeTabs groupId="app-type">
|
||||
<CodeTab label="Medusa API Router" value="medusa">
|
||||
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { ICurrencyModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export async function GET(
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
): Promise<void> {
|
||||
const currencyModuleService: ICurrencyModuleService = req.scope.resolve(
|
||||
const currencyModuleService = req.scope.resolve(
|
||||
Modules.CURRENCY
|
||||
)
|
||||
|
||||
@@ -59,16 +58,15 @@ export async function GET(request: Request) {
|
||||
<CodeTabs groupId="app-type">
|
||||
<CodeTab label="Medusa API Router" value="medusa">
|
||||
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { ICurrencyModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export async function GET(
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
): Promise<void> {
|
||||
const currencyModuleService: ICurrencyModuleService = req.scope.resolve(
|
||||
const currencyModuleService = req.scope.resolve(
|
||||
Modules.CURRENCY
|
||||
)
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ export const metadata = {
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
The Currency Module is the `@medusajs/medusa/currency` NPM package that provides currency-related features in your Medusa and Node.js applications.
|
||||
The Currency Module provides currency-related features in your Medusa and Node.js applications.
|
||||
|
||||
## How to Use Currency Module's Service
|
||||
|
||||
@@ -15,18 +15,33 @@ You can use the Currency Module's main service by resolving from the Medusa cont
|
||||
For example:
|
||||
|
||||
<CodeTabs groupId="resource-type">
|
||||
<CodeTab label="Workflow Step" value="workflow-step">
|
||||
|
||||
```ts title="src/workflows/hello-world/step1.ts"
|
||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
const step1 = createStep("step-1", async (_, { container }) => {
|
||||
const currencyModuleService = container.resolve(
|
||||
Modules.CURRENCY
|
||||
)
|
||||
|
||||
const currencies = await currencyModuleService.listCurrencies()
|
||||
})
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
<CodeTab label="API Route" value="api-route">
|
||||
|
||||
```ts title="src/api/store/custom/route.ts"
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { ICurrencyModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts title="src/api/store/custom/route.ts"
|
||||
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export async function GET(
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
): Promise<void> {
|
||||
const currencyModuleService: ICurrencyModuleService = req.scope.resolve(
|
||||
const currencyModuleService = req.scope.resolve(
|
||||
Modules.CURRENCY
|
||||
)
|
||||
|
||||
@@ -39,35 +54,17 @@ export async function GET(
|
||||
</CodeTab>
|
||||
<CodeTab label="Subscriber" value="subscribers">
|
||||
|
||||
```ts title="src/subscribers/custom-handler.ts"
|
||||
import { SubscriberArgs } from "@medusajs/framework"
|
||||
import { ICurrencyModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
```ts title="src/subscribers/custom-handler.ts"
|
||||
import { SubscriberArgs } from "@medusajs/framework"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
export default async function subscriberHandler({ container }: SubscriberArgs) {
|
||||
const currencyModuleService: ICurrencyModuleService = container.resolve(
|
||||
const currencyModuleService = container.resolve(
|
||||
Modules.CURRENCY
|
||||
)
|
||||
|
||||
const currencies = await currencyModuleService.listCurrencies()
|
||||
}
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
<CodeTab label="Workflow Step" value="workflow-step">
|
||||
|
||||
```ts title="src/workflows/hello-world/step1.ts"
|
||||
import { createStep } from "@medusajs/framework/workflows-sdk"
|
||||
import { ICurrencyModuleService } from "@medusajs/framework/types"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
|
||||
const step1 = createStep("step-1", async (_, { container }) => {
|
||||
const currencyModuleService: ICurrencyModuleService = container.resolve(
|
||||
Modules.CURRENCY
|
||||
)
|
||||
|
||||
const currencies = await currencyModuleService.listCurrencies()
|
||||
})
|
||||
```
|
||||
|
||||
</CodeTab>
|
||||
@@ -87,12 +84,12 @@ const currency = await currencyModuleService.retrieveCurrency("usd")
|
||||
|
||||
### Support Currencies in Modules
|
||||
|
||||
Other commerce modules use currency codes in their data models or operations. You can use the Currency Module to retrieve a currency code and its details.
|
||||
Other commerce modules use currency codes in their data models or operations. Use the Currency Module to retrieve a currency code and its details.
|
||||
|
||||
An example with the Region Module:
|
||||
|
||||
```ts
|
||||
const region = await regionModuleService.retrieveCurrency("reg_123")
|
||||
const region = await regionModuleService.retrieveRegion("reg_123")
|
||||
const currency = await currencyModuleService.retrieveCurrency(
|
||||
region.currency_code
|
||||
)
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
export const metadata = {
|
||||
title: `Relations between Currency Module and Other Modules`,
|
||||
}
|
||||
|
||||
# {metadata.title}
|
||||
|
||||
This document showcases the link modules defined between the Currency Module and other commerce modules.
|
||||
|
||||
## Store Module
|
||||
|
||||
A store has a default currency. Medusa defines a link module that builds a relationship between the `Store` and `Currency` data models.
|
||||
|
||||

|
||||
Reference in New Issue
Block a user