Skip to main content
Skip to main content

DraftOrderService

Handles draft orders

Implements

Constructors

constructor

**new DraftOrderService**(«destructured»)

Parameters

__namedParametersInjectedDependenciesRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
cartService_CartServiceRequired
customShippingOptionService_CustomShippingOptionServiceRequired
draftOrderRepository_Repository<DraftOrder>Required
eventBus_EventBusServiceRequired
lineItemService_LineItemServiceRequired
manager_EntityManagerRequired
orderRepository_Repository<Order> & { findOneWithRelations: Method findOneWithRelations ; findWithRelations: Method findWithRelations }Required
paymentRepository_Repository<Payment>Required
productVariantService_ProductVariantServiceRequired
shippingOptionService_ShippingOptionServiceRequired
transactionManager_undefined | EntityManagerRequired
EventsobjectRequired
Events.CREATEDstringRequired

Default: "draft_order.created"

Events.UPDATEDstringRequired

Default: "draft_order.updated"

Accessors

activeManager_

Protected get**activeManager_**(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Methods

atomicPhase_

Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;

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.

TResultobjectRequired
TErrorobjectRequired

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

Promise<TResult>

PromisePromise<TResult>Required
the result of the transactional work

create

**create**(data): Promise&#60;[DraftOrder](/references/services/classes/DraftOrder)&#62;

Creates a draft order.

Parameters

data to create draft order from

Returns

Promise<DraftOrder>

PromisePromise<DraftOrder>Required
the created draft order

delete

**delete**(draftOrderId): Promise&#60;undefined \| [DraftOrder](/references/services/classes/DraftOrder)&#62;

Deletes draft order idempotently.

Parameters

draftOrderIdstringRequired
id of draft order to delete

Returns

Promise<undefined | DraftOrder>

PromisePromise<undefined | DraftOrder>Required
empty promise

list

**list**(selector, config?): Promise&#60;[DraftOrder](/references/services/classes/DraftOrder)[]&#62;

Lists draft orders

Parameters

selectoranyRequired
query object for find
configFindConfig<DraftOrder>Required
configurable attributes for find

Returns

Promise<DraftOrder[]>

PromisePromise<DraftOrder[]>Required
list of draft orders

listAndCount

**listAndCount**(selector, config?): Promise&#60;[[DraftOrder](/references/services/classes/DraftOrder)[], number]&#62;

Lists draft orders alongside the count

Parameters

selectoranyRequired
query selector to filter draft orders
configFindConfig<DraftOrder>Required
query config

Returns

Promise<[DraftOrder[], number]>

PromisePromise<[DraftOrder[], number]>Required
draft orders

registerCartCompletion

**registerCartCompletion**(draftOrderId, orderId): Promise&#60;UpdateResult&#62;

Registers a draft order as completed, when an order has been completed.

Parameters

draftOrderIdstringRequired
id of draft order to complete
orderIdstringRequired
id of order completed from draft order cart

Returns

Promise<UpdateResult>

PromisePromise<UpdateResult>Required
the created order

retrieve

**retrieve**(draftOrderId, config?): Promise&#60;[DraftOrder](/references/services/classes/DraftOrder)&#62;

Retrieves a draft order with the given id.

Parameters

draftOrderIdstringRequired
id of the draft order to retrieve
configFindConfig<DraftOrder>Required
query object for findOne

Default: {}

Returns

Promise<DraftOrder>

PromisePromise<DraftOrder>Required
the draft order

retrieveByCartId

**retrieveByCartId**(cartId, config?): Promise&#60;[DraftOrder](/references/services/classes/DraftOrder)&#62;

Retrieves a draft order based on its associated cart id

Parameters

cartIdstringRequired
cart id that the draft orders's cart has
configFindConfig<DraftOrder>Required
query object for findOne

Default: {}

Returns

Promise<DraftOrder>

PromisePromise<DraftOrder>Required
the draft order

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters

errRecord<string, unknown> | { code: string }Required

Returns

boolean

booleanboolean

update

**update**(id, data): Promise&#60;[DraftOrder](/references/services/classes/DraftOrder)&#62;

Updates a draft order with the given data

Parameters

idstringRequired
id of the draft order
dataobjectRequired
values to update the order with
data.no_notification_orderbooleanRequired

Returns

Promise<DraftOrder>

PromisePromise<DraftOrder>Required
the updated draft order

withTransaction

**withTransaction**(transactionManager?): [DraftOrderService](/references/services/classes/DraftOrderService)

Parameters

transactionManagerEntityManager

Returns

DraftOrderService

DraftOrderServiceDraftOrderServiceRequired
Was this section helpful?