Skip to main content
Skip to main content

OrderService

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
addressRepository_Repository<Address>Required
cartService_CartServiceRequired
customerService_CustomerServiceRequired
discountService_DiscountServiceRequired
draftOrderService_DraftOrderServiceRequired
eventBus_EventBusServiceRequired
featureFlagRouter_FlagRouterRequired
fulfillmentProviderService_FulfillmentProviderServiceRequired
fulfillmentService_FulfillmentServiceRequired
getTotalsRelationsanyRequired
giftCardService_GiftCardServiceRequired
inventoryService_IInventoryServiceRequired
lineItemService_LineItemServiceRequired
manager_EntityManagerRequired
newTotalsService_NewTotalsServiceRequired
orderRepository_Repository<Order> & &#123; findOneWithRelations: Method findOneWithRelations ; findWithRelations: Method findWithRelations &#125;Required
paymentProviderService_PaymentProviderServiceRequired
productVariantInventoryService_ProductVariantInventoryServiceRequired
regionService_RegionServiceRequired
shippingOptionService_ShippingOptionServiceRequired
shippingProfileService_ShippingProfileServiceRequired
taxProviderService_TaxProviderServiceRequired
totalsService_TotalsServiceRequired
transactionManager_undefined | EntityManagerRequired
EventsobjectRequired
Events.CANCELEDstringRequired
Events.COMPLETEDstringRequired
Events.FULFILLMENT_CANCELEDstringRequired
Events.FULFILLMENT_CREATEDstringRequired
Events.GIFT_CARD_CREATEDstringRequired
Events.ITEMS_RETURNEDstringRequired
Events.PAYMENT_CAPTUREDstringRequired
Events.PAYMENT_CAPTURE_FAILEDstringRequired
Events.PLACEDstringRequired
Events.REFUND_CREATEDstringRequired
Events.REFUND_FAILEDstringRequired
Events.RETURN_ACTION_REQUIREDstringRequired
Events.RETURN_REQUESTEDstringRequired
Events.SHIPMENT_CREATEDstringRequired
Events.SWAP_CREATEDstringRequired
Events.UPDATEDstringRequired

Accessors

activeManager_

Returns

EntityManagerEntityManagerRequired

Methods

addShippingMethod

Parameters

orderIdstringRequired
optionIdstringRequired
dataRecord<string, unknown>

Returns

PromisePromise<Order>Required

archive

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

Parameters

orderIdstringRequired
the order to archive

Returns

PromisePromise<Order>Required
the result of the update operation

atomicPhase_

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.

Parameters

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

Returns

PromisePromise<TResult>Required
the result of the transactional work

cancel

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

Parameters

orderIdstringRequired
id of order to cancel.

Returns

PromisePromise<Order>Required
result of the update operation.

cancelFulfillment

Cancels a fulfillment (if related to an order)

Parameters

fulfillmentIdstringRequired
the ID of the fulfillment to cancel

Returns

PromisePromise<Order>Required
updated order

capturePayment

Captures payment for an order.

Parameters

orderIdstringRequired
id of order to capture payment for.

Returns

PromisePromise<Order>Required
result of the update operation.

completeOrder

Parameters

orderIdstringRequired
id of the order to complete

Returns

PromisePromise<Order>Required
the result of the find operation

createFromCart

Creates an order from a cart

Parameters

cartOrIdstring | CartRequired

Returns

PromisePromise<Order>Required
resolves to the creation result.

createFulfillment

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

orderIdstringRequired
id of order to fulfil.
itemsToFulfillFulFillmentItemType[]Required
items to fulfil.
configobject
the config to fulfil.
config.location_idstring
config.metadataRecord<string, unknown>
config.no_notificationboolean

Returns

PromisePromise<Order>Required
result of the update operation.

createGiftCardsFromLineItem_

Parameters

orderOrderRequired
An order is a purchase made by a customer. It holds details about payment and fulfillment of the order. An order may also be created from a draft order, which is created by an admin user.
lineItemLineItemRequired
Line Items are created when a product is added to a Cart. When Line Items are purchased they will get copied to the resulting order, swap, or claim, and can eventually be referenced in Fulfillments and Returns. Line items may also be used for order edits.
managerEntityManagerRequired

Returns

Promise&#60;GiftCard&#62;[]Promise<GiftCard>[]Required

createRefund

Refunds a given amount back to the customer.

Parameters

orderIdstringRequired
id of the order to refund.
refundAmountnumberRequired
the amount to refund.
reasonstringRequired
the reason to refund.
notestring
note for refund.
configobject
the config for refund.
config.no_notificationboolean

Returns

PromisePromise<Order>Required
the result of the refund operation.

createShipment

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

orderIdstringRequired
the id of the order that has been shipped
fulfillmentIdstringRequired
the fulfillment that has now been shipped
trackingLinksTrackingLink[]
array of tracking numbers associated with the shipment
configobject
the config of the order that has been shipped
config.metadataRecord<string, unknown>Required
config.no_notificationboolean

Returns

PromisePromise<Order>Required
the resulting order following the update.

decorateTotals

**decorateTotals**(order, totalsFields?): Promise&#60;[Order](/references/js-client/internal/classes/internal.Order)&#62;

Parameters

orderOrderRequired
An order is a purchase made by a customer. It holds details about payment and fulfillment of the order. An order may also be created from a draft order, which is created by an admin user.
totalsFieldsstring[]

Returns

PromisePromise<Order>Required

**decorateTotals**(order, context?): Promise&#60;[Order](/references/js-client/internal/classes/internal.Order)&#62;

Parameters

orderOrderRequired
An order is a purchase made by a customer. It holds details about payment and fulfillment of the order. An order may also be created from a draft order, which is created by an admin user.

Returns

PromisePromise<Order>Required

decorateTotalsLegacy

Parameters

orderOrderRequired
An order is a purchase made by a customer. It holds details about payment and fulfillment of the order. An order may also be created from a draft order, which is created by an admin user.
totalsFieldsstring[]

Returns

PromisePromise<Order>Required

getFulfillmentItems

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

Parameters

orderOrderRequired
the order to get line items from
itemsFulFillmentItemType[]Required
the items to get
transformer(item: undefined | LineItem, quantity: number) => unknownRequired
a 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

PromisePromise<LineItem[]>Required
the line items generated by the transformer.

list

Parameters

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

Returns

PromisePromise<Order[]>Required
the result of the find operation

listAndCount

Parameters

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

Returns

PromisePromise<[Order[], number]>Required
the result of the find operation

registerReturnReceived

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 situations where a custom refund amount is requested, but the returned items are not matching the requested items. Setting the allowMismatch argument to true, will process the return, ignoring any mismatches.

Parameters

orderIdstringRequired
the order to return.
receivedReturnReturnRequired
the received return
customRefundAmountnumber
the custom refund amount return

Returns

PromisePromise<Order>Required
the result of the update operation

retrieve

Gets an order by id.

Parameters

orderIdstringRequired
id or selector of order to retrieve
config of order to retrieve

Returns

PromisePromise<Order>Required
the order document

retrieveByCartId

Gets an order by cart id.

Parameters

cartIdstringRequired
cart id to find order
the config to be used to find order

Returns

PromisePromise<Order>Required
the order document

retrieveByCartIdWithTotals

Parameters

cartIdstringRequired

Returns

PromisePromise<Order>Required

retrieveByExternalId

Gets an order by id.

Parameters

externalIdstringRequired
id of order to retrieve
query config to get order by

Returns

PromisePromise<Order>Required
the order document

retrieveLegacy

Parameters

orderIdOrSelectorstring | Selector<Order>Required

Returns

PromisePromise<Order>Required

retrieveWithTotals

Parameters

orderIdstringRequired

Returns

PromisePromise<Order>Required

shouldRetryTransaction_

Parameters

errRecord<string, unknown> | &#123; code: string &#125;Required

Returns

booleanboolean

transformQueryForTotals

Parameters

configFindConfig<Order>Required

Returns

objectobject
relationsundefined | string[]Required
selectundefined | keyof Order[]Required
totalsToSelectundefined | keyof Order[]Required

update

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

Parameters

orderIdstringRequired
the id of the order. Must be a string that can be casted to an ObjectId
updateUpdateOrderInputRequired
an object with the update values.

Returns

PromisePromise<Order>Required
resolves to the update result.

updateBillingAddress

Updates the order's billing address.

Parameters

orderOrderRequired
the order to update
addressAddressRequired
the value to set the billing address to

Returns

PromisePromise<void>Required
the result of the update operation

updateShippingAddress

Updates the order's shipping address.

Parameters

orderOrderRequired
the order to update
addressAddressRequired
the value to set the shipping address to

Returns

PromisePromise<void>Required
the result of the update operation

validateFulfillmentLineItem

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

itemLineItemRequired
the line item to check has sufficient fulfillable quantity.
quantitynumberRequired
the quantity that is requested to be fulfilled.

Returns

`null` \| LineItemnull | LineItem
a line item that has the requested fulfillment quantity set.

withTransaction

Parameters

transactionManagerEntityManager

Returns

OrderServiceOrderServiceRequired
Was this section helpful?