OrderService
internal.internal.OrderService
Properties
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>getTotalsRelations
anyRequiredmanager_
EntityManagerRequiredorderRepository_
Repository<Order> & { findOneWithRelations: Method findOneWithRelations ; findWithRelations: Method findWithRelations }RequiredtransactionManager_
undefined | EntityManagerRequiredEvents
objectRequiredEvents.CANCELED
stringRequiredEvents.COMPLETED
stringRequiredEvents.FULFILLMENT_CANCELED
stringRequiredEvents.FULFILLMENT_CREATED
stringRequiredEvents.GIFT_CARD_CREATED
stringRequiredEvents.ITEMS_RETURNED
stringRequiredEvents.PAYMENT_CAPTURED
stringRequiredEvents.PAYMENT_CAPTURE_FAILED
stringRequiredEvents.PLACED
stringRequiredEvents.REFUND_CREATED
stringRequiredEvents.REFUND_FAILED
stringRequiredEvents.RETURN_ACTION_REQUIRED
stringRequiredEvents.RETURN_REQUESTED
stringRequiredEvents.SHIPMENT_CREATED
stringRequiredEvents.SWAP_CREATED
stringRequiredEvents.UPDATED
stringRequiredAccessors
activeManager_
Protected
get
activeManager_(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredInherited from
TransactionBaseService.activeManager_
Methods
addShippingMethod
addShippingMethod(orderId
, optionId
, data?
, config?
): Promise
<Order
>
Parameters
Returns
Promise
<Order
>
archive
archive(orderId
): Promise
<Order
>
Archives an order. It only alloved, if the order has been fulfilled and payment has been captured.
Parameters
orderId
stringRequiredReturns
Promise
<Order
>
the result of the update operation
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.
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Returns
Promise
<TResult
>
Promise
Promise<TResult>RequiredInherited from
TransactionBaseService.atomicPhase_
cancel
cancel(orderId
): Promise
<Order
>
Cancels an order. Throws if fulfillment process has been initiated. Throws if payment process has been initiated.
Parameters
orderId
stringRequiredReturns
Promise
<Order
>
result of the update operation.
cancelFulfillment
cancelFulfillment(fulfillmentId
): Promise
<Order
>
Cancels a fulfillment (if related to an order)
Parameters
fulfillmentId
stringRequiredReturns
Promise
<Order
>
updated order
capturePayment
capturePayment(orderId
): Promise
<Order
>
Captures payment for an order.
Parameters
orderId
stringRequiredReturns
Promise
<Order
>
result of the update operation.
completeOrder
completeOrder(orderId
): Promise
<Order
>
Parameters
orderId
stringRequiredReturns
Promise
<Order
>
the result of the find operation
createFromCart
createFromCart(cartOrId
): Promise
<Order
>
Creates an order from a cart
Parameters
Returns
Promise
<Order
>
resolves to the creation result.
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
orderId
stringRequiredconfig
objectconfig.location_id
stringconfig.metadata
Record<string, unknown>config.no_notification
booleanReturns
Promise
<Order
>
result of the update operation.
createGiftCardsFromLineItem_
Protected
createGiftCardsFromLineItem_(order
, lineItem
, manager
): Promise
<GiftCard
>[]
Parameters
Returns
Promise
<GiftCard
>[]
createRefund
createRefund(orderId
, refundAmount
, reason
, note?
, config?
): Promise
<Order
>
Refunds a given amount back to the customer.
Parameters
orderId
stringRequiredrefundAmount
numberRequiredreason
stringRequirednote
stringconfig
objectconfig.no_notification
booleanReturns
Promise
<Order
>
the result of the refund operation.
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
orderId
stringRequiredfulfillmentId
stringRequiredtrackingLinks
TrackingLink[]config
objectconfig.metadata
Record<string, unknown>Requiredconfig.no_notification
booleanReturns
Promise
<Order
>
the resulting order following the update.
decorateTotals
decorateTotals(order
, totalsFields?
): Promise
<Order
>
Parameters
totalsFields
string[]Returns
Promise
<Order
>
decorateTotals(order
, context?
): Promise
<Order
>
Parameters
context
TotalsContextReturns
Promise
<Order
>
decorateTotalsLegacy
Protected
decorateTotalsLegacy(order
, totalsFields?
): Promise
<Order
>
Parameters
totalsFields
string[]Returns
Promise
<Order
>
getFulfillmentItems
Protected
getFulfillmentItems(order
, items
, transformer
): Promise
<LineItem
[]>
Retrieves the order line items, given an array of items.
Parameters
Returns
Promise
<LineItem
[]>
the line items generated by the transformer.
list
list(selector
, config?
): Promise
<Order
[]>
Parameters
config
FindConfig<Order>Returns
Promise
<Order
[]>
the result of the find operation
listAndCount
listAndCount(selector
, config?
): Promise
<[Order
[], number
]>
Parameters
config
FindConfig<Order>Returns
Promise
<[Order
[], number
]>
the result of the find operation
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
orderId
stringRequiredcustomRefundAmount
numberReturns
Promise
<Order
>
the result of the update operation
retrieve
retrieve(orderId
, config?
): Promise
<Order
>
Gets an order by id.
Parameters
orderId
stringRequiredconfig
FindConfig<Order>Returns
Promise
<Order
>
the order document
retrieveByCartId
retrieveByCartId(cartId
, config?
): Promise
<Order
>
Gets an order by cart id.
Parameters
cartId
stringRequiredconfig
FindConfig<Order>Returns
Promise
<Order
>
the order document
retrieveByCartIdWithTotals
retrieveByCartIdWithTotals(cartId
, options?
): Promise
<Order
>
Parameters
cartId
stringRequiredoptions
FindConfig<Order>Returns
Promise
<Order
>
retrieveByExternalId
retrieveByExternalId(externalId
, config?
): Promise
<Order
>
Gets an order by id.
Parameters
externalId
stringRequiredconfig
FindConfig<Order>Returns
Promise
<Order
>
the order document
retrieveLegacy
Protected
retrieveLegacy(orderIdOrSelector
, config?
): Promise
<Order
>
Parameters
config
FindConfig<Order>Returns
Promise
<Order
>
retrieveWithTotals
retrieveWithTotals(orderId
, options?
, context?
): Promise
<Order
>
Parameters
Returns
Promise
<Order
>
shouldRetryTransaction_
Protected
shouldRetryTransaction_(err
): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleanInherited from
TransactionBaseService.shouldRetryTransaction_
transformQueryForTotals
Protected
transformQueryForTotals(config
): { relations
: undefined
| string
[] ; select
: undefined
| keyof Order
[] ; totalsToSelect
: undefined
| keyof Order
[] }
Parameters
Returns
object
`object`
objectupdate
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
orderId
stringRequiredReturns
Promise
<Order
>
resolves to the update result.
updateBillingAddress
Protected
updateBillingAddress(order
, address
): Promise
<void
>
Updates the order's billing address.
Parameters
Returns
Promise
<void
>
Promise
Promise<void>RequiredupdateShippingAddress
Protected
updateShippingAddress(order
, address
): Promise
<void
>
Updates the order's shipping address.
Parameters
Returns
Promise
<void
>
Promise
Promise<void>RequiredvalidateFulfillmentLineItem
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
quantity
numberRequiredReturns
null
| LineItem
``null`` \| LineItem
null | LineItemwithTransaction
withTransaction(transactionManager?
): OrderService
Parameters
transactionManager
EntityManager