docs: revise commerce modules overview pages (#10738)

* revise API Key Module overview

* revise auth module

* support ref sidebar items

* remove examples

* revise cart module

* revise currency

* revise customer module

* revise fulfillment module

* revise inventory module

* revise order module

* revise payment

* revise pricing module

* revise product module

* revise promotion module

* revise region module

* revise sales channel module

* revise stock location module

* revise store module

* revise tax module

* revise user module

* lint content + fix snippets
This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-12-26 10:32:16 +02:00
1 parent c8f9938865
commit ebca8fed28
112 files changed
+9465 -7731

No files matched your search

@@ -49,8 +49,8 @@ To retrieve the return, pass `return.*` in `fields`.
const { data: fulfillments } = await query.graph({
entity: "fulfillment",
fields: [
"order.*"
]
"order.*",
],
})
// fulfillments.order
@@ -67,8 +67,8 @@ import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
const { data: fulfillments } = useQueryGraphStep({
entity: "fulfillment",
fields: [
"order.*"
]
"order.*",
],
})
// fulfillments.order
@@ -142,8 +142,8 @@ To retrieve the price set of a shipping option with [Query](!docs!/learn/fundame
const { data: shippingOptions } = await query.graph({
entity: "shipping_option",
fields: [
"price_set.*"
]
"price_set.*",
],
})
// shippingOptions.price_set
@@ -160,8 +160,8 @@ import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
const { data: shippingOptions } = useQueryGraphStep({
entity: "shipping_option",
fields: [
"price_set.*"
]
"price_set.*",
],
})
// shippingOptions.price_set
@@ -245,8 +245,8 @@ To retrieve the stock location of a fulfillment provider, pass `locations.*` in
const { data: fulfillmentSets } = await query.graph({
entity: "fulfillment_set",
fields: [
"location.*"
]
"location.*",
],
})
// fulfillmentSets.location
@@ -263,8 +263,8 @@ import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
const { data: fulfillmentSets } = useQueryGraphStep({
entity: "fulfillment_set",
fields: [
"location.*"
]
"location.*",
],
})
// fulfillmentSets.location
@@ -6,162 +6,176 @@ export const metadata = {
# {metadata.title}
The Fulfillment Module provides fulfillment-related features in your Medusa and Node.js applications.
In this section of the documentation, you will find resources to learn more about the Fulfillment Module and how to use it in your application.
## How to Use Fulfillment Module's Service
Medusa has fulfillment related features available out-of-the-box through the Fulfillment Module. A [module](!docs!/learn/fundamentals/modules) is a standalone package that provides features for a single domain. Each of Medusa's commerce features are placed in commerce modules, such as this Fulfillment Module.
You can use the Fulfillment Module's main service by resolving from the Medusa container the resource `Modules.FULFILLMENT`.
<Note>
Learn more about why modules are isolated in [this documentation](!docs!/learn/fundamentals/modules/isolation).
</Note>
## Fulfillment Features
- [Fulfillment Management](./item-fulfillment/page.mdx): Create fulfillments and keep track of their status, items, and more.
- [Integrate Third-Party Fulfillment Providers](./fulfillment-provider/page.mdx): Create third-party fulfillment providers to provide customers with shipping options and fulfill their orders.
- [Restrict By Location and Rules](./shipping-option/page.mdx): Shipping options can be restricted to specific geographical locations. You can also specify custom rules to restrict shipping options.
- [Support Different Fulfillment Forms](./concepts/page.mdx): Support various fulfillment forms, such as shipping or pick up.
---
## How to Use the Fulfillment Module
In your Medusa application, you build flows around commerce modules. A flow is built as a [Workflow](!docs!/learn/fundamentals/workflows), which is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism.
You can build custom workflows and steps. You can also re-use Medusa's workflows and steps, which are provided by the `@medusajs/medusa/core-flows` package.
For example:
<CodeTabs groupId="resource-type">
<CodeTab label="Workflow Step" value="workflow-step">
export const highlights = [
["12", "Modules.FULFILLMENT", "Resolve the module in a step."]
]
```ts title="src/workflows/hello-world/step1.ts"
import { createStep } from "@medusajs/framework/workflows-sdk"
```ts title="src/workflows/create-fulfillment.ts" highlights={highlights}
import {
createWorkflow,
WorkflowResponse,
createStep,
StepResponse,
} from "@medusajs/framework/workflows-sdk"
import { Modules } from "@medusajs/framework/utils"
const step1 = createStep("step-1", async (_, { container }) => {
const fulfillmentModuleService = container.resolve(
Modules.FULFILLMENT
)
const createFulfillmentStep = createStep(
"create-fulfillment",
async ({}, { container }) => {
const fulfillmentModuleService = container.resolve(Modules.FULFILLMENT)
const fulfillments = await fulfillmentModuleService.listFulfillments()
})
const fulfillment = await fulfillmentModuleService.createFulfillment({
location_id: "loc_123",
provider_id: "webshipper",
delivery_address: {
country_code: "us",
city: "Strongsville",
address_1: "18290 Royalton Rd",
},
items: [
{
title: "Shirt",
sku: "SHIRT",
quantity: 1,
barcode: "123456",
},
],
labels: [],
order: {},
})
return new StepResponse({ fulfillment }, fulfillment.id)
},
async (fulfillmentId, { container }) => {
if (!fulfillmentId) {
return
}
const fulfillmentModuleService = container.resolve(Modules.FULFILLMENT)
await fulfillmentModuleService.deleteFulfillment(fulfillmentId)
}
)
export const createFulfillmentWorkflow = createWorkflow(
"create-fulfillment",
() => {
const { fulfillment } = createFulfillmentStep()
return new WorkflowResponse({
fulfillment,
})
}
)
```
</CodeTab>
<CodeTab label="API Route" value="api-route">
You can then execute the workflow in your custom API routes, scheduled jobs, or subscribers:
```ts title="src/api/store/custom/route.ts"
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { Modules } from "@medusajs/framework/utils"
<CodeTabs group="resource-types">
<CodeTab label="API Route" value="api-route">
```ts title="src/api/workflow/route.ts" highlights={[["11"], ["12"]]} collapsibleLines="1-6" expandButtonLabel="Show Imports"
import type {
MedusaRequest,
MedusaResponse,
} from "@medusajs/framework/http"
import { createFulfillmentWorkflow } from "../../workflows/create-fuilfillment"
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const fulfillmentModuleService = req.scope.resolve(
Modules.FULFILLMENT
)
) {
const { result } = await createFulfillmentWorkflow(req.scope)
.run()
res.json({
fulfillments: await fulfillmentModuleService.listFulfillments(),
})
res.send(result)
}
```
</CodeTab>
<CodeTab label="Subscriber" value="subscribers">
<CodeTab label="Subscriber" value="subscriber">
```ts title="src/subscribers/user-created.ts" highlights={[["11"], ["12"]]} collapsibleLines="1-6" expandButtonLabel="Show Imports"
import {
type SubscriberConfig,
type SubscriberArgs,
} from "@medusajs/framework"
import { createFulfillmentWorkflow } from "../workflows/create-fuilfillment"
```ts title="src/subscribers/custom-handler.ts"
import { SubscriberArgs } from "@medusajs/framework"
import { Modules } from "@medusajs/framework/utils"
export default async function handleUserCreated({
event: { data },
container,
}: SubscriberArgs<{ id: string }>) {
const { result } = await createFulfillmentWorkflow(container)
.run()
export default async function subscriberHandler({ container }: SubscriberArgs) {
const fulfillmentModuleService = container.resolve(
Modules.FULFILLMENT
)
console.log(result)
}
const fulfillments = await fulfillmentModuleService.listFulfillments()
export const config: SubscriberConfig = {
event: "user.created",
}
```
</CodeTab>
<CodeTab label="Scheduled Job" value="scheduled-job">
```ts title="src/jobs/run-daily.ts" highlights={[["7"], ["8"]]}
import { MedusaContainer } from "@medusajs/framework/types"
import { createFulfillmentWorkflow } from "../workflows/create-fuilfillment"
export default async function myCustomJob(
container: MedusaContainer
) {
const { result } = await createFulfillmentWorkflow(container)
.run()
console.log(result)
}
export const config = {
name: "run-once-a-day",
schedule: `0 0 * * *`,
}
```
</CodeTab>
</CodeTabs>
---
## Features
### Fulfillment Management
Create fulfillments and keep track of their status, items, and more.
```ts
const fulfillment = await fulfillmentModuleService.createFulfillment({
location_id: "loc_123",
provider_id: "webshipper",
delivery_address: {
country_code: "us",
city: "Strongsville",
address_1: "18290 Royalton Rd",
},
items: [
{
title: "Shirt",
sku: "SHIRT",
quantity: 1,
barcode: "123456",
},
],
labels: [],
order: {},
})
```
### Integrate Third-Party Fulfillment Providers
Use third-party fulfillment providers to provide customers with shipping options and fulfill their orders.
```ts
const shippingOption = await fulfillmentModuleService.createShippingOptions({
// ...
provider_id: "webshipper",
})
```
### Restrict By Location and Rules
Shipping options can be restricted to specific geographical locations. You can also specify custom rules to restrict shipping options.
```ts
const serviceZone = await fulfillmentModuleService.createServiceZones({
name: "US",
fulfillment_set_id: "fset_123",
geo_zones: [
{
type: "country",
country_code: "us",
},
],
})
const shippingOption = await fulfillmentModuleService.createShippingOptions({
name: "Express Shipping",
// restrict location
service_zone_id: serviceZone.id,
// restrict by custom rules
rules: [
{
field: "customer_group",
operator: "eq",
value: "vip",
},
],
// ...
})
```
### Support Different Fulfillment Forms
Support various fulfillment forms, such as shipping or pick up.
```ts
const fulfillmentSets = await fulfillmentModuleService.createFulfillmentSets([
{
name: "Shipping",
type: "shipping",
},
{
name: "Pick-up",
type: "pick-up",
},
])
```
Learn more about workflows in [this documentation](!docs!/learn/fundamentals/workflows).
---
## Configure Fulfillment Module
Refer to [this documentation](./module-options/page.mdx) for details on the module's options.
The Fulfillment Module accepts options for further configurations. Refer to [this documentation](./module-options/page.mdx) for details on the module's options.
---
<CommerceModuleSections name="Fulfillment" />