Commerce Modules

Order Module

The Order Module is the @medusajs/medusa/order NPM package that provides order-related features in your Medusa and Node.js applications.

How to Use Order Module's Service#

You can use the Order Module's main service by resolving from the Medusa container the resource Modules.ORDER imported from @medusajs/framework/utils.

For example:


Features#

Order Management#

Store and manage your orders to retriev, create, cancel, and perform other operations.

Code
1const order = await orderModuleService.createOrders({2  currency_code: "usd",3  items: [4    {5      title: "Shirt",6      quantity: 1,7      unit_price: 3000,8    },9  ],10  shipping_methods: [11    {12      name: "Express shipping",13      amount: 3000,14    },15  ],16})

Draft Orders#

Allow merchants to create orders on behalf of their customers as draft orders that later are transformed to regular orders.

Code
1const draftOrder = await orderModuleService.createOrders({2  currency_code: "usd",3  // other details...4  status: "draft",5})

Apply Promotions#

Apply promotions or discounts to the order's items and shipping methods by adding adjustment lines that are factored into their subtotals.

Code
1const lineAdjustments = await orderModuleService.addLineItemAdjustments({2  item_id: "cali_123",3  code: "50OFF",4  amount: 500,5})6
7const shippingAdjustments =8  await orderModuleService.addShippingMethodAdjustments({9    shipping_method_id: "casm_123",10    code: "FREESHIPPING",11    amount: 1000,12  })

Returns, Exchanges, and Claims#

Return or exchange items, with version-based control over the order's timeline.

Code
1const orderReturn = await orderModuleService.createReturn({2  order_id: "order_123",3  items: [{4    id: "orditem_123",5    quantity: 1,6  }],7})
Was this page helpful?
Edit this page