This documentation provides a reference to the addOrderLineItemsWorkflow
. It belongs to the @medusajs/medusa/core-flows
package.
This workflow adds line items to an order. This is useful when making edits to an order. It's used by other workflows, such as orderEditAddNewItemWorkflow.
You can use this workflow within your customizations or your own custom workflows, allowing you to wrap custom logic around adding items to an order.
Source CodeWorkflow hook
Step conditioned by when
View step details
OrderAddLineItemWorkflowInput & AdditionalData
OrderAddLineItemWorkflowInput & AdditionalDataOrderAddLineItemWorkflowInput
objectAdditionalData
objectadditional_data
property accepted in HTTP
requests, that allows passing custom data and handle them in hooks.
Learn more in this documentation.OrderLineItemDTO[]
OrderLineItemDTO[]original_total
BigNumberValueoriginal_subtotal
BigNumberValueoriginal_tax_total
BigNumberValueitem_total
BigNumberValueitem_subtotal
BigNumberValueitem_tax_total
BigNumberValuetotal
BigNumberValuesubtotal
BigNumberValuetax_total
BigNumberValuediscount_total
BigNumberValuediscount_tax_total
BigNumberValuerefundable_total
BigNumberValuerefundable_total_per_unit
BigNumberValueraw_original_total
BigNumberRawValueraw_original_subtotal
BigNumberRawValueraw_original_tax_total
BigNumberRawValueraw_item_total
BigNumberRawValueraw_item_subtotal
BigNumberRawValueraw_item_tax_total
BigNumberRawValueraw_total
BigNumberRawValueraw_subtotal
BigNumberRawValueraw_tax_total
BigNumberRawValueraw_discount_total
BigNumberRawValueraw_discount_tax_total
BigNumberRawValueraw_refundable_total
BigNumberRawValueraw_refundable_total_per_unit
BigNumberRawValueid
stringtitle
stringrequires_shipping
booleanis_discountable
booleanis_giftcard
booleanis_tax_inclusive
booleanunit_price
numberraw_unit_price
BigNumberRawValuequantity
numberraw_quantity
BigNumberRawValuedetail
OrderItemDTOcreated_at
Dateupdated_at
Datesubtitle
null | stringOptionalthumbnail
null | stringOptionalvariant_id
null | stringOptionalproduct_id
null | stringOptionalproduct_title
null | stringOptionalproduct_description
null | stringOptionalproduct_subtitle
null | stringOptionalproduct_type_id
null | stringOptionalproduct_type
null | stringOptionalproduct_collection
null | stringOptionalproduct_handle
null | stringOptionalvariant_sku
null | stringOptionalvariant_barcode
null | stringOptionalvariant_title
null | stringOptionalvariant_option_values
null | Record<string, unknown>Optionalcompare_at_unit_price
numberOptionalmetadata
null | Record<string, unknown>OptionalHooks 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 { addOrderLineItemsWorkflow } from "@medusajs/medusa/core-flows";2import { StepResponse } from "@medusajs/workflows-sdk";3 4addOrderLineItemsWorkflow.hooks.setPricingContext((5 { order, 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
inputorder
anyvariantIds
string[]region
RegionDTOcustomerData
FindOrCreateCustomerOutputStepOutputadditional_data
Record<string, unknown> | undefinedadditional_data
property in HTTP requests.
Learn more in this documentation.