Order Module

In this section of the documentation, you will find resources to learn more about the Order Module and how to use it in your application.

Looking for no-code docs?Refer to the Medusa Admin User Guide to learn how to manage orders using the dashboard.

Medusa has order related features available out-of-the-box through the Order Module. A module 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 Order Module.

NoteLearn more about why modules are isolated in this documentation.

Order Features#

  • Order Management: 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.
  • Apply Promotion Adjustments: 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: Apply tax lines to an order's line items and shipping methods.
  • Returns, Edits, Exchanges, and Claims: Make changes to an order to edit, return, or exchange its items, with version-based control over the order's timeline.

How to Use the Order Module#

In your Medusa application, you build flows around commerce modules. A flow is built as a Workflow, 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:

src/workflows/create-draft-order.ts
1import { 2  createWorkflow, 3  WorkflowResponse,4  createStep,5  StepResponse,6} from "@medusajs/framework/workflows-sdk"7import { Modules } from "@medusajs/framework/utils"8
9const createDraftOrderStep = createStep(10  "create-order",11  async ({}, { container }) => {12    const orderModuleService = container.resolve(Modules.ORDER)13
14    const draftOrder = await orderModuleService.createOrders({15      currency_code: "usd",16      items: [17        {18          title: "Shirt",19          quantity: 1,20          unit_price: 3000,21        },22      ],23      shipping_methods: [24        {25          name: "Express shipping",26          amount: 3000,27        },28      ],29      status: "draft",30    })31
32    return new StepResponse({ draftOrder }, draftOrder.id)33  },34  async (draftOrderId, { container }) => {35    if (!draftOrderId) {36      return37    }38    const orderModuleService = container.resolve(Modules.ORDER)39
40    await orderModuleService.deleteOrders([draftOrderId])41  }42)43
44export const createDraftOrderWorkflow = createWorkflow(45  "create-draft-order",46  () => {47    const { draftOrder } = createDraftOrderStep()48
49    return new WorkflowResponse({50      draftOrder,51    })52  }53)

You can then execute the workflow in your custom API routes, scheduled jobs, or subscribers:

Learn more about workflows in this documentation.


Was this page helpful?
Edit this page
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break