OrderService
Constructors
constructor
new OrderService(«destructured»
)
Parameters
Properties
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>manager_
EntityManagerRequiredorderRepository_
Repository<Order> & { findOneWithRelations: Method findOneWithRelations ; findWithRelations: Method findWithRelations }RequiredtransactionManager_
undefined | EntityManagerRequiredEvents
objectRequiredEvents.CANCELED
stringRequiredDefault: "order.canceled"
Events.COMPLETED
stringRequiredDefault: "order.completed"
Events.FULFILLMENT_CANCELED
stringRequiredDefault: "order.fulfillment_canceled"
Events.FULFILLMENT_CREATED
stringRequiredDefault: "order.fulfillment_created"
Events.GIFT_CARD_CREATED
stringRequiredDefault: "order.gift_card_created"
Events.ITEMS_RETURNED
stringRequiredDefault: "order.items_returned"
Events.PAYMENT_CAPTURED
stringRequiredDefault: "order.payment_captured"
Events.PAYMENT_CAPTURE_FAILED
stringRequiredDefault: "order.payment_capture_failed"
Events.PLACED
stringRequiredDefault: "order.placed"
Events.REFUND_CREATED
stringRequiredDefault: "order.refund_created"
Events.REFUND_FAILED
stringRequiredDefault: "order.refund_failed"
Events.RETURN_ACTION_REQUIRED
stringRequiredDefault: "order.return_action_required"
Events.RETURN_REQUESTED
stringRequiredDefault: "order.return_requested"
Events.SHIPMENT_CREATED
stringRequiredDefault: "order.shipment_created"
Events.SWAP_CREATED
stringRequiredDefault: "order.swap_created"
Events.UPDATED
stringRequiredDefault: "order.updated"
Accessors
activeManager_
Protected
get
activeManager_(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredMethods
addShippingMethod
addShippingMethod(orderId
, optionId
, data?
, config?
): Promise
<Order
>
Parameters
orderId
stringRequiredoptionId
stringRequireddata
Record<string, unknown>Default: {}
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
>
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>Requiredcancel
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
>
cancelFulfillment
cancelFulfillment(fulfillmentId
): Promise
<Order
>
Cancels a fulfillment (if related to an order)
Parameters
fulfillmentId
stringRequiredReturns
Promise
<Order
>
capturePayment
capturePayment(orderId
): Promise
<Order
>
Captures payment for an order.
Parameters
orderId
stringRequiredReturns
Promise
<Order
>
completeOrder
completeOrder(orderId
): Promise
<Order
>
Parameters
orderId
stringRequiredReturns
Promise
<Order
>
createFromCart
createFromCart(cartOrId
): Promise
<Order
>
Creates an order from a cart
Parameters
Returns
Promise
<Order
>
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
objectRequiredDefault: {}
config.location_id
stringconfig.metadata
Record<string, unknown>config.no_notification
booleanReturns
Promise
<Order
>
createGiftCardsFromLineItem_
Protected
createGiftCardsFromLineItem_(order
, lineItem
, manager
): Promise
<GiftCard
>[]
Parameters
manager
EntityManagerRequiredReturns
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
objectRequiredconfig.no_notification
booleanReturns
Promise
<Order
>
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
objectRequiredconfig.metadata
Record<string, unknown>Requiredconfig.no_notification
booleanReturns
Promise
<Order
>
decorateTotals
decorateTotals(order
, totalsFields?
): Promise
<Order
>
Calculate and attach the different total fields on the object
Parameters
totalsFields
string[]Returns
Promise
<Order
>
decorateTotals(order
, context?
): Promise
<Order
>
Calculate and attach the different total fields on the object
Parameters
context
TotalsContextReturns
Promise
<Order
>
decorateTotalsLegacy
Protected
decorateTotalsLegacy(order
, totalsFields?
): Promise
<Order
>
Parameters
totalsFields
string[]RequiredDefault: []
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
[]>
getTotalsRelations
Private
getTotalsRelations(config
): string
[]
Parameters
Returns
string
[]
string[]
string[]Requiredlist
list(selector
, config?
): Promise
<Order
[]>
Parameters
Returns
Promise
<Order
[]>
listAndCount
listAndCount(selector
, config?
): Promise
<[Order
[], number
]>
Parameters
Returns
Promise
<[Order
[], number
]>
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
>
retrieve
retrieve(orderId
, config?
): Promise
<Order
>
Gets an order by id.
Parameters
orderId
stringRequiredDefault: {}
Returns
Promise
<Order
>
retrieveByCartId
retrieveByCartId(cartId
, config?
): Promise
<Order
>
Gets an order by cart id.
Parameters
cartId
stringRequiredDefault: {}
Returns
Promise
<Order
>
retrieveByCartIdWithTotals
retrieveByCartIdWithTotals(cartId
, options?
): Promise
<Order
>
Parameters
cartId
stringRequiredDefault: {}
Returns
Promise
<Order
>
retrieveByExternalId
retrieveByExternalId(externalId
, config?
): Promise
<Order
>
Gets an order by id.
Parameters
externalId
stringRequiredDefault: {}
Returns
Promise
<Order
>
retrieveLegacy
Protected
retrieveLegacy(orderIdOrSelector
, config?
): Promise
<Order
>
Parameters
Default: {}
Returns
Promise
<Order
>
retrieveWithTotals
retrieveWithTotals(orderId
, options?
, context?
): Promise
<Order
>
Parameters
orderId
stringRequiredDefault: {}
Default: {}
Returns
Promise
<Order
>
shouldRetryTransaction_
Protected
shouldRetryTransaction_(err
): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleantransformQueryForTotals
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
>
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