Skip to main content

Class: OrderService

Hierarchy​

  • TransactionBaseService

    ↳ OrderService

Constructors​

constructor​

• new OrderService(__namedParameters)

Parameters​

NameType
__namedParametersInjectedDependencies

Overrides​

TransactionBaseService.constructor

Defined in​

medusa/src/services/order.ts:137

Properties​

__configModule__​

• Protected Optional Readonly __configModule__: Record<string, unknown>

Inherited from​

TransactionBaseService.__configModule__

Defined in​

medusa/src/interfaces/transaction-base-service.ts:14


__container__​

• Protected Readonly __container__: any

Inherited from​

TransactionBaseService.__container__

Defined in​

medusa/src/interfaces/transaction-base-service.ts:13


__moduleDeclaration__​

• Protected Optional Readonly __moduleDeclaration__: Record<string, unknown>

Inherited from​

TransactionBaseService.__moduleDeclaration__

Defined in​

medusa/src/interfaces/transaction-base-service.ts:15


addressRepository_​

• Protected Readonly addressRepository_: Repository<Address>

Defined in​

medusa/src/services/order.ts:128


cartService_​

• Protected Readonly cartService_: CartService

Defined in​

medusa/src/services/order.ts:127


customerService_​

• Protected Readonly customerService_: CustomerService

Defined in​

medusa/src/services/order.ts:115


discountService_​

• Protected Readonly discountService_: DiscountService

Defined in​

medusa/src/services/order.ts:119


draftOrderService_​

• Protected Readonly draftOrderService_: DraftOrderService

Defined in​

medusa/src/services/order.ts:130


eventBus_​

• Protected Readonly eventBus_: EventBusService

Defined in​

medusa/src/services/order.ts:132


featureFlagRouter_​

• Protected Readonly featureFlagRouter_: FlagRouter

Defined in​

medusa/src/services/order.ts:133


fulfillmentProviderService_​

• Protected Readonly fulfillmentProviderService_: FulfillmentProviderService

Defined in​

medusa/src/services/order.ts:120


fulfillmentService_​

• Protected Readonly fulfillmentService_: FulfillmentService

Defined in​

medusa/src/services/order.ts:121


giftCardService_​

• Protected Readonly giftCardService_: GiftCardService

Defined in​

medusa/src/services/order.ts:129


inventoryService_​

• Protected Readonly inventoryService_: IInventoryService

Defined in​

medusa/src/services/order.ts:131


lineItemService_​

• Protected Readonly lineItemService_: LineItemService

Defined in​

medusa/src/services/order.ts:122


manager_​

• Protected manager_: EntityManager

Inherited from​

TransactionBaseService.manager_

Defined in​

medusa/src/interfaces/transaction-base-service.ts:5


newTotalsService_​

• Protected Readonly newTotalsService_: NewTotalsService

Defined in​

medusa/src/services/order.ts:124


orderRepository_​

• Protected Readonly orderRepository_: Repository<Order> & { findOneWithRelations: (relations: FindOptionsRelations<Order>, optionsWithoutRelations: Omit<FindManyOptions<Order>, "relations">) => Promise<Order> ; findWithRelations: (relations: FindOptionsRelations<Order>, optionsWithoutRelations: Omit<FindManyOptions<Order>, "relations">) => Promise<Order[]> }

Defined in​

medusa/src/services/order.ts:114


paymentProviderService_​

• Protected Readonly paymentProviderService_: PaymentProviderService

Defined in​

medusa/src/services/order.ts:116


productVariantInventoryService_​

• Protected Readonly productVariantInventoryService_: ProductVariantInventoryService

Defined in​

medusa/src/services/order.ts:135


regionService_​

• Protected Readonly regionService_: RegionService

Defined in​

medusa/src/services/order.ts:126


shippingOptionService_​

• Protected Readonly shippingOptionService_: ShippingOptionService

Defined in​

medusa/src/services/order.ts:117


shippingProfileService_​

• Protected Readonly shippingProfileService_: ShippingProfileService

Defined in​

medusa/src/services/order.ts:118


taxProviderService_​

• Protected Readonly taxProviderService_: TaxProviderService

Defined in​

medusa/src/services/order.ts:125


totalsService_​

• Protected Readonly totalsService_: TotalsService

Defined in​

medusa/src/services/order.ts:123


transactionManager_​

• Protected transactionManager_: undefined | EntityManager

Inherited from​

TransactionBaseService.transactionManager_

Defined in​

medusa/src/interfaces/transaction-base-service.ts:6


Events​

▪ Static Readonly Events: Object

Type declaration​

NameType
CANCELEDstring
COMPLETEDstring
FULFILLMENT_CANCELEDstring
FULFILLMENT_CREATEDstring
GIFT_CARD_CREATEDstring
ITEMS_RETURNEDstring
PAYMENT_CAPTUREDstring
PAYMENT_CAPTURE_FAILEDstring
PLACEDstring
REFUND_CREATEDstring
REFUND_FAILEDstring
RETURN_ACTION_REQUIREDstring
RETURN_REQUESTEDstring
SHIPMENT_CREATEDstring
SWAP_CREATEDstring
UPDATEDstring

Defined in​

medusa/src/services/order.ts:95

Accessors​

activeManager_​

• Protected get activeManager_(): EntityManager

Returns​

EntityManager

Inherited from​

TransactionBaseService.activeManager_

Defined in​

medusa/src/interfaces/transaction-base-service.ts:8

Methods​

addShippingMethod​

▸ addShippingMethod(orderId, optionId, data?, config?): Promise<Order>

Parameters​

NameType
orderIdstring
optionIdstring
data?Record<string, unknown>
configCreateShippingMethodDto

Returns​

Promise<Order>

Defined in​

medusa/src/services/order.ts:1024


archive​

▸ archive(orderId): Promise<Order>

Archives an order. It only alloved, if the order has been fulfilled and payment has been captured.

Parameters​

NameTypeDescription
orderIdstringthe order to archive

Returns​

Promise<Order>

the result of the update operation

Defined in​

medusa/src/services/order.ts:1556


atomicPhase_​

▸ Protected atomicPhase_<TResult, TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise<TResult>

Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.

Type parameters​

Name
TResult
TError

Parameters​

NameTypeDescription
work(transactionManager: EntityManager) => Promise<TResult>the transactional work to be done
isolationOrErrorHandler?IsolationLevel | (error: TError) => Promise<void | TResult>the isolation level to be used for the work.
maybeErrorHandlerOrDontFail?(error: TError) => Promise<void | TResult>Potential error handler

Returns​

Promise<TResult>

the result of the transactional work

Inherited from​

TransactionBaseService.atomicPhase_

Defined in​

medusa/src/interfaces/transaction-base-service.ts:56


cancel​

▸ cancel(orderId): Promise<Order>

Cancels an order. Throws if fulfillment process has been initiated. Throws if payment process has been initiated.

Parameters​

NameTypeDescription
orderIdstringid of order to cancel.

Returns​

Promise<Order>

result of the update operation.

Defined in​

medusa/src/services/order.ts:1174


cancelFulfillment​

▸ cancelFulfillment(fulfillmentId): Promise<Order>

Cancels a fulfillment (if related to an order)

Parameters​

NameTypeDescription
fulfillmentIdstringthe ID of the fulfillment to cancel

Returns​

Promise<Order>

updated order

Defined in​

medusa/src/services/order.ts:1493


capturePayment​

▸ capturePayment(orderId): Promise<Order>

Captures payment for an order.

Parameters​

NameTypeDescription
orderIdstringid of order to capture payment for.

Returns​

Promise<Order>

result of the update operation.

Defined in​

medusa/src/services/order.ts:1263


completeOrder​

▸ completeOrder(orderId): Promise<Order>

Parameters​

NameTypeDescription
orderIdstringid of the order to complete

Returns​

Promise<Order>

the result of the find operation

Defined in​

medusa/src/services/order.ts:577


createFromCart​

▸ createFromCart(cartOrId): Promise<Order>

Creates an order from a cart

Parameters​

NameType
cartOrIdstring | Cart

Returns​

Promise<Order>

resolves to the creation result.

Defined in​

medusa/src/services/order.ts:607


createFulfillment​

▸ createFulfillment(orderId, itemsToFulfill, config?): Promise<Order>

Creates fulfillments for an order. In a situation where the order has more than one shipping method, we need to partition the order items, such that they can be sent to their respective fulfillment provider.

Parameters​

NameTypeDescription
orderIdstringid of order to fulfil.
itemsToFulfillFulFillmentItemType[]items to fulfil.
configObjectthe config to fulfil.
config.location_id?string-
config.metadata?Record<string, unknown>-
config.no_notification?boolean-

Returns​

Promise<Order>

result of the update operation.

Defined in​

medusa/src/services/order.ts:1368


createGiftCardsFromLineItem_​

▸ Protected createGiftCardsFromLineItem_(order, lineItem, manager): Promise<GiftCard>[]

Parameters​

NameType
orderOrder
lineItemLineItem
managerEntityManager

Returns​

Promise<GiftCard>[]

Defined in​

medusa/src/services/order.ts:804


createRefund​

▸ createRefund(orderId, refundAmount, reason, note?, config?): Promise<Order>

Refunds a given amount back to the customer.

Parameters​

NameTypeDescription
orderIdstringid of the order to refund.
refundAmountnumberthe amount to refund.
reasonstringthe reason to refund.
note?stringnote for refund.
configObjectthe config for refund.
config.no_notification?boolean-

Returns​

Promise<Order>

the result of the refund operation.

Defined in​

medusa/src/services/order.ts:1582


createShipment​

▸ createShipment(orderId, fulfillmentId, trackingLinks?, config?): Promise<Order>

Adds a shipment to the order to indicate that an order has left the warehouse. Will ask the fulfillment provider for any documents that may have been created in regards to the shipment.

Parameters​

NameTypeDescription
orderIdstringthe id of the order that has been shipped
fulfillmentIdstringthe fulfillment that has now been shipped
trackingLinks?TrackingLink[]array of tracking numebers associated with the shipment
configObjectthe config of the order that has been shipped
config.metadataRecord<string, unknown>-
config.no_notification?boolean-

Returns​

Promise<Order>

the resulting order following the update.

Defined in​

medusa/src/services/order.ts:858


decorateTotals​

▸ decorateTotals(order, totalsFields?): Promise<Order>

Calculate and attach the different total fields on the object

Parameters​

NameType
orderOrder
totalsFields?string[]

Returns​

Promise<Order>

Defined in​

medusa/src/services/order.ts:1779

▸ decorateTotals(order, context?): Promise<Order>

Calculate and attach the different total fields on the object

Parameters​

NameType
orderOrder
context?TotalsContext

Returns​

Promise<Order>

Defined in​

medusa/src/services/order.ts:1781


decorateTotalsLegacy​

▸ Protected decorateTotalsLegacy(order, totalsFields?): Promise<Order>

Parameters​

NameTypeDefault value
orderOrderundefined
totalsFieldsstring[][]

Returns​

Promise<Order>

Defined in​

medusa/src/services/order.ts:1650


getFulfillmentItems​

▸ Protected getFulfillmentItems(order, items, transformer): Promise<LineItem[]>

Retrieves the order line items, given an array of items.

Parameters​

NameTypeDescription
orderOrderthe order to get line items from
itemsFulFillmentItemType[]the items to get
transformer(item: undefined | LineItem, quantity: number) => unknowna function to apply to each of the items retrieved from the order, should return a line item. If the transformer returns an undefined value the line item will be filtered from the returned array.

Returns​

Promise<LineItem[]>

the line items generated by the transformer.

Defined in​

medusa/src/services/order.ts:1535


getTotalsRelations​

▸ Private getTotalsRelations(config): string[]

Parameters​

NameType
configFindConfig<Order>

Returns​

string[]

Defined in​

medusa/src/services/order.ts:2044


list​

▸ list(selector, config?): Promise<Order[]>

Parameters​

NameTypeDescription
selectorSelector<Order>the query object for find
configFindConfig<Order>the config to be used for find

Returns​

Promise<Order[]>

the result of the find operation

Defined in​

medusa/src/services/order.ts:189


listAndCount​

▸ listAndCount(selector, config?): Promise<[Order[], number]>

Parameters​

NameTypeDescription
selectorQuerySelector<Order>the query object for find
configFindConfig<Order>the config to be used for find

Returns​

Promise<[Order[], number]>

the result of the find operation

Defined in​

medusa/src/services/order.ts:206


registerReturnReceived​

▸ registerReturnReceived(orderId, receivedReturn, customRefundAmount?): Promise<Order>

Handles receiving a return. This will create a refund to the customer. If the returned items don't match the requested items the return status will be updated to requires_action. This behaviour is useful in sitautions where a custom refund amount is requested, but the retuned items are not matching the requested items. Setting the allowMismatch argument to true, will process the return, ignoring any mismatches.

Parameters​

NameTypeDescription
orderIdstringthe order to return.
receivedReturnReturnthe received return
customRefundAmount?numberthe custom refund amount return

Returns​

Promise<Order>

the result of the update operation

Defined in​

medusa/src/services/order.ts:1969


retrieve​

▸ retrieve(orderId, config?): Promise<Order>

Gets an order by id.

Parameters​

NameTypeDescription
orderIdstringid or selector of order to retrieve
configFindConfig<Order>config of order to retrieve

Returns​

Promise<Order>

the order document

Defined in​

medusa/src/services/order.ts:388


retrieveByCartId​

▸ retrieveByCartId(cartId, config?): Promise<Order>

Gets an order by cart id.

Parameters​

NameTypeDescription
cartIdstringcart id to find order
configFindConfig<Order>the config to be used to find order

Returns​

Promise<Order>

the order document

Defined in​

medusa/src/services/order.ts:484


retrieveByCartIdWithTotals​

▸ retrieveByCartIdWithTotals(cartId, options?): Promise<Order>

Parameters​

NameType
cartIdstring
optionsFindConfig<Order>

Returns​

Promise<Order>

Defined in​

medusa/src/services/order.ts:518


retrieveByExternalId​

▸ retrieveByExternalId(externalId, config?): Promise<Order>

Gets an order by id.

Parameters​

NameTypeDescription
externalIdstringid of order to retrieve
configFindConfig<Order>query config to get order by

Returns​

Promise<Order>

the order document

Defined in​

medusa/src/services/order.ts:533


retrieveLegacy​

▸ Protected retrieveLegacy(orderIdOrSelector, config?): Promise<Order>

Parameters​

NameType
orderIdOrSelectorstring | Selector<Order>
configFindConfig<Order>

Returns​

Promise<Order>

Defined in​

medusa/src/services/order.ts:428


retrieveWithTotals​

▸ retrieveWithTotals(orderId, options?, context?): Promise<Order>

Parameters​

NameType
orderIdstring
optionsFindConfig<Order>
contextTotalsContext

Returns​

Promise<Order>

Defined in​

medusa/src/services/order.ts:467


shouldRetryTransaction_​

▸ Protected shouldRetryTransaction_(err): boolean

Parameters​

NameType
errRecord<string, unknown> | { code: string }

Returns​

boolean

Inherited from​

TransactionBaseService.shouldRetryTransaction_

Defined in​

medusa/src/interfaces/transaction-base-service.ts:37


transformQueryForTotals​

▸ Protected transformQueryForTotals(config): Object

Parameters​

NameType
configFindConfig<Order>

Returns​

Object

NameType
relationsundefined | string[]
selectundefined | keyof Order[]
totalsToSelectundefined | keyof Order[]

Defined in​

medusa/src/services/order.ts:312


update​

▸ update(orderId, update): Promise<Order>

Updates an order. Metadata updates should use dedicated method, e.g. setMetadata etc. The function will throw errors if metadata updates are attempted.

Parameters​

NameTypeDescription
orderIdstringthe id of the order. Must be a string that can be casted to an ObjectId
updateUpdateOrderInputan object with the update values.

Returns​

Promise<Order>

resolves to the update result.

Defined in​

medusa/src/services/order.ts:1085


updateBillingAddress​

▸ Protected updateBillingAddress(order, address): Promise<void>

Updates the order's billing address.

Parameters​

NameTypeDescription
orderOrderthe order to update
addressAddressthe value to set the billing address to

Returns​

Promise<void>

the result of the update operation

Defined in​

medusa/src/services/order.ts:946


updateShippingAddress​

▸ Protected updateShippingAddress(order, address): Promise<void>

Updates the order's shipping address.

Parameters​

NameTypeDescription
orderOrderthe order to update
addressAddressthe value to set the shipping address to

Returns​

Promise<void>

the result of the update operation

Defined in​

medusa/src/services/order.ts:993


validateFulfillmentLineItem​

▸ Protected validateFulfillmentLineItem(item, quantity): null | LineItem

Checks that a given quantity of a line item can be fulfilled. Fails if the fulfillable quantity is lower than the requested fulfillment quantity. Fulfillable quantity is calculated by subtracting the already fulfilled quantity from the quantity that was originally purchased.

Parameters​

NameTypeDescription
itemLineItemthe line item to check has sufficient fulfillable quantity.
quantitynumberthe quantity that is requested to be fulfilled.

Returns​

null | LineItem

a line item that has the requested fulfillment quantity set.

Defined in​

medusa/src/services/order.ts:1335


withTransaction​

▸ withTransaction(transactionManager?): OrderService

Parameters​

NameType
transactionManager?EntityManager

Returns​

OrderService

Inherited from​

TransactionBaseService.withTransaction

Defined in​

medusa/src/interfaces/transaction-base-service.ts:20

Was this section helpful?