chore: reorganize docs apps (#7228)

* reorganize docs apps

* add README

* fix directory

* add condition for old docs
This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-05-03 17:36:38 +03:00
1 parent 224ebb2154
commit 4fe28f5a95
6187 files changed
+601447 -598226

No files matched your search

@@ -0,0 +1,51 @@
export const metadata = {
title: `Order Concepts`,
}
# {metadata.title}
In this document, you’ll learn about orders and their general fields.
## Order Data Model
An order represents a customer purchase in your store. The `Order` data model holds the information about that purchase.
---
## Order Items
The items purchased in the order are represented by the `OrderItem` data model. An order can have multiple items.
![https://res.cloudinary.com/dza7lstvk/image/upload/v1712304722/Medusa%20Resources/order-order-items_uvckxd.jpg](https://res.cloudinary.com/dza7lstvk/image/upload/v1712304722/Medusa%20Resources/order-order-items_uvckxd.jpg)
Learn more about order items in [this guide](../order-items/page.mdx).
---
## Order’s Shipping Method
An order has one or more shipping methods used to handle item shipment. Each shipping method is represented by the `ShippingMethod` data model that holds its details.
### data Field
When fulfilling the order, you may use a third-party fulfillment provider that requires additional custom data to be passed along from the order creation process.
The `ShippingMethod` data model has a `data` field. It’s an object used to store custom data relevant later for fulfillment.
In the Medusa application, the `data` is passed to the Fulfillment Module when fulfilling items.
---
## Order Totals
The order’s total amounts (including tax total, total after an item is returned, etc…) are represented by the `OrderSummary` data model. An order can have multiple summaries.
---
## Order Payments
Payments made on an order, whether they’re capture or refund payments, are recorded as transactions represented by the `Transaction` data model.
An order can have multiple transactions. The sum of these transactions must be equal to the order summary’s total. Otherwise, there’s an outstanding amount.
Learn more about transactions in [this guide](../transactions/page.mdx).
@@ -0,0 +1,301 @@
import { Table } from "docs-ui"
export const metadata = {
title: `Order Change`,
}
# {metadata.title}
In this document, you’ll learn how to make changes to an order, such as return or exchange an item.
## What's an Order Change?
An order change is modifying the order’s items for business purposes. For example, when a customer requests to return an item, or when you suggest exchanging an item with another.
Order changes are represented by the `OrderChange` data model.
---
## Order Change Actions
An order change can have multiple underlying actions. For example, to exchange an item, you have to:
- Mark an item as returned.
- Arrange to receive the item from the customer.
- Add the new item to be sent to the customer.
- Fulfill the item and send it to the customer.
Each of these actions is represented by the `OrderChangeAction` data model.
### Action Name
The `action` field of the `OrderChangeAction` holds the name of the action to perform. Based on the action, additional details are stored in the `details` object field of the data model.
<Table>
<Table.Header>
<Table.Row>
<Table.HeaderCell>Action Name</Table.HeaderCell>
<Table.HeaderCell>Description</Table.HeaderCell>
<Table.HeaderCell>Expected details</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>
`ITEM_ADD`
</Table.Cell>
<Table.Cell>
Adds a new item to the order.
</Table.Cell>
<Table.Cell>
- `quantity`: The quantity of the item to add.
- `unit_price`: The price of the item.
- `reference_id`: The ID of the item to add.
For example:
`{ quantity: 1; unit_price: 1000; reference_id: "orditem_123" }`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`ITEM_REMOVE`
</Table.Cell>
<Table.Cell>
Removes an item from the order.
</Table.Cell>
<Table.Cell>
- `quantity`: The quantity of the item to remove.
- `unit_price`: The price of the item.
- `reference_id`: The ID of the item to remove.
For example:
`{ quantity: 1; unit_price: 1000; reference_id: "orditem_123" }`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`WRITE_OFF_ITEM`
</Table.Cell>
<Table.Cell>
Removes a quantity of an item.
</Table.Cell>
<Table.Cell>
- `quantity`: The quantity to remove of the item.
- `reference_id`: The ID of the item to remove its quantity.
`{ quantity: 1; reference_id: "orditem_123"}`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`RETURN_ITEM`
</Table.Cell>
<Table.Cell>
Request a return of an item.
</Table.Cell>
<Table.Cell>
- `quantity`: The quantity to return of the item.
- `reference_id`: The ID of the item to return.
`{ quantity: 1; reference_id: "orditem_123"}`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`RECEIVE_RETURN_ITEM`
</Table.Cell>
<Table.Cell>
Mark as received an item whose return was previously requested.
</Table.Cell>
<Table.Cell>
- `quantity`: The quantity received of the item.
- `reference_id`: The ID of the item to mark its return as received.
`{ quantity: 1; reference_id: "orditem_123"}`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`RECEIVE_DAMAGED_RETURN_ITEM`
</Table.Cell>
<Table.Cell>
Mark as received an item whose return was previously requested, but consider the items damaged.
This changes the order item’s `return_dismissed_quantity` field rather than its `return_received_quantity` field.
</Table.Cell>
<Table.Cell>
- `quantity`: The quantity received of the item.
- `reference_id`: The ID of the item to mark its return as received.
`{ quantity: 1; reference_id: "orditem_123"}`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`CANCEL_RETURN`
</Table.Cell>
<Table.Cell>
Cancel a previously requested return of an item.
</Table.Cell>
<Table.Cell>
- `quantity`: The quantity to cancel its return request.
- `unit_price`: The price of the item.
- `reference_id`: The ID of the item to cancel its return request.
`{ quantity: 1; unit_price: 1000; reference_id: "orditem_123"}`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`SHIPPING_ADD`
</Table.Cell>
<Table.Cell>
Add a shipping method to an item.
</Table.Cell>
<Table.Cell>
- `amount`: The amount of the shipping.
- `reference_id`: The ID of the shipping method to add.
`{ amount: 1000; reference_id: "orditem_123"}`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`SHIP_ITEM`
</Table.Cell>
<Table.Cell>
Mark a quantity of an item as shipped. This modifies the shipped_quantity field of an order item.
</Table.Cell>
<Table.Cell>
- `quantity`: The quantity of the item to ship.
- `reference_id`: The ID of the item to mark its specified quantity as shipped.
`{ quantity: 1; reference_id: "ordli_123"}`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`FULFILL_ITEM`
</Table.Cell>
<Table.Cell>
Mark a quantity of an item as fulfilled. This modifies the fulfilled_quantity field of an order item.
</Table.Cell>
<Table.Cell>
- `quantity`: The quantity of the item to ship.
- `reference_id`: The ID of the item to mark its specified quantity as shipped.
`{ quantity: 1; reference_id: "ordli_123"}`
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
`CANCEL`
</Table.Cell>
<Table.Cell>
Cancel the order change.
</Table.Cell>
<Table.Cell>
Doesn’t expect any data.
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
### Action Chaining
Actions are chained one after the other, similar to the example in the earlier section. This also allows you to cancel or undo some actions.
For example, if you request an order return with `RETURN_ITEM` action, you can later cancel it with the `CANCEL_RETURN` action.
The actions are ordered by the `ordering` field of the `OrderChangeAction` data model.
### Action Amount
The `OrderChangeAction` data model has an `amount` field that indicates a change in the order’s amount that this action incurs.
---
## Order Change Confirmation
The `OrderChange` data model has a `status` field that indicates its current status. By default, it’s pending. At this point, the order change’s actions aren’t applied to the order yet.
To apply these changes to the order, you must confirm the order change. When the order change is confirmed:
- The status of the order change is changed to `confirmed`.
- The order’s items are changed based on the order change’s actions. For example, an item is added, or an existing item’s quantity is changed.
- The order summary is modified to reflect new changes.
<Note>
If there are changes to the order’s total amount due to refunding or capturing payment, they must be added as transactions first. Otherwise, they won’t be accounted for when modifying the order summary
</Note>
@@ -0,0 +1,37 @@
export const metadata = {
title: `Order Item`,
}
# {metadata.title}
In this document, you’ll learn about the order item and the general details it holds.
## OrderItem Data Model
Each item in an order is represented by the `OrderItem` data model. It holds details related to the quantity of the item and the underlying product details.
---
## Order Item Quantity
The `OrderItem` data model has the following quantity fields:
- `quantity`: The quantity ordered.
- `fulfilled_quantity`: The quantity that’s been fulfilled.
- `shipped_quantity`: The quantity that’s been shipped.
- `return_requested_quantity`: The quantity requested to be returned, but hasn’t been received yet.
- `return_received_quantity`: The quantity that’s been received from the customer due to a return request.
- `return_dismissed_quantity`: The quantity that’s been received from the customer due to a return request, but the items are damaged.
- `written_off_quantity`: The quantity removed from the originally ordered quantity.
---
## Item’s Product Details
The details of the purchased products are represented by the `LineItem` data model. Not only does a line item hold the details of the product, but also details related to its price, adjustments due to promotions, and taxes.
<Note>
The `LineItem` data model is similar to the Cart Module’s `LineItem` data model. So, when using both modules, the data can be copied between the modules as-is.
</Note>
@@ -0,0 +1,33 @@
export const metadata = {
title: `Order Versioning`,
}
# {metadata.title}
In this document, you’ll learn how an order and its details are versioned.
## What's Versioning?
Versioning means assigning a version number to a record, such as an order and its items. This is useful to view the different versions of the order following changes in its lifetime.
---
## version Field
The `Order` and `OrderSummary` data models have a `version` field that indicates the current order version. By default, its value is `1`.
The `OrderItem` data model also has a `version` field, but it indicates the version it belongs to. For example, original items in the order have version `1`. Then, when a new item is added, its version is `2`. If an existing item is modified, such as its quantity has been changed, its version is updated.
---
## Order Change Versioning
The `OrderChange` and `OrderChangeAction` data models also have a `version` field. When an order change is created, the `version` field’s value is the associated order’s version incremented.
So, if the order’s `version` is `1`, the order change’s version is `2`.
Then, once the order change is confirmed and applied to the order, the versions of the order and order summary change to that of the order change.
Order items change depending on the version they were added or modified in, as explained in the earlier section.
![https://res.cloudinary.com/dza7lstvk/image/upload/v1712304242/Medusa%20Resources/order-versioning_rsx2rn.jpg](https://res.cloudinary.com/dza7lstvk/image/upload/v1712304242/Medusa%20Resources/order-versioning_rsx2rn.jpg)
@@ -0,0 +1,177 @@
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 by retrieving, creating, canceling, and performing other operations.
```ts
const order = await orderModuleService.create({
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.create({
currency_code: "usd",
// other details...
status: "draft",
})
```
### Returns, Exchanges, and Other Order Changes
Orders can be changed to return items from the customer, exchange an item with another, change the quantity of an item, or 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")
```
### 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,
})
```
---
## Configure Order Module
After installing the `@medusajs/order` package in your Medusa application, add it to the `modules` object in `medusa-config.js`:
```js title="medusa-config.js"
const modules = {
// ...
order: {
resolve: "@medusajs/order",
},
}
```
---
## 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/modules-sdk"
export async function GET(
req: MedusaRequest,
res: MedusaResponse
): Promise<void> {
const orderModuleService: IOrderModuleService =
req.scope.resolve(ModuleRegistrationName.ORDER)
res.json({
orders: await orderModuleService.list(),
})
}
```
</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/modules-sdk"
export default async function subscriberHandler({
container,
}: SubscriberArgs) {
const orderModuleService: IOrderModuleService =
container.resolve(ModuleRegistrationName.API_KEY)
const orders = await orderModuleService.list()
}
```
</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/modules-sdk"
const step1 = createStep("step-1", async (_, context) => {
const orderModuleService: IOrderModuleService =
context.container.resolve(
ModuleRegistrationName.API_KEY
)
const orders = await orderModuleService.list()
})
```
</CodeTab>
</CodeTabs>
@@ -0,0 +1,134 @@
---
sidebar_label: "Promotions Adjustments"
---
export const metadata = {
title: `Promotions Adjustments in Orders`,
}
# {metadata.title}
In this document, you’ll learn how a promotion is applied to an order’s items and shipping methods using adjustment lines.
## What are Adjustment Lines?
An adjustment line indicates a change to a line item or a shipping method’s amount. It’s used to apply promotions or discounts on an order.
The `LineItemAdjustment` data model represents adjustment lines for a line item, and the `ShippingMethodAdjustment` data model represents adjustment lines for a shipping method.
![https://res.cloudinary.com/dza7lstvk/image/upload/v1712306017/Medusa%20Resources/order-adjustments_myflir.jpg](https://res.cloudinary.com/dza7lstvk/image/upload/v1712306017/Medusa%20Resources/order-adjustments_myflir.jpg)
The `amount` field of the adjustment line indicates the amount to be discounted from the original amount. Also, the ID of the applied promotion can be stored in the `promotion_id` field of the adjustment line.
---
## Promotion Actions
When using the Order and Promotion modules together, such as in the Medusa application, use the `computeActions` method of the Promotion Module’s main service. It retrieves the actions of line items and shipping methods.
<Note>
Learn more about actions in the [Promotion Module’s documentation](../../promotion/actions/).
</Note>
```ts
import {
ComputeActionAdjustmentLine,
ComputeActionItemLine,
ComputeActionShippingLine,
// ...
} from "@medusajs/types"
// ...
// retrieve the order
const order = await orderModuleService.retrieve("ord_123", {
relations: [
"items.item.adjustments",
"shipping_methods.adjustments",
],
})
// retrieve the line item adjustments
const lineItemAdjustments: ComputeActionItemLine[] = []
order.items.forEach((item) => {
const filteredAdjustments = item.adjustments?.filter(
(adjustment) => adjustment.code !== undefined
) as unknown as ComputeActionAdjustmentLine[]
if (filteredAdjustments.length) {
lineItemAdjustments.push({
...item,
...item.detail,
adjustments: filteredAdjustments,
})
}
})
//retrieve shipping method adjustments
const shippingMethodAdjustments: ComputeActionShippingLine[] =
[]
order.shipping_methods.forEach((shippingMethod) => {
const filteredAdjustments =
shippingMethod.adjustments?.filter(
(adjustment) => adjustment.code !== undefined
) as unknown as ComputeActionAdjustmentLine[]
if (filteredAdjustments.length) {
shippingMethodAdjustments.push({
...shippingMethod,
adjustments: filteredAdjustments,
})
}
})
// compute actions
const actions = await promotionModuleService.computeActions(
["promo_123"],
{
items: lineItemAdjustments,
shipping_methods: shippingMethodAdjustments,
}
)
```
The `computeActions` method accepts the existing adjustments of line items and shipping methods to compute the actions accurately.
<Note>
Learn more about the `computeActions` method in [this reference](/references/promotion/computeActions).
</Note>
Then, use the returned `addItemAdjustment` and `addShippingMethodAdjustment` actions to set the order’s line items and the shipping method’s adjustments.
```ts
import {
AddItemAdjustmentAction,
AddShippingMethodAdjustment,
// ...
} from "@medusajs/types"
// ...
await orderModuleService.setLineItemAdjustments(
order.id,
actions.filter(
(action) => action.action === "addItemAdjustment"
) as AddItemAdjustmentAction[]
)
await orderModuleService.setShippingMethodAdjustments(
order.id,
actions.filter(
(action) =>
action.action === "addShippingMethodAdjustment"
) as AddShippingMethodAdjustment[]
)
```
---
## Discountable Option
The `LineItem` data model has an `is_discountable` field that indicates whether promotions can be applied to the line item. It’s enabled by default.
When disabled, a promotion can’t be applied to a line item. In the context of the Promotion Module, the promotion isn’t applied to the line item even if it matches its rules.
@@ -0,0 +1,17 @@
export const metadata = {
title: `Relations between Order Module and Other Modules`,
}
# {metadata.title}
When Commerce Modules are used together in a Medusa application, the Medusa application handles building the relations between these modules.
This document showcases the relation between the Order Module and other Commerce Modules.
## Sales Channel Module
Orders can be scoped to a sales channel. The Medusa application forms a relation between the `Order` and the `SalesChannel` data models.
![A diagram showcasing an example of how resources from the Order and Sales Channel modules are linked](https://res.cloudinary.com/dza7lstvk/image/upload/v1712315409/Medusa%20Resources/order-sales-channel_dy72gx.jpg)
This is useful for omnichannel purposes. Associating an order with a sales channel in turn ensures that associated products, inventory, and other details are also scoped to that sales channel.
@@ -0,0 +1,35 @@
---
sidebar_label: "Tax Lines"
---
export const metadata = {
title: `Tax Lines in Order Module`,
}
# {metadata.title}
In this document, you’ll learn about tax lines in an order.
## What are Tax Lines?
A tax line indicates the tax rate of a line item or a shipping method. The `LineItemTaxLine` data model represents a line item’s tax line, and the `ShippingMethodTaxLine` data model represents a shipping method’s tax line.
![https://res.cloudinary.com/dza7lstvk/image/upload/v1712307225/Medusa%20Resources/order-tax-lines_sixujd.jpg](https://res.cloudinary.com/dza7lstvk/image/upload/v1712307225/Medusa%20Resources/order-tax-lines_sixujd.jpg)
---
## Tax Inclusivity
By default, the tax amount is calculated by taking the tax rate from the line item or shipping method’s amount and then added to the item/method’s subtotal.
However, line items and shipping methods have an `is_tax_inclusive` field that, when enabled, indicates that the item or method’s price already includes taxes.
So, instead of calculating the tax rate and adding it to the item/method’s subtotal, it’s calculated as part of the subtotal.
<Note>
The following diagram is a simplified showcase of how a subtotal is calculated from the tax perspective.
</Note>
![https://res.cloudinary.com/dza7lstvk/image/upload/v1712307395/Medusa%20Resources/order-tax-inclusive_oebdnm.jpg](https://res.cloudinary.com/dza7lstvk/image/upload/v1712307395/Medusa%20Resources/order-tax-inclusive_oebdnm.jpg)
@@ -0,0 +1,79 @@
import { Table } from "docs-ui"
export const metadata = {
title: `Transactions`,
}
# {metadata.title}
In this document, you’ll learn about an order’s transactions and usefulness.
## What is a Transaction?
A transaction represents any order payment process, such as capturing or refunding an amount. It’s represented by the `Transaction` data model.
The transaction’s main purpose is to ensure a correct balance between paid and outstanding amounts.
---
## Transaction Reference
The Order Module doesn’t provide payment processing functionalities, so it doesn’t store payments that can be processed. For that, use the Payment Module or custom logic.
The `Transaction` data model has two fields that determine which data model and record holds the actual payment’s details:
- `reference`: indicates the table’s name in the database. For example, `payment` if you’re using the Payment Module.
- `reference_id`: indicates the ID of the record in the table. For example, `pay_123`.
---
## Checking Outstanding Amount
The order’s total is stored in the `OrderSummary`'s `total` field. To check the outstanding amount of the order, the transaction amounts of an order are summed. Then:
<Table>
<Table.Header>
<Table.Row>
<Table.HeaderCell>Condition</Table.HeaderCell>
<Table.HeaderCell>Result</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>
summary’s total - transaction amounts total = 0
</Table.Cell>
<Table.Cell>
There’s no outstanding amount.
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
summary’s total - transaction amounts total > 0
</Table.Cell>
<Table.Cell>
The customer owes additional payment to the merchant.
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>
summary’s total - transaction amounts total < 0
</Table.Cell>
<Table.Cell>
The merchant owes the customer a refund.
</Table.Cell>
</Table.Row>
</Table.Body>
</Table>