addOrderLineItemsWorkflow - Medusa Core Workflows Reference
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 CodeExamples#
Steps#
Workflow hook
Step conditioned by when
View step details
Input#
OrderAddLineItemWorkflowInput & AdditionalData
OrderAddLineItemWorkflowInput & AdditionalData
OrderAddLineItemWorkflowInput & AdditionalData
OrderAddLineItemWorkflowInput & AdditionalDataOrderAddLineItemWorkflowInput
OrderAddLineItemWorkflowInput
OrderAddLineItemWorkflowInput
OrderAddLineItemWorkflowInputAdditionalData
AdditionalData
AdditionalData
AdditionalDataOutput#
OrderLineItemDTO[]
OrderLineItemDTO[]
OrderLineItemDTO[]
OrderLineItemDTO[]original_total
BigNumberValueThe original total of the order line item.
original_total
BigNumberValueoriginal_subtotal
BigNumberValueThe original subtotal of the order line item.
original_subtotal
BigNumberValueoriginal_tax_total
BigNumberValueThe original tax total of the order line item.
original_tax_total
BigNumberValueitem_total
BigNumberValueThe item total of the order line item.
item_total
BigNumberValueitem_subtotal
BigNumberValueThe item subtotal of the order line item.
item_subtotal
BigNumberValueitem_tax_total
BigNumberValueThe item tax total of the order line item.
item_tax_total
BigNumberValuetotal
BigNumberValueThe total of the order line item.
total
BigNumberValuesubtotal
BigNumberValueThe subtotal of the order line item.
subtotal
BigNumberValuetax_total
BigNumberValueThe tax total of the order line item.
tax_total
BigNumberValuediscount_total
BigNumberValueThe discount total of the order line item.
discount_total
BigNumberValuediscount_tax_total
BigNumberValueThe discount tax total of the order line item.
discount_tax_total
BigNumberValuerefundable_total
BigNumberValueThe refundable total of the order line item.
refundable_total
BigNumberValuerefundable_total_per_unit
BigNumberValueThe refundable total per unit of the order line item.
refundable_total_per_unit
BigNumberValueraw_original_total
BigNumberRawValueThe raw original total of the order line item.
raw_original_total
BigNumberRawValueraw_original_subtotal
BigNumberRawValueThe raw original subtotal of the order line item.
raw_original_subtotal
BigNumberRawValueraw_original_tax_total
BigNumberRawValueThe raw original tax total of the order line item.
raw_original_tax_total
BigNumberRawValueraw_item_total
BigNumberRawValueThe raw item total of the order line item.
raw_item_total
BigNumberRawValueraw_item_subtotal
BigNumberRawValueThe raw item subtotal of the order line item.
raw_item_subtotal
BigNumberRawValueraw_item_tax_total
BigNumberRawValueThe raw item tax total of the order line item.
raw_item_tax_total
BigNumberRawValueraw_total
BigNumberRawValueThe raw total of the order line item.
raw_total
BigNumberRawValueraw_subtotal
BigNumberRawValueThe raw subtotal of the order line item.
raw_subtotal
BigNumberRawValueraw_tax_total
BigNumberRawValueThe raw tax total of the order line item.
raw_tax_total
BigNumberRawValueraw_discount_total
BigNumberRawValueThe raw discount total of the order line item.
raw_discount_total
BigNumberRawValueraw_discount_tax_total
BigNumberRawValueThe raw discount tax total of the order line item.
raw_discount_tax_total
BigNumberRawValueraw_refundable_total
BigNumberRawValueThe raw refundable total of the order line item..
raw_refundable_total
BigNumberRawValueraw_refundable_total_per_unit
BigNumberRawValueThe raw refundable total per unit of the order line item.
raw_refundable_total_per_unit
BigNumberRawValueid
stringThe ID of the line item.
id
stringtitle
stringThe title of the line item.
title
stringrequires_shipping
booleanIndicates whether the line item requires shipping.
requires_shipping
booleanis_discountable
booleanIndicates whether the line item is discountable.
is_discountable
booleanis_giftcard
booleanIndicates whether the line item is a gift card.
is_giftcard
booleanis_tax_inclusive
booleanIndicates whether the line item price is tax inclusive.
is_tax_inclusive
booleanunit_price
numberThe unit price of the line item.
unit_price
numberraw_unit_price
BigNumberRawValueThe raw unit price of the line item.
raw_unit_price
BigNumberRawValuequantity
numberThe quantity of the line item.
quantity
numberraw_quantity
BigNumberRawValueThe raw quantity of the line item.
raw_quantity
BigNumberRawValuedetail
OrderItemDTOThe details of the item
detail
OrderItemDTOcreated_at
DateThe date when the line item was created.
created_at
Dateupdated_at
DateThe date when the line item was last updated.
updated_at
Datesubtitle
null | stringOptionalThe subtitle of the line item.
subtitle
null | stringOptionalthumbnail
null | stringOptionalThe thumbnail of the line item.
thumbnail
null | stringOptionalvariant_id
null | stringOptionalThe ID of the variant associated with the line item.
variant_id
null | stringOptionalproduct_id
null | stringOptionalThe ID of the product associated with the line item.
product_id
null | stringOptionalproduct_title
null | stringOptionalThe title of the product associated with the line item.
product_title
null | stringOptionalproduct_description
null | stringOptionalThe description of the product associated with the line item.
product_description
null | stringOptionalproduct_subtitle
null | stringOptionalThe subtitle of the product associated with the line item.
product_subtitle
null | stringOptionalproduct_type_id
null | stringOptionalThe ID of the type of the product associated with the line item.
product_type_id
null | stringOptionalproduct_type
null | stringOptionalThe type of the product associated with the line item.
product_type
null | stringOptionalproduct_collection
null | stringOptionalThe collection of the product associated with the line item.
product_collection
null | stringOptionalproduct_handle
null | stringOptionalThe handle of the product associated with the line item.
product_handle
null | stringOptionalvariant_sku
null | stringOptionalThe SKU (stock keeping unit) of the variant associated with the line item.
variant_sku
null | stringOptionalvariant_barcode
null | stringOptionalThe barcode of the variant associated with the line item.
variant_barcode
null | stringOptionalvariant_title
null | stringOptionalThe title of the variant associated with the line item.
variant_title
null | stringOptionalvariant_option_values
null | Record<string, unknown>OptionalThe option values of the variant associated with the line item.
variant_option_values
null | Record<string, unknown>Optionalcompare_at_unit_price
numberOptionalThe compare at unit price of the line item.
compare_at_unit_price
numberOptionalThe raw compare at unit price of the line item.
The associated tax lines.
The associated adjustments.
metadata
null | Record<string, unknown>OptionalHolds custom data in key-value pairs.
metadata
null | Record<string, unknown>OptionalHooks#
Hooks 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.
setPricingContext#
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.
Example
Input
Handlers consuming this hook accept the following input.
input
inputThe input data for the hook.
input
inputorder
any
order
anyvariantIds
string[]
variantIds
string[]region
RegionDTOThe region details.
region
RegionDTOcustomerData
FindOrCreateCustomerOutputStepOutputThe details of the customer found or created.
customerData
FindOrCreateCustomerOutputStepOutputadditional_data
Record<string, unknown> | undefinedAdditional data that can be passed through the additional_data
property in HTTP requests.
Learn more in this documentation.
additional_data
Record<string, unknown> | undefinedadditional_data
property in HTTP requests.
Learn more in this documentation.