OrderService
Hierarchy
TransactionBaseService
↳
OrderService
Constructors
constructor
new OrderService(«destructured»
)
Parameters
Name |
---|
«destructured» |
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
: Method findOneWithRelations ; findWithRelations
: Method findWithRelations }
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
Name | Type |
---|---|
CANCELED | string |
COMPLETED | string |
FULFILLMENT_CANCELED | string |
FULFILLMENT_CREATED | string |
GIFT_CARD_CREATED | string |
ITEMS_RETURNED | string |
PAYMENT_CAPTURED | string |
PAYMENT_CAPTURE_FAILED | string |
PLACED | string |
REFUND_CREATED | string |
REFUND_FAILED | string |
RETURN_ACTION_REQUIRED | string |
RETURN_REQUESTED | string |
SHIPMENT_CREATED | string |
SWAP_CREATED | string |
UPDATED | string |
Defined in
medusa/src/services/order.ts:95
Accessors
activeManager_
Protected
get
activeManager_(): EntityManager
Returns
EntityManager
-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
Name |
---|
orderId |
optionId |
data? |
config |
Returns
Promise
<Order
>
-Promise
:
-Order
:
Defined in
medusa/src/services/order.ts:1030
archive
archive(orderId
): Promise
<Order
>
Archives an order. It only alloved, if the order has been fulfilled and payment has been captured.
Parameters
Name | Description |
---|---|
orderId | string |
Returns
Promise
<Order
>
-Promise
: the result of the update operation
-Order
:
Defined in
medusa/src/services/order.ts:1562
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.
Name |
---|
TResult |
TError |
Parameters
Name | Description |
---|---|
work | (transactionManager : EntityManager ) => Promise <TResult > |
isolationOrErrorHandler? | IsolationLevel | (error : TError ) => Promise <void | TResult > |
maybeErrorHandlerOrDontFail? | (error : TError ) => Promise <void | TResult > |
Returns
Promise
<TResult
>
-Promise
: 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
Name | Description |
---|---|
orderId | string |
Returns
Promise
<Order
>
-Promise
: result of the update operation.
-Order
:
Defined in
medusa/src/services/order.ts:1180
cancelFulfillment
cancelFulfillment(fulfillmentId
): Promise
<Order
>
Cancels a fulfillment (if related to an order)
Parameters
Name | Description |
---|---|
fulfillmentId | string |
Returns
Promise
<Order
>
-Promise
: updated order
-Order
:
Defined in
medusa/src/services/order.ts:1499
capturePayment
capturePayment(orderId
): Promise
<Order
>
Captures payment for an order.
Parameters
Name | Description |
---|---|
orderId | string |
Returns
Promise
<Order
>
-Promise
: result of the update operation.
-Order
:
Defined in
medusa/src/services/order.ts:1269
completeOrder
completeOrder(orderId
): Promise
<Order
>
Parameters
Name | Description |
---|---|
orderId | string |
Returns
Promise
<Order
>
-Promise
: the result of the find operation
-Order
:
Defined in
medusa/src/services/order.ts:577
createFromCart
createFromCart(cartOrId
): Promise
<Order
>
Creates an order from a cart
Parameters
Name |
---|
cartOrId |
Returns
Promise
<Order
>
-Promise
: resolves to the creation result.
-Order
:
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
Name | Description |
---|---|
orderId | string |
itemsToFulfill | FulFillmentItemType [] |
config | object |
config.location_id? | string |
config.metadata? | Record<string , unknown > |
config.no_notification? | boolean |
Returns
Promise
<Order
>
-Promise
: result of the update operation.
-Order
:
Defined in
medusa/src/services/order.ts:1374
createGiftCardsFromLineItem_
Protected
createGiftCardsFromLineItem_(order
, lineItem
, manager
): Promise
<GiftCard
>[]
Parameters
Name |
---|
order |
lineItem |
manager |
Returns
Promise
<GiftCard
>[]
-Promise<GiftCard\>[]
:
-Promise
:
-GiftCard
:
Defined in
medusa/src/services/order.ts:811
createRefund
createRefund(orderId
, refundAmount
, reason
, note?
, config?
): Promise
<Order
>
Refunds a given amount back to the customer.
Parameters
Name | Description |
---|---|
orderId | string |
refundAmount | number |
reason | string |
note? | string |
config | object |
config.no_notification? | boolean |
Returns
Promise
<Order
>
-Promise
: the result of the refund operation.
-Order
:
Defined in
medusa/src/services/order.ts:1588
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
Name | Description |
---|---|
orderId | string |
fulfillmentId | string |
trackingLinks? | TrackingLink [] |
config | object |
config.metadata | Record<string , unknown > |
config.no_notification? | boolean |
Returns
Promise
<Order
>
-Promise
: the resulting order following the update.
-Order
:
Defined in
medusa/src/services/order.ts:864
decorateTotals
decorateTotals(order
, totalsFields?
): Promise
<Order
>
Calculate and attach the different total fields on the object
Parameters
Name |
---|
order |
totalsFields? |
Returns
Promise
<Order
>
-Promise
:
-Order
:
Defined in
medusa/src/services/order.ts:1785
decorateTotals(order
, context?
): Promise
<Order
>
Calculate and attach the different total fields on the object
Parameters
Name |
---|
order |
context? |
Returns
Promise
<Order
>
-Promise
:
-Order
:
Defined in
medusa/src/services/order.ts:1787
decorateTotalsLegacy
Protected
decorateTotalsLegacy(order
, totalsFields?
): Promise
<Order
>
Parameters
Name | Default value |
---|---|
order | Order |
totalsFields | string [] |
Returns
Promise
<Order
>
-Promise
:
-Order
:
Defined in
medusa/src/services/order.ts:1656
getFulfillmentItems
Protected
getFulfillmentItems(order
, items
, transformer
): Promise
<LineItem
[]>
Retrieves the order line items, given an array of items.
Parameters
Name | Description |
---|---|
order | Order |
items | FulFillmentItemType [] |
transformer | (item : undefined | LineItem , quantity : number ) => unknown |
Returns
Promise
<LineItem
[]>
-Promise
: the line items generated by the transformer.
-LineItem[]
:
-LineItem
:
Defined in
medusa/src/services/order.ts:1541
getTotalsRelations
Private
getTotalsRelations(config
): string
[]
Parameters
Name |
---|
config |
Returns
string
[]
-string[]
:
-string
: (optional)
Defined in
medusa/src/services/order.ts:2061
list
list(selector
, config?
): Promise
<Order
[]>
Parameters
Name | Description |
---|---|
selector | Selector <Order > |
config | FindConfig <Order > |
Returns
Promise
<Order
[]>
-Promise
: the result of the find operation
-Order[]
:
-Order
:
Defined in
medusa/src/services/order.ts:189
listAndCount
listAndCount(selector
, config?
): Promise
<[Order
[], number
]>
Parameters
Name | Description |
---|---|
selector | QuerySelector <Order > |
config | FindConfig <Order > |
Returns
Promise
<[Order
[], number
]>
-Promise
: the result of the find operation
-Order[]
:
-number
: (optional)
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 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
Name | Description |
---|---|
orderId | string |
receivedReturn | Return |
customRefundAmount? | number |
Returns
Promise
<Order
>
-Promise
: the result of the update operation
-Order
:
Defined in
medusa/src/services/order.ts:1986
retrieve
retrieve(orderId
, config?
): Promise
<Order
>
Gets an order by id.
Parameters
Name | Description |
---|---|
orderId | string |
config | FindConfig <Order > |
Returns
Promise
<Order
>
-Promise
: the order document
-Order
:
Defined in
medusa/src/services/order.ts:388
retrieveByCartId
retrieveByCartId(cartId
, config?
): Promise
<Order
>
Gets an order by cart id.
Parameters
Name | Description |
---|---|
cartId | string |
config | FindConfig <Order > |
Returns
Promise
<Order
>
-Promise
: the order document
-Order
:
Defined in
medusa/src/services/order.ts:484
retrieveByCartIdWithTotals
retrieveByCartIdWithTotals(cartId
, options?
): Promise
<Order
>
Parameters
Name |
---|
cartId |
options |
Returns
Promise
<Order
>
-Promise
:
-Order
:
Defined in
medusa/src/services/order.ts:518
retrieveByExternalId
retrieveByExternalId(externalId
, config?
): Promise
<Order
>
Gets an order by id.
Parameters
Name | Description |
---|---|
externalId | string |
config | FindConfig <Order > |
Returns
Promise
<Order
>
-Promise
: the order document
-Order
:
Defined in
medusa/src/services/order.ts:533
retrieveLegacy
Protected
retrieveLegacy(orderIdOrSelector
, config?
): Promise
<Order
>
Parameters
Name |
---|
orderIdOrSelector |
config |
Returns
Promise
<Order
>
-Promise
:
-Order
:
Defined in
medusa/src/services/order.ts:428
retrieveWithTotals
retrieveWithTotals(orderId
, options?
, context?
): Promise
<Order
>
Parameters
Name |
---|
orderId |
options |
context |
Returns
Promise
<Order
>
-Promise
:
-Order
:
Defined in
medusa/src/services/order.ts:467
shouldRetryTransaction_
Protected
shouldRetryTransaction_(err
): boolean
Parameters
Name |
---|
err |
Returns
boolean
-boolean
: (optional)
Inherited from
TransactionBaseService.shouldRetryTransaction_
Defined in
medusa/src/interfaces/transaction-base-service.ts:37
transformQueryForTotals
Protected
transformQueryForTotals(config
): { relations
: undefined
| string
[] ; select
: undefined
| keyof Order
[] ; totalsToSelect
: undefined
| keyof Order
[] }
Parameters
Name |
---|
config |
Returns
object
-object
: (optional)
Name | Type |
---|---|
relations | undefined | string [] |
select | undefined | keyof Order [] |
totalsToSelect | undefined | 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
Name | Description |
---|---|
orderId | string |
update | UpdateOrderInput |
Returns
Promise
<Order
>
-Promise
: resolves to the update result.
-Order
:
Defined in
medusa/src/services/order.ts:1091
updateBillingAddress
Protected
updateBillingAddress(order
, address
): Promise
<void
>
Updates the order's billing address.
Parameters
Name | Description |
---|---|
order | Order |
address | Address |
Returns
Promise
<void
>
-Promise
: the result of the update operation
Defined in
medusa/src/services/order.ts:952
updateShippingAddress
Protected
updateShippingAddress(order
, address
): Promise
<void
>
Updates the order's shipping address.
Parameters
Name | Description |
---|---|
order | Order |
address | Address |
Returns
Promise
<void
>
-Promise
: the result of the update operation
Defined in
medusa/src/services/order.ts:999
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
Name | Description |
---|---|
item | LineItem |
quantity | number |
Returns
null
| LineItem
-`null
| LineItem`: (optional) a line item that has the requested fulfillment quantity
set.
Defined in
medusa/src/services/order.ts:1341
withTransaction
withTransaction(transactionManager?
): OrderService
Parameters
Name |
---|
transactionManager? |
Returns
-OrderService
:
Inherited from
TransactionBaseService.withTransaction