This documentation provides a reference to the createOrderWorkflow
. It belongs to the @medusajs/medusa/core-flows
package.
This workflow creates an order. It's used by the Create Draft Order Admin API Route, but you can also use it to create any order.
This workflow has a hook that allows you to perform custom actions on the created order. For example, you can pass under additional_data
custom data that
allows you to create custom data models linked to the order.
You can also use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around creating an order. For example, you can create a workflow that imports orders from an external system, then uses this workflow to create the orders in Medusa.
Source CodeWorkflow hook
Step conditioned by when
View step details
CreateOrderWorkflowInput
CreateOrderWorkflowInputregion_id
stringOptionalcustomer_id
stringOptionalsales_channel_id
stringOptionalstatus
stringOptionalemail
stringOptionalcurrency_code
stringOptionalshipping_address_id
stringOptionalbilling_address_id
stringOptionalno_notification
booleanOptionalmetadata
null | Record<string, unknown>Optionalpromo_codes
string[]Optionaladditional_data
Record<string, unknown>Optionaladditional_data
property in HTTP requests.
Learn more in this documentation.OrderDTO
OrderDTOid
stringversion
numberdisplay_id
numberstatus
OrderStatuscurrency_code
stringcreated_at
string | Dateupdated_at
string | Dateoriginal_item_total
BigNumberValueoriginal_item_subtotal
BigNumberValueoriginal_item_tax_total
BigNumberValueitem_total
BigNumberValueitem_subtotal
BigNumberValueitem_tax_total
BigNumberValueoriginal_total
BigNumberValueoriginal_subtotal
BigNumberValueoriginal_tax_total
BigNumberValuetotal
BigNumberValuesubtotal
BigNumberValuetax_total
BigNumberValuediscount_subtotal
BigNumberValuediscount_total
BigNumberValuediscount_tax_total
BigNumberValuegift_card_total
BigNumberValuegift_card_tax_total
BigNumberValueshipping_total
BigNumberValueshipping_subtotal
BigNumberValueshipping_tax_total
BigNumberValueoriginal_shipping_total
BigNumberValueoriginal_shipping_subtotal
BigNumberValueoriginal_shipping_tax_total
BigNumberValueraw_original_item_total
BigNumberRawValueraw_original_item_subtotal
BigNumberRawValueraw_original_item_tax_total
BigNumberRawValueraw_item_total
BigNumberRawValueraw_item_subtotal
BigNumberRawValueraw_item_tax_total
BigNumberRawValueraw_original_total
BigNumberRawValueraw_original_subtotal
BigNumberRawValueraw_original_tax_total
BigNumberRawValueraw_total
BigNumberRawValueraw_subtotal
BigNumberRawValueraw_tax_total
BigNumberRawValueraw_discount_total
BigNumberRawValueraw_discount_tax_total
BigNumberRawValueraw_gift_card_total
BigNumberRawValueraw_gift_card_tax_total
BigNumberRawValueraw_shipping_total
BigNumberRawValueraw_shipping_subtotal
BigNumberRawValueraw_shipping_tax_total
BigNumberRawValueraw_original_shipping_total
BigNumberRawValueraw_original_shipping_subtotal
BigNumberRawValueraw_original_shipping_tax_total
BigNumberRawValueregion_id
stringOptionalcustomer_id
stringOptionalsales_channel_id
stringOptionalemail
stringOptionalis_draft_order
booleanOptionalmetadata
null | Record<string, unknown>Optionalcanceled_at
string | DateOptionalHooks allow you to inject custom functionalities into the workflow. You'll receive data from the workflow, as well as additional data sent through an HTTP request.
Learn more about Hooks and Additional Data.
This hook is executed after the order is retrieved and before the line items are created. You can consume this hook to return any custom context useful for the prices retrieval of the variants to be added to the order.
For example, assuming you have the following custom pricing rule:
You can consume the setPricingContext
hook to add the location_id
context to the prices calculation:
1import { createOrderWorkflow } from "@medusajs/medusa/core-flows";2import { StepResponse } from "@medusajs/workflows-sdk";3 4createOrderWorkflow.hooks.setPricingContext((5 { variantIds, region, customerData, additional_data }, { container }6) => {7 return new StepResponse({8 location_id: "sloc_123", // Special price for in-store purchases9 });10});
The variants' prices will now be retrieved using the context you return.
Handlers consuming this hook accept the following input.
input
inputvariantIds
string[]region
RegionDTOcustomerData
FindOrCreateCustomerOutputStepOutputadditional_data
Record<string, unknown> | undefinedadditional_data
property in HTTP requests.
Learn more in this documentation.This hook is executed after the order is created. You can consume this hook to perform custom actions on the created order.
Handlers consuming this hook accept the following input.
input
inputorder
OrderDTOadditional_data
Record<string, unknown> | undefinedadditional_data
property in HTTP requests.
Learn more in this documentation.