docs: docs for next release (#13303)

* added draft order plugin docs

* fix vale error

* added note about draft order being optional

* add new shipping option - shipping method link

* update user guides

* generate

* fix github icon

* changes to shipping option type

* document logger

* reorder list

* fixes

* fixes
This commit is contained in:
Shahed Nasser authored and GitHub committed 2025-08-28 18:49:07 +03:00
1 parent 94effdcda7
commit d510639193
55 files changed
+1653 -182

No files matched your search

+364 -18
View File
@@ -109,6 +109,7 @@ The `defineConfig` utility accepts an object having the following properties:
- [modules](#module-configurations-modules): Configurations related to registered modules.
- [plugins](#plugin-configurations-plugins): Configurations related to registered plugins.
- [featureFlags](#feature-flags-featureFlags): Configurations to manage enabled beta features in the Medusa application.
- [logger](#custom-logger-logger): Override the default logger.
### Using Environment Variables
@@ -992,6 +993,27 @@ After enabling a feature flag, make sure to run migrations, as the feature may i
npx medusa db:migrate
```
***
## Custom Logger (`logger`)
The `logger` configuration allows you to override the default [Logger](https://docs.medusajs.com/learn/debugging-and-testing/logging/index.html.md) used in the Medusa application with your custom implementation.
Learn more about creating a custom logger in the [Override Logger](https://docs.medusajs.com/learn/debugging-and-testing/logging/custom-logger/index.html.md) chapter.
The `logger` configuration accepts an instance of a class that extends the `Logger` interface.
### Example
```ts title="medusa-config.ts"
import { logger } from "./src/logger/my-logger"
module.exports = defineConfig({
// ...
logger,
})
```
# Using TypeScript Aliases
@@ -4000,6 +4022,133 @@ Trace span names start with the following keywords based on what it's reporting:
- [Integrate Sentry with Medusa](https://docs.medusajs.com/resources/integrations/guides/sentry/index.html.md)
# Override Logger
In this guide, you'll learn how to override the default [Logger](https://docs.medusajs.com/learn/debugging-and-testing/logging/index.html.md) in Medusa with your custom implementation.
## Why Override the Logger?
Medusa's default `Logger` logs your application's events, errors, and general log messages into the console. However, you might want to customize this behavior for your specific use case.
For example, you might want to change the logs format, or add additional metadata to your logs. In those cases, it's useful to override the default `Logger` with your custom implementation.
After overriding the `Logger`, Medusa will use your custom logger whenever it needs to log a message.
***
## How to Override the Logger?
To override the default `Logger`:
1. Create a class that extends the `Logger` interface from `@medusajs/framework/types`.
2. Pass the class in the Medusa configurations.
### Step 1: Create a Custom Logger Class
To create a custom logger class, create a new file at `src/utils/custom-logger.ts` with the following content:
```ts title="src/utils/custom-logger.ts"
import { Logger } from "@medusajs/framework/types"
class MyLogger implements Logger {
panic(data: unknown): void {
console.error("PANIC:", data)
}
shouldLog(level: string): boolean {
// For demonstration, always log
return true
}
setLogLevel(level: string): void {
console.info("Set log level to:", level)
}
unsetLogLevel(): void {
console.info("Unset log level")
}
activity(message: string, config?: unknown): string {
console.log("ACTIVITY:", message, config)
return "activity-id"
}
progress(activityId: string, message: string): void {
console.log(`PROGRESS [${activityId}]:`, message)
}
error(messageOrError: string | Error, error?: Error): void {
if (error) {
console.error("ERROR:", messageOrError, error)
} else {
console.error("ERROR:", messageOrError)
}
}
failure(activityId: string, message: string): unknown {
console.warn(`FAILURE [${activityId}]:`, message)
return null
}
success(activityId: string, message: string): Record<string, unknown> {
console.log(`SUCCESS [${activityId}]:`, message)
return { activityId, message }
}
silly(message: string): void {
console.debug("SILLY:", message)
}
debug(message: string): void {
console.debug("DEBUG:", message)
}
verbose(message: string): void {
console.info("VERBOSE:", message)
}
http(message: string): void {
console.info("HTTP:", message)
}
info(message: string): void {
console.info("INFO:", message)
}
warn(message: string): void {
console.warn("WARN:", message)
}
log(...args: unknown[]): void {
console.log(...args)
}
}
export const logger = new MyLogger()
```
You can implement the methods as per your requirements. For simplicity, the above example logs messages to the console with a prefix indicating the log level.
Notice that you must export an instance of your custom logger class to use it in the Medusa configurations.
You can learn more about the methods in the [Logger](https://docs.medusajs.com/learn/debugging-and-testing/logging/index.html.md) chapter.
### Step 2: Pass the Custom Logger in Medusa Configurations
Next, to use the custom logger, set the `logger` configuration in your `medusa-config.ts` file:
```ts title="medusa-config.ts"
import { logger } from "./src/logger/my-logger"
module.exports = defineConfig({
// ...
logger,
})
```
The `logger` configuration accepts an instance of a class that extends the `Logger` interface.
### Test Custom Logger
To test that your custom logger is working, start the Medusa application:
```bash npm2yarn
npm run dev
```
The logs will be displayed based on your custom implementation. For example, the above implementation that logs messages to the console will show logs similar to the following:
```bash
INFO: Watching filesystem to reload dev server on file change
WARN: Local Event Bus installed. This is not recommended for production.
```
# Logging
In this chapter, you’ll learn how to use Medusa’s logging utility.
@@ -4008,6 +4157,8 @@ In this chapter, you’ll learn how to use Medusa’s logging utility.
Medusa provides a `Logger` class with advanced logging functionalities. This includes configuring logging levels or saving logs to a file.
By default, the `Logger` class logs messages to the console. You can also override the default logger with your custom implementation, as explained in the [Override Logger](https://docs.medusajs.com/learn/debugging-and-testing/logging/custom-logger/index.html.md) guide.
The Medusa application registers the `Logger` class in the Medusa container and each module's container as `logger`.
***
@@ -25945,6 +26096,7 @@ Read-only links are used to query data across modules, but the relations aren't
|First Data Model|Second Data Model|Type|Description|
|---|---|---|---|
|Cart|Customer|Read-only - has one|Learn more|
|ShippingMethod|ShippingOption|Read-only - has one|Learn more|
|Order|Cart|Stored - one-to-one|Learn more|
|Cart|PaymentCollection|Stored - one-to-one|Learn more|
|LineItem|Product|Read-only - has one|Learn more|
@@ -25995,6 +26147,48 @@ const { data: carts } = useQueryGraphStep({
***
## Fulfillment Module
Medusa defines a read-only link between the `ShippingMethod` data model and the [Fulfillment Module](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/fulfillment/index.html.md)'s `ShippingOption` data model. This means you can retrieve the details of a shipping method's shipping option, but you don't manage the links in a pivot table in the database. The shipping option of a shipping method is determined by the `shipping_option_id` property of the `ShippingMethod` data model.
This link allows you to retrieve the shipping option that a shipping method was created from.
This read-only link was added in [Medusa v2.10.0](https://github.com/medusajs/medusa/releases/tag/v2.10.0)
### Retrieve with Query
To retrieve the shipping option of a shipping method with [Query](https://docs.medusajs.com/docs/learn/fundamentals/module-links/query/index.html.md), pass `shipping_option.*` in `fields`:
### query.graph
```ts
const { data: shippingMethods } = await query.graph({
entity: "shipping_method",
fields: [
"shipping_option.*",
],
})
// shippingMethods[0].shipping_option
```
### useQueryGraphStep
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: shippingMethods } = useQueryGraphStep({
entity: "shipping_method",
fields: [
"shipping_option.*",
],
})
// shippingMethods[0].shipping_option
```
## Order Module
The [Order Module](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/index.html.md) provides order-management features.
@@ -27479,6 +27673,7 @@ The Fulfillment Module has the following links to other modules:
|First Data Model|Second Data Model|Type|Description|
|---|---|---|---|
|ShippingMethod|ShippingOption|Read-only - has one|Learn more|
|Order|Fulfillment|Stored - one-to-many|Learn more|
|Return|Fulfillment|Stored - one-to-many|Learn more|
|PriceSet|ShippingOption|Stored - many-to-one|Learn more|
@@ -27488,6 +27683,50 @@ The Fulfillment Module has the following links to other modules:
***
## Cart Module
Medusa defines a read-only link between the `ShippingMethod` data model of the [Cart Module](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/cart/index.html.md) and the `ShippingOption` data model. This means you can retrieve the details of a shipping method's shipping option, but you don't manage the links in a pivot table in the database. The shipping option of a shipping method is determined by the `shipping_option_id` property of the `ShippingMethod` data model.
This link allows you to retrieve the shipping option that a shipping method was created from.
This read-only link was added in [Medusa v2.10.0](https://github.com/medusajs/medusa/releases/tag/v2.10.0)
### Retrieve with Query
To retrieve the shipping option of a shipping method with [Query](https://docs.medusajs.com/docs/learn/fundamentals/module-links/query/index.html.md), pass `shipping_option.*` in `fields`:
### query.graph
```ts
const { data: shippingMethods } = await query.graph({
entity: "shipping_method",
fields: [
"shipping_option.*",
],
})
// shippingMethods[0].shipping_option
```
### useQueryGraphStep
```ts
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
// ...
const { data: shippingMethods } = useQueryGraphStep({
entity: "shipping_method",
fields: [
"shipping_option.*",
],
})
// shippingMethods[0].shipping_option
```
***
## Order Module
The [Order Module](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/index.html.md) provides order-management functionalities.
@@ -28045,11 +28284,11 @@ The Fulfillment Module accepts options for further configurations. Refer to [thi
In this document, you’ll learn about shipping options and their rules.
## What’s a Shipping Option?
## What is a Shipping Option?
A shipping option is a way of shipping an item. Each fulfillment provider provides a set of shipping options. For example, a provider may provide a shipping option for express shipping and another for standard shipping.
A shipping option is a way of shipping an item. Each fulfillment provider offers a set of shipping options. For example, a provider may offer a shipping option for express shipping and another for standard shipping.
When the customer places their order, they choose a shipping option to be used to fulfill their items.
When the customer places an order, they choose a shipping option to fulfill their items.
A shipping option is represented by the [ShippingOption data model](https://docs.medusajs.com/references/fulfillment/models/ShippingOption/index.html.md).
@@ -28057,15 +28296,15 @@ A shipping option is represented by the [ShippingOption data model](https://docs
## Service Zone Restrictions
A shipping option is restricted by a service zone, limiting the locations a shipping option be used in.
A shipping option is restricted by a service zone, which limits the locations where the shipping option can be used.
For example, a fulfillment provider may have a shipping option that can be used in the United States, and another in Canada.
For example, a fulfillment provider may have a shipping option that can be used in the United States and another in Canada.
![A diagram showcasing the relation between shipping options and service zones.](https://res.cloudinary.com/dza7lstvk/image/upload/v1712330831/Medusa%20Resources/shipping-option-service-zone_pobh6k.jpg)
Service zones can be more restrictive, such as restricting to certain cities or province codes.
Service zones can be more restrictive, such as limiting to certain cities or province codes.
The province code is always in lower-case and in [ISO 3166-2 format](https://en.wikipedia.org/wiki/ISO_3166-2).
The province code is always in lowercase and in [ISO 3166-2 format](https://en.wikipedia.org/wiki/ISO_3166-2).
![A diagram showcasing the relation between shipping options, service zones, and geo zones](https://res.cloudinary.com/dza7lstvk/image/upload/v1712331186/Medusa%20Resources/shipping-option-service-zone-city_m5sxod.jpg)
@@ -28073,11 +28312,11 @@ The province code is always in lower-case and in [ISO 3166-2 format](https://en.
## Shipping Option Rules
You can restrict shipping options by custom rules, such as the item’s weight or the customer’s group.
You can restrict shipping options by custom rules, such as the item’s weight or the customer group.
You can also restrict a shipping option's price based on specific conditions. For example, you can make a shipping option's price free based on the cart's total. Learn more in the Pricing Module's [Price Rules](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/pricing/price-rules#how-to-set-rules-on-a-price/index.html.md) guide.
You can also restrict a shipping option's price based on specific conditions. For example, you can make a shipping option's price free based on the cart total. Learn more in the Pricing Module's [Price Rules](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/pricing/price-rules#how-to-set-rules-on-a-price/index.html.md) guide.
These rules are represented by the [ShippingOptionRule data model](https://docs.medusajs.com/references/fulfillment/models/ShippingOptionRule/index.html.md). Its properties define the custom rule:
These rules are represented by the [ShippingOptionRule data model](https://docs.medusajs.com/references/fulfillment/models/ShippingOptionRule/index.html.md). Its properties define the custom rules:
- `attribute`: The name of a property or table that the rule applies to. For example, `customer_group`.
- `operator`: The operator used in the condition. For example:
@@ -28093,19 +28332,21 @@ A shipping option can have multiple rules. For example, you can add rules to a s
***
## Shipping Profile and Types
## Shipping Profiles and Types
A shipping option belongs to a type. For example, a shipping option’s type may be `express`, while another `standard`. The type is represented by the [ShippingOptionType data model](https://docs.medusajs.com/references/fulfillment/models/ShippingOptionType/index.html.md).
A shipping option belongs to a type and a profile.
A shipping option also belongs to a shipping profile, as each shipping profile defines the type of items to be shipped in a similar manner.
A shipping option type defines a group of shipping options with shared shipping characteristics. For example, a shipping option’s type may be `express`, while another may be `standard`. The type is represented by the [ShippingOptionType data model](https://docs.medusajs.com/references/fulfillment/models/ShippingOptionType/index.html.md).
A shipping profile defines a group of items (such as products) that are shipped in a similar manner. For example, the "Standard" shipping profile applies to all products, whereas the "Digital" shipping profile applies to digital products. Shipping profiles are represented by the [ShippingProfile data model](https://docs.medusajs.com/references/fulfillment/models/ShippingProfile/index.html.md).
***
## data Property
When fulfilling an item, you might use a third-party fulfillment provider that requires additional custom data to be passed along from the checkout or order-creation process.
When fulfilling an item, you might use a third-party fulfillment provider that requires additional custom data to be passed along from the checkout or order creation process.
The `ShippingOption` data model has a `data` property. It's an object that stores custom data relevant later when creating and processing a fulfillment.
The `ShippingOption` data model has a `data` property. It's an object that stores custom data relevant for creating and processing a fulfillment later.
# Inventory Concepts
@@ -29005,6 +29246,105 @@ An order can have multiple transactions. The sum of these transactions must be e
Refer to the [Transactions](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/transactions/index.html.md) guide to learn more.
# Draft Orders Plugin
In this guide, you'll learn about the Draft Orders Plugin and its features.
The Draft Orders Plugin was initially only available to Cloud users during its early access phase. It is now available for all Medusa users.
## What is the Draft Orders Plugin?
The Draft Orders Plugin is a Medusa plugin that allows admin users to create and manage draft orders on behalf of customers from the Medusa Admin.
The Medusa application already has the foundation to support draft orders, including data models and API routes. This plugin adds a user interface for managing draft orders in the Medusa Admin dashboard.
The Draft Orders Plugin is especially useful for handling customer support scenarios or when a customer places an order offline, such as over the phone or in-store.
### Features
- [Create draft orders from the Medusa Admin.](https://docs.medusajs.com/user-guide/orders/draft-orders/create/index.html.md)
- [Manage items in a draft order, allowing admin users to add, update, or remove items](https://docs.medusajs.com/user-guide/orders/draft-orders/manage#manage-draft-orders-items/index.html.md).
- [Add shipping methods to draft orders.](https://docs.medusajs.com/user-guide/orders/draft-orders/manage#manage-draft-orders-shipping-methods/index.html.md).
- [Associate existing customers with draft orders.](https://docs.medusajs.com/user-guide/orders/draft-orders/manage#manage-draft-orders-customer-details/index.html.md).
- [Convert draft orders to regular orders.](https://docs.medusajs.com/user-guide/orders/draft-orders/manage#convert-draft-order-to-regular-order/index.html.md).
***
## Install the Draft Orders Plugin
The Draft Orders Plugin is available in all Medusa applications starting v2.10.0.
For earlier versions, you can install the plugin manually.
### Prerequisites
- [Medusa application >= v2.4.0](https://docs.medusajs.com/docs/learn/installation/index.html.md)
To install the Draft Orders Plugin:
1. Run the following command in your Medusa application's directory:
```bash npm2yarn
npm install @medusajs/draft-order
```
2. Add the plugin to your `medusa-config.ts` file:
```ts title="medusa-config.ts"
module.exports = defineConfig({
// ...
plugins: [
{
resolve: "@medusajs/draft-order",
options: {},
},
],
})
```
### Test the Draft Orders Plugin
To test the Draft Orders Plugin, start the Medusa application with the following command:
```bash npm2yarn
npm run dev
```
If you open the Medusa Admin at `localhost:9000/app` and log in, you'll find an "Orders -> Drafts" sidebar item.
***
## Draft Orders User Guides
To learn how to use the draft order features in the Medusa Admin, refer to the [Draft Orders](https://docs.medusajs.com/user-guide/orders/draft-orders/index.html.md) user guides.
***
## How Draft Orders Work
A draft order is stored in the database as a regular order. It is represented by the [Order data model](https://docs.medusajs.com/references/order/models/Order/index.html.md) with the following properties:
- `status`: Set to `draft` to indicate that the order is a draft.
- `is_draft_order`: Set to `true` to indicate that the order is a draft order.
So, the same [order concepts](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/concepts/index.html.md) apply to draft orders as well.
### Editing Draft Orders
Similar to regular orders, draft orders can be [edited](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/edit/index.html.md), allowing admin users to add, update, or remove items, as well as add shipping methods.
When the order edit is confirmed on the draft order, the changes are applied directly to the draft order and its [version](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/order-versioning/index.html.md) is incremented.
### Converting Draft Orders to Regular Orders
Once a draft order is finalized and ready for processing, it can be converted to a regular order. This involves:
- Changing its `status` property to `pending`.
- Changing its `is_draft_order` property to `false`.
Admin users can then manage the order like any other regular order, including processing payments and fulfilling items.
# Order Edit
In this document, you'll learn about order edits.
@@ -30063,7 +30403,7 @@ Learn more about why modules are isolated in [this documentation](https://docs.m
## Order Features
- [Order Management](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/concepts/index.html.md): Store and manage your orders to retrieve, create, cancel, and perform other operations.
- Draft Orders: Allow merchants to create orders on behalf of their customers as draft orders that later are transformed to regular orders.
- [Draft Orders](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/draft-orders/index.html.md): Allow merchants to create orders on behalf of their customers as draft orders that later are transformed to regular orders.
- [Apply Promotion Adjustments](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/promotion-adjustments/index.html.md): Apply promotions or discounts to the order's items and shipping methods by adding adjustment lines that are factored into their subtotals.
- [Apply Tax Lines](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/tax-lines/index.html.md): Apply tax lines to an order's line items and shipping methods.
- [Returns](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/return/index.html.md), [Edits](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/edit/index.html.md), [Exchanges](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/exchange/index.html.md), and [Claims](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/claim/index.html.md): Make [changes](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/order-change/index.html.md) to an order to edit, return, or exchange its items, with [version-based control](https://docs.medusajs.com/Users/shahednasser/medusa/www/apps/resources/app/commerce-modules/order/order-versioning/index.html.md) over the order's timeline.
@@ -41493,7 +41833,7 @@ Emitted when a shipment is created for an order.
```ts
{
id, // the ID of the shipment
id, // the ID of the fulfillment
no_notification, // (boolean) whether to notify the customer
}
```
@@ -113061,7 +113401,13 @@ curl -X POST 'http://localhost:9000/restaurants/res_01J5X704WQTFSZMRC7Z6S3YAC7/p
"amount": 20
}
],
"manage_inventory": false
"manage_inventory": false,
"options": [
{
"title": "Default Title",
"values": ["Default Value"]
}
]
}
],
"sales_channels": [