Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improved commerce modules [5/5] #9592

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export const metadata = {

In this guide, you’ll find common examples of how you can use the API Key Module in your application.

<Note>

You should only use the API Key Module's main service when implementing complex customizations. For common cases, check out [available workflows instead](../../../medusa-workflows-reference/page.mdx).

</Note>

## Create an API Key

<CodeTabs groupId="app-type">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export const metadata = {

In this guide, you’ll find common examples of how you can use the Auth Module in your application.

<Note>

You should only use the Auth Module's main service when implementing complex customizations. For common cases, check out [available workflows instead](../../../medusa-workflows-reference/page.mdx).

</Note>

## Authenticate User

<Note>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export const metadata = {

In this guide, you’ll find common examples of how you can use the Cart Module in your application.

<Note>

You should only use the Cart Module's main service when implementing complex customizations. For common cases, check out [available workflows instead](../../../medusa-workflows-reference/page.mdx).

</Note>

## Create a Cart

<CodeTabs groupId="app-type">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export const metadata = {

In this guide, you’ll find common examples of how you can use the Currency Module in your application.

<Note>

You should only use the Currency Module's main service when implementing complex customizations. For common cases, check out [available workflows instead](../../../medusa-workflows-reference/page.mdx).

</Note>

## List Currencies

<CodeTabs groupId="app-type">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export const metadata = {

In this guide, you’ll find common examples of how you can use the Customer Module in your application.

<Note>

You should only use the Customer Module's main service when implementing complex customizations. For common cases, check out [available workflows instead](../../../medusa-workflows-reference/page.mdx).

</Note>

## Create a Customer

<CodeTabs groupId="app-type">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export const metadata = {

In this document, you’ll find common examples of how you can use the Inventory Module in your application.

<Note>

You should only use the Inventory Module's main service when implementing complex customizations. For common cases, check out [available workflows instead](../../../medusa-workflows-reference/page.mdx).

</Note>

## Create an Inventory Item

<CodeTabs groupId="app-type">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export const metadata = {

In this guide, you’ll find common examples of how you can use the Payment Module in your application.

<Note>

You should only use the Payment Module's main service when implementing complex customizations. For common cases, check out [available workflows instead](../../../medusa-workflows-reference/page.mdx).

</Note>

## Create a Payment Collection

<CodeTabs groupId="app-type">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export const metadata = {

In this document, you’ll find common examples of how you can use the Pricing Module in your application.

<Note>

You should only use the Pricing Module's main service when implementing complex customizations. For common cases, check out [available workflows instead](../../../medusa-workflows-reference/page.mdx).

</Note>

## Create a Price Set

<CodeTabs groupId="app-type">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export const metadata = {

In this guide, you’ll find common examples of how you can use the Product Module in your application.

<Note>

You should only use the Product Module's main service when implementing complex customizations. For common cases, check out [available workflows instead](../../../medusa-workflows-reference/page.mdx).

</Note>

## Create Product

<CodeTabs groupId="app-type">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export const metadata = {

In this document, you’ll find common examples of how you can use the Promotion Module in your application.

<Note>

You should only use the Promotion Module's main service when implementing complex customizations. For common cases, check out [available workflows instead](../../../medusa-workflows-reference/page.mdx).

</Note>

## Create a Promotion

<CodeTabs groupId="app-type">
Expand Down
51 changes: 26 additions & 25 deletions www/apps/resources/app/commerce-modules/region/examples/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@ export const metadata = {

In this guide, you’ll find common examples of how you can use the Region Module in your application.

<Note>

You should only use the Region Module's main service when implementing complex customizations. For common cases, check out [available workflows instead](../../../medusa-workflows-reference/page.mdx).

</Note>

## Create a Region

<CodeTabs groupId="app-type">
<CodeTab label="Medusa API Router" value="medusa">

```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { IRegionModuleService } 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 POST(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const regionModuleService: IRegionModuleService = req.scope.resolve(
const regionModuleService = req.scope.resolve(
Modules.REGION
)

Expand Down Expand Up @@ -69,16 +74,15 @@ export async function POST(request: Request) {
<CodeTabs groupId="app-type">
<CodeTab label="Medusa API Router" value="medusa">

```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { IRegionModuleService } 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 regionModuleService: IRegionModuleService = req.scope.resolve(
const regionModuleService = req.scope.resolve(
Modules.REGION
)

Expand Down Expand Up @@ -115,16 +119,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 { IRegionModuleService } 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 regionModuleService: IRegionModuleService = req.scope.resolve(
const regionModuleService = req.scope.resolve(
Modules.REGION
)

Expand Down Expand Up @@ -161,16 +164,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 { IRegionModuleService } 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 POST(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const regionModuleService: IRegionModuleService = req.scope.resolve(
const regionModuleService = req.scope.resolve(
Modules.REGION
)

Expand Down Expand Up @@ -211,16 +213,15 @@ export async function POST(request: Request) {
<CodeTabs groupId="app-type">
<CodeTab label="Medusa API Router" value="medusa">

```ts
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { IRegionModuleService } 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 DELETE(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const regionModuleService: IRegionModuleService = req.scope.resolve(
const regionModuleService = req.scope.resolve(
Modules.REGION
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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.

## 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)
53 changes: 25 additions & 28 deletions www/apps/resources/app/commerce-modules/region/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const metadata = {

# {metadata.title}

The Region Module is the `@medusajs/medusa/region` NPM package that provides region-related features in your Medusa and Node.js applications.
The Region Module provides region-related features in your Medusa and Node.js applications.

## How to Use Region Module's Service

Expand All @@ -15,18 +15,33 @@ You can use the Region Module's main service by resolving from the Medusa contai
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 regionModuleService = container.resolve(
Modules.REGION
)

const regions = await regionModuleService.listRegions()
})
```

</CodeTab>
<CodeTab label="API Route" value="api-route">

```ts title="src/api/store/custom/route.ts"
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { IRegionModuleService } 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 regionModuleService: IRegionModuleService = req.scope.resolve(
const regionModuleService = req.scope.resolve(
Modules.REGION
)

Expand All @@ -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 { IRegionModuleService } 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 regionModuleService: IRegionModuleService = container.resolve(
const regionModuleService = container.resolve(
Modules.REGION
)

const regions = await regionModuleService.listRegions()
}
```

</CodeTab>
<CodeTab label="Workflow Step" value="workflow-step">

```ts title="src/workflows/hello-world/step1.ts"
import { createStep } from "@medusajs/framework/workflows-sdk"
import { IRegionModuleService } from "@medusajs/framework/types"
import { Modules } from "@medusajs/framework/utils"

const step1 = createStep("step-1", async (_, { container }) => {
const regionModuleService: IRegionModuleService = container.resolve(
Modules.REGION
)

const regions = await regionModuleService.listRegions()
})
```

</CodeTab>
Expand Down

This file was deleted.

Loading
Loading