--- displayed_sidebar: servicesSidebar --- import ParameterTypes from "@site/src/components/ParameterTypes" # OrderService ## Constructors ### constructor **new OrderService**(`«destructured»`) #### Parameters ## Properties ", "description": "", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "__container__", "type": "`any`", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "__moduleDeclaration__", "type": "Record<`string`, `unknown`\\>", "description": "", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "addressRepository_", "type": "`Repository`<[`Address`](Address.mdx)\\>", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "cartService_", "type": "[`CartService`](CartService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "customerService_", "type": "[`CustomerService`](CustomerService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "discountService_", "type": "[`DiscountService`](DiscountService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "draftOrderService_", "type": "[`DraftOrderService`](DraftOrderService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "eventBus_", "type": "[`EventBusService`](EventBusService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "featureFlagRouter_", "type": "[`FlagRouter`](FlagRouter.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "fulfillmentProviderService_", "type": "[`FulfillmentProviderService`](FulfillmentProviderService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "fulfillmentService_", "type": "[`FulfillmentService`](FulfillmentService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "giftCardService_", "type": "[`GiftCardService`](GiftCardService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "inventoryService_", "type": "[`IInventoryService`](../interfaces/IInventoryService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "lineItemService_", "type": "[`LineItemService`](LineItemService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "manager_", "type": "`EntityManager`", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "newTotalsService_", "type": "[`NewTotalsService`](NewTotalsService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "orderRepository_", "type": "`Repository`<[`Order`](Order.mdx)\\> & { `findOneWithRelations`: Method findOneWithRelations ; `findWithRelations`: Method findWithRelations }", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "paymentProviderService_", "type": "[`PaymentProviderService`](PaymentProviderService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "productVariantInventoryService_", "type": "[`ProductVariantInventoryService`](ProductVariantInventoryService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "regionService_", "type": "[`RegionService`](RegionService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "shippingOptionService_", "type": "[`ShippingOptionService`](ShippingOptionService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "shippingProfileService_", "type": "[`ShippingProfileService`](ShippingProfileService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "taxProviderService_", "type": "[`TaxProviderService`](TaxProviderService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "totalsService_", "type": "[`TotalsService`](TotalsService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "transactionManager_", "type": "`undefined` \\| `EntityManager`", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "Events", "type": "`object`", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "Events.CANCELED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.canceled\"", "expandable": false, "children": [] }, { "name": "Events.COMPLETED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.completed\"", "expandable": false, "children": [] }, { "name": "Events.FULFILLMENT_CANCELED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.fulfillment_canceled\"", "expandable": false, "children": [] }, { "name": "Events.FULFILLMENT_CREATED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.fulfillment_created\"", "expandable": false, "children": [] }, { "name": "Events.GIFT_CARD_CREATED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.gift_card_created\"", "expandable": false, "children": [] }, { "name": "Events.ITEMS_RETURNED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.items_returned\"", "expandable": false, "children": [] }, { "name": "Events.PAYMENT_CAPTURED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.payment_captured\"", "expandable": false, "children": [] }, { "name": "Events.PAYMENT_CAPTURE_FAILED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.payment_capture_failed\"", "expandable": false, "children": [] }, { "name": "Events.PLACED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.placed\"", "expandable": false, "children": [] }, { "name": "Events.REFUND_CREATED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.refund_created\"", "expandable": false, "children": [] }, { "name": "Events.REFUND_FAILED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.refund_failed\"", "expandable": false, "children": [] }, { "name": "Events.RETURN_ACTION_REQUIRED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.return_action_required\"", "expandable": false, "children": [] }, { "name": "Events.RETURN_REQUESTED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.return_requested\"", "expandable": false, "children": [] }, { "name": "Events.SHIPMENT_CREATED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.shipment_created\"", "expandable": false, "children": [] }, { "name": "Events.SWAP_CREATED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.swap_created\"", "expandable": false, "children": [] }, { "name": "Events.UPDATED", "type": "`string`", "description": "", "optional": false, "defaultValue": "\"order.updated\"", "expandable": false, "children": [] } ]} /> ## Accessors ### activeManager\_ `Protected` `get` **activeManager_**(): `EntityManager` #### Returns `EntityManager` ## Methods ### addShippingMethod **addShippingMethod**(`orderId`, `optionId`, `data?`, `config?`): `Promise`<[`Order`](Order.mdx)\> #### Parameters ", "description": "", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "config", "type": "[`CreateShippingMethodDto`](../types/CreateShippingMethodDto.mdx)", "description": "", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "", "expandable": false, "children": [] } ]} /> ___ ### archive **archive**(`orderId`): `Promise`<[`Order`](Order.mdx)\> Archives an order. It only alloved, if the order has been fulfilled and payment has been captured. #### Parameters #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "the result of the update operation", "expandable": false, "children": [] } ]} /> ___ ### 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. #### Parameters `Promise`<`TResult`\\>", "description": "the transactional work to be done", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "isolationOrErrorHandler", "type": "`IsolationLevel` \\| (`error`: `TError`) => `Promise`<`void` \\| `TResult`\\>", "description": "the isolation level to be used for the work.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "maybeErrorHandlerOrDontFail", "type": "(`error`: `TError`) => `Promise`<`void` \\| `TResult`\\>", "description": "Potential error handler", "optional": true, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns `Promise`<`TResult`\> ", "optional": false, "defaultValue": "", "description": "the result of the transactional work", "expandable": false, "children": [] } ]} /> ___ ### cancel **cancel**(`orderId`): `Promise`<[`Order`](Order.mdx)\> Cancels an order. Throws if fulfillment process has been initiated. Throws if payment process has been initiated. #### Parameters #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "result of the update operation.", "expandable": false, "children": [] } ]} /> ___ ### cancelFulfillment **cancelFulfillment**(`fulfillmentId`): `Promise`<[`Order`](Order.mdx)\> Cancels a fulfillment (if related to an order) #### Parameters #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "updated order", "expandable": false, "children": [] } ]} /> ___ ### capturePayment **capturePayment**(`orderId`): `Promise`<[`Order`](Order.mdx)\> Captures payment for an order. #### Parameters #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "result of the update operation.", "expandable": false, "children": [] } ]} /> ___ ### completeOrder **completeOrder**(`orderId`): `Promise`<[`Order`](Order.mdx)\> #### Parameters #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "the result of the find operation", "expandable": false, "children": [] } ]} /> ___ ### createFromCart **createFromCart**(`cartOrId`): `Promise`<[`Order`](Order.mdx)\> Creates an order from a cart #### Parameters #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "resolves to the creation result.", "expandable": false, "children": [] } ]} /> ___ ### createFulfillment **createFulfillment**(`orderId`, `itemsToFulfill`, `config?`): `Promise`<[`Order`](Order.mdx)\> 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 ", "description": "", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "config.no_notification", "type": "`boolean`", "description": "", "optional": true, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "result of the update operation.", "expandable": false, "children": [] } ]} /> ___ ### createGiftCardsFromLineItem\_ `Protected` **createGiftCardsFromLineItem_**(`order`, `lineItem`, `manager`): `Promise`<[`GiftCard`](GiftCard.mdx)\>[] #### Parameters #### Returns `Promise`<[`GiftCard`](GiftCard.mdx)\>[] []", "type": "`Promise`<[`GiftCard`](GiftCard.mdx)\\>[]", "optional": false, "defaultValue": "", "description": "", "expandable": false, "children": [] } ]} /> ___ ### createRefund **createRefund**(`orderId`, `refundAmount`, `reason`, `note?`, `config?`): `Promise`<[`Order`](Order.mdx)\> Refunds a given amount back to the customer. #### Parameters #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "the result of the refund operation.", "expandable": false, "children": [] } ]} /> ___ ### createShipment **createShipment**(`orderId`, `fulfillmentId`, `trackingLinks?`, `config?`): `Promise`<[`Order`](Order.mdx)\> 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 ", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "config.no_notification", "type": "`boolean`", "description": "", "optional": true, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "the resulting order following the update.", "expandable": false, "children": [] } ]} /> ___ ### decorateTotals **decorateTotals**(`order`, `totalsFields?`): `Promise`<[`Order`](Order.mdx)\> Calculate and attach the different total fields on the object #### Parameters #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "", "expandable": false, "children": [] } ]} /> **decorateTotals**(`order`, `context?`): `Promise`<[`Order`](Order.mdx)\> Calculate and attach the different total fields on the object #### Parameters #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "", "expandable": false, "children": [] } ]} /> ___ ### decorateTotalsLegacy `Protected` **decorateTotalsLegacy**(`order`, `totalsFields?`): `Promise`<[`Order`](Order.mdx)\> #### Parameters #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "", "expandable": false, "children": [] } ]} /> ___ ### getFulfillmentItems `Protected` **getFulfillmentItems**(`order`, `items`, `transformer`): `Promise`<[`LineItem`](LineItem.mdx)[]\> Retrieves the order line items, given an array of items. #### Parameters `unknown`", "description": "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.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns `Promise`<[`LineItem`](LineItem.mdx)[]\> ", "optional": false, "defaultValue": "", "description": "the line items generated by the transformer.", "expandable": false, "children": [] } ]} /> ___ ### getTotalsRelations `Private` **getTotalsRelations**(`config`): `string`[] #### Parameters ", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns `string`[] ___ ### list **list**(`selector`, `config?`): `Promise`<[`Order`](Order.mdx)[]\> #### Parameters ", "description": "the query object for find", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "config", "type": "[`FindConfig`](../interfaces/FindConfig.mdx)<[`Order`](Order.mdx)\\>", "description": "the config to be used for find", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns `Promise`<[`Order`](Order.mdx)[]\> ", "optional": false, "defaultValue": "", "description": "the result of the find operation", "expandable": false, "children": [] } ]} /> ___ ### listAndCount **listAndCount**(`selector`, `config?`): `Promise`<[[`Order`](Order.mdx)[], `number`]\> #### Parameters ", "description": "the query object for find", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "config", "type": "[`FindConfig`](../interfaces/FindConfig.mdx)<[`Order`](Order.mdx)\\>", "description": "the config to be used for find", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns `Promise`<[[`Order`](Order.mdx)[], `number`]\> ", "optional": false, "defaultValue": "", "description": "the result of the find operation", "expandable": false, "children": [] } ]} /> ___ ### registerReturnReceived **registerReturnReceived**(`orderId`, `receivedReturn`, `customRefundAmount?`): `Promise`<[`Order`](Order.mdx)\> 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 #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "the result of the update operation", "expandable": false, "children": [] } ]} /> ___ ### retrieve **retrieve**(`orderId`, `config?`): `Promise`<[`Order`](Order.mdx)\> Gets an order by id. #### Parameters ", "description": "config of order to retrieve", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "the order document", "expandable": false, "children": [] } ]} /> ___ ### retrieveByCartId **retrieveByCartId**(`cartId`, `config?`): `Promise`<[`Order`](Order.mdx)\> Gets an order by cart id. #### Parameters ", "description": "the config to be used to find order", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "the order document", "expandable": false, "children": [] } ]} /> ___ ### retrieveByCartIdWithTotals **retrieveByCartIdWithTotals**(`cartId`, `options?`): `Promise`<[`Order`](Order.mdx)\> #### Parameters ", "description": "", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "", "expandable": false, "children": [] } ]} /> ___ ### retrieveByExternalId **retrieveByExternalId**(`externalId`, `config?`): `Promise`<[`Order`](Order.mdx)\> Gets an order by id. #### Parameters ", "description": "query config to get order by", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "the order document", "expandable": false, "children": [] } ]} /> ___ ### retrieveLegacy `Protected` **retrieveLegacy**(`orderIdOrSelector`, `config?`): `Promise`<[`Order`](Order.mdx)\> #### Parameters ", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "config", "type": "[`FindConfig`](../interfaces/FindConfig.mdx)<[`Order`](Order.mdx)\\>", "description": "", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "", "expandable": false, "children": [] } ]} /> ___ ### retrieveWithTotals **retrieveWithTotals**(`orderId`, `options?`, `context?`): `Promise`<[`Order`](Order.mdx)\> #### Parameters ", "description": "", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] }, { "name": "context", "type": "[`TotalsContext`](../types/TotalsContext.mdx)", "description": "", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "", "expandable": false, "children": [] } ]} /> ___ ### shouldRetryTransaction\_ `Protected` **shouldRetryTransaction_**(`err`): `boolean` #### Parameters \\| { `code`: `string` }", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns `boolean` ___ ### transformQueryForTotals `Protected` **transformQueryForTotals**(`config`): { `relations`: `undefined` \| `string`[] ; `select`: `undefined` \| keyof [`Order`](Order.mdx)[] ; `totalsToSelect`: `undefined` \| keyof [`Order`](Order.mdx)[] } #### Parameters ", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns `object` ___ ### update **update**(`orderId`, `update`): `Promise`<[`Order`](Order.mdx)\> Updates an order. Metadata updates should use dedicated method, e.g. `setMetadata` etc. The function will throw errors if metadata updates are attempted. #### Parameters #### Returns `Promise`<[`Order`](Order.mdx)\> ", "optional": false, "defaultValue": "", "description": "resolves to the update result.", "expandable": false, "children": [] } ]} /> ___ ### updateBillingAddress `Protected` **updateBillingAddress**(`order`, `address`): `Promise`<`void`\> Updates the order's billing address. #### Parameters #### Returns `Promise`<`void`\> ", "optional": false, "defaultValue": "", "description": "the result of the update operation", "expandable": false, "children": [] } ]} /> ___ ### updateShippingAddress `Protected` **updateShippingAddress**(`order`, `address`): `Promise`<`void`\> Updates the order's shipping address. #### Parameters #### Returns `Promise`<`void`\> ", "optional": false, "defaultValue": "", "description": "the result of the update operation", "expandable": false, "children": [] } ]} /> ___ ### validateFulfillmentLineItem `Protected` **validateFulfillmentLineItem**(`item`, `quantity`): ``null`` \| [`LineItem`](LineItem.mdx) 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 #### Returns ``null`` \| [`LineItem`](LineItem.mdx) ___ ### withTransaction **withTransaction**(`transactionManager?`): [`OrderService`](OrderService.mdx) #### Parameters #### Returns [`OrderService`](OrderService.mdx)