Files
medusa-store/www/apps/resources/app/commerce-modules/order/page.mdx
Shahed Nasser 964927b597 docs: general fixes and improvements (#7918)
* docs improvements and changes

* updated module definition

* modules + dml changes

* fix build

* fix vale error

* fix lint errors

* fixes to stripe docs

* fix condition

* fix condition

* fix module defintion

* fix checkout

* disable UI action

* change oas preview action

* flatten provider module options

* fix lint errors

* add module link docs

* pr comments fixes

* fix vale error

* change node engine version

* links -> linkable

* add note about database name

* small fixes

* link fixes

* fix response code in api reference

* added migrations step
2024-07-04 17:26:03 +03:00

164 lines
4.0 KiB
Plaintext

import { CodeTabs, CodeTab } from "docs-ui"
export const metadata = {
title: `Order Module`,
}
# {metadata.title}
The Order Module is the `@medusajs/order` NPM package that provides order-related features in your Medusa and Node.js applications.
## Features
### Order Management
Store and manage your orders to retriev, create, cancel, and perform other operations.
```ts
const order = await orderModuleService.createOrders({
currency_code: "usd",
items: [
{
title: "Shirt",
quantity: 1,
unit_price: 3000,
},
],
shipping_methods: [
{
name: "Express shipping",
amount: 3000,
},
],
})
```
### Draft Orders
Allow merchants to create orders on behalf of their customers as draft orders that later are transformed to regular orders.
```ts
const draftOrder = await orderModuleService.createOrders({
currency_code: "usd",
// other details...
status: "draft",
})
```
### Apply Promotions
Apply promotions or discounts to the order's items and shipping methods by adding adjustment lines that are factored into their subtotals.
```ts
const lineAdjustments = await orderModuleService.addLineItemAdjustments({
item_id: "cali_123",
code: "50OFF",
amount: 500,
})
const shippingAdjustments =
await orderModuleService.addShippingMethodAdjustments({
shipping_method_id: "casm_123",
code: "FREESHIPPING",
amount: 1000,
})
```
### Returns, Exchanges, and Other Order Changes
<Note title="In Development" type="soon">
Order Changes are still in development.
</Note>
Orders can be changed to return items from the customer, exchange an item with another, change the quantity of an item, or perform other changes.
Changes are only applied after confirmation, and order history is preserved through versioning.
```ts
const orderChange = await orderModuleService.createOrderChange({
order_id: "ord_123",
})
// add item to the order
await orderModuleService.addOrderAction({
order_change_id: orderChange.id,
action: "ADD_ITEM",
details: {
quantity: 1,
unit_price: 4000,
reference_id: "orditem_123",
},
})
// confirm order change and apply it to order
await orderModuleService.confirmOrderChange("ord_123")
```
---
## How to Use Order Module's Service
You can use the Order Module's main service by resolving from the Medusa container the resource `ModuleRegistrationName.ORDER` imported from `@medusajs/modules-sdk`.
For example:
<CodeTabs groupId="resource-type">
<CodeTab label="API Route" value="api-route">
```ts title="src/api/store/custom/route.ts"
import { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
import { IOrderModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const orderModuleService: IOrderModuleService = req.scope.resolve(
ModuleRegistrationName.ORDER
)
res.json({
orders: await orderModuleService.listOrders(),
})
}
```
</CodeTab>
<CodeTab label="Subscriber" value="subscribers">
```ts title="src/subscribers/custom-handler.ts"
import { SubscriberArgs } from "@medusajs/medusa"
import { IOrderModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
export default async function subscriberHandler({ container }: SubscriberArgs) {
const orderModuleService: IOrderModuleService = container.resolve(
ModuleRegistrationName.ORDER
)
const orders = await orderModuleService.listOrders()
}
```
</CodeTab>
<CodeTab label="Workflow Step" value="workflow-step">
```ts title="src/workflows/hello-world/step1.ts"
import { createStep } from "@medusajs/workflows-sdk"
import { IOrderModuleService } from "@medusajs/types"
import { ModuleRegistrationName } from "@medusajs/utils"
const step1 = createStep("step-1", async (_, { container }) => {
const orderModuleService: IOrderModuleService = container.resolve(
ModuleRegistrationName.ORDER
)
const orders = await orderModuleService.listOrders()
})
```
</CodeTab>
</CodeTabs>