---
displayed_sidebar: servicesSidebar
---

import ParameterTypes from "@site/src/components/ParameterTypes"

# DraftOrderService

Handles draft orders

#### Implements

## Constructors

### constructor

`**new DraftOrderService**(«destructured»)`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "__namedParameters",
    "type": "[InjectedDependencies](../types/InjectedDependencies-9.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

## Properties

<ParameterTypes parameters={[
  {
    "name": "__configModule__",
    "type": "`Record<string, unknown>`",
    "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": "cartService_",
    "type": "[CartService](CartService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "customShippingOptionService_",
    "type": "[CustomShippingOptionService](CustomShippingOptionService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "draftOrderRepository_",
    "type": "Repository&#60;[DraftOrder](DraftOrder.mdx)&#62;",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "eventBus_",
    "type": "[EventBusService](EventBusService.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": "orderRepository_",
    "type": "Repository&#60;[Order](Order.mdx)&#62; & ``{ findOneWithRelations: Method findOneWithRelations ; findWithRelations: Method findWithRelations  }``",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "paymentRepository_",
    "type": "Repository&#60;[Payment](Payment.mdx)&#62;",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "productVariantService_",
    "type": "[ProductVariantService](ProductVariantService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "shippingOptionService_",
    "type": "[ShippingOptionService](ShippingOptionService.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.CREATED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"draft_order.created\"",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events.UPDATED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"draft_order.updated\"",
    "expandable": false,
    "children": []
  }
]} />

## Accessors

### activeManager\_

`Protected get**activeManager_**(): EntityManager`

#### Returns

EntityManager

<ParameterTypes parameters={[
  {
    "name": "EntityManager",
    "type": "EntityManager",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

## 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.

<ParameterTypes parameters={[
  {
    "name": "TResult",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "TError",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "work",
    "type": "(`transactionManager`: EntityManager) => Promise&#60;TResult&#62;",
    "description": "the transactional work to be done",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "isolationOrErrorHandler",
    "type": "`IsolationLevel` \\| (`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
    "description": "the isolation level to be used for the work.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "maybeErrorHandlerOrDontFail",
    "type": "(`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
    "description": "Potential error handler",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;TResult&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;TResult&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the transactional work",
    "expandable": false,
    "children": []
  }
]} />

___

### create

`**create**(data): Promise&#60;[DraftOrder](DraftOrder.mdx)&#62;`

Creates a draft order.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "data",
    "type": "[DraftOrderCreateProps](../types/DraftOrderCreateProps.mdx)",
    "description": "data to create draft order from",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[DraftOrder](DraftOrder.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[DraftOrder](DraftOrder.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the created draft order",
    "expandable": false,
    "children": []
  }
]} />

___

### delete

`**delete**(draftOrderId): Promise&#60;undefined \| [DraftOrder](DraftOrder.mdx)&#62;`

Deletes draft order idempotently.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "draftOrderId",
    "type": "`string`",
    "description": "id of draft order to delete",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;undefined \| [DraftOrder](DraftOrder.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;undefined \\| [DraftOrder](DraftOrder.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "empty promise",
    "expandable": false,
    "children": []
  }
]} />

___

### list

`**list**(selector, config?): Promise&#60;[DraftOrder](DraftOrder.mdx)[]&#62;`

Lists draft orders

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "selector",
    "type": "`any`",
    "description": "query object for find",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[DraftOrder](DraftOrder.mdx)&#62;",
    "description": "configurable attributes for find",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[DraftOrder](DraftOrder.mdx)[]&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[DraftOrder](DraftOrder.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "list of draft orders",
    "expandable": false,
    "children": []
  }
]} />

___

### listAndCount

`**listAndCount**(selector, config?): Promise&#60;[[DraftOrder](DraftOrder.mdx)[], number]&#62;`

Lists draft orders alongside the count

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "selector",
    "type": "`any`",
    "description": "query selector to filter draft orders",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[DraftOrder](DraftOrder.mdx)&#62;",
    "description": "query config",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[[DraftOrder](DraftOrder.mdx)[], number]&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[[DraftOrder](DraftOrder.mdx)[], number]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "draft orders",
    "expandable": false,
    "children": []
  }
]} />

___

### registerCartCompletion

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

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

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "draftOrderId",
    "type": "`string`",
    "description": "id of draft order to complete",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "orderId",
    "type": "`string`",
    "description": "id of order completed from draft order cart",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;UpdateResult&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;UpdateResult&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the created order",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieve

`**retrieve**(draftOrderId, config?): Promise&#60;[DraftOrder](DraftOrder.mdx)&#62;`

Retrieves a draft order with the given id.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "draftOrderId",
    "type": "`string`",
    "description": "id of the draft order to retrieve",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[DraftOrder](DraftOrder.mdx)&#62;",
    "description": "query object for findOne",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[DraftOrder](DraftOrder.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[DraftOrder](DraftOrder.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the draft order",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieveByCartId

`**retrieveByCartId**(cartId, config?): Promise&#60;[DraftOrder](DraftOrder.mdx)&#62;`

Retrieves a draft order based on its associated cart id

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "cartId",
    "type": "`string`",
    "description": "cart id that the draft orders's cart has",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../interfaces/FindConfig.mdx)&#60;[DraftOrder](DraftOrder.mdx)&#62;",
    "description": "query object for findOne",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[DraftOrder](DraftOrder.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[DraftOrder](DraftOrder.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the draft order",
    "expandable": false,
    "children": []
  }
]} />

___

### shouldRetryTransaction\_

`Protected **shouldRetryTransaction_**(err): boolean`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "err",
    "type": "`Record<string, unknown>` \\| ``{ code: string  }``",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`boolean`

<ParameterTypes parameters={[
  {
    "name": "boolean",
    "type": "`boolean`",
    "optional": true,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### update

`**update**(id, data): Promise&#60;[DraftOrder](DraftOrder.mdx)&#62;`

Updates a draft order with the given data

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "id",
    "type": "`string`",
    "description": "id of the draft order",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "data",
    "type": "`object`",
    "description": "values to update the order with",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "data.no_notification_order",
    "type": "`boolean`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

Promise&#60;[DraftOrder](DraftOrder.mdx)&#62;

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[DraftOrder](DraftOrder.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the updated draft order",
    "expandable": false,
    "children": []
  }
]} />

___

### withTransaction

`**withTransaction**(transactionManager?): [DraftOrderService](DraftOrderService.mdx)`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "transactionManager",
    "type": "EntityManager",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

[DraftOrderService](DraftOrderService.mdx)

<ParameterTypes parameters={[
  {
    "name": "DraftOrderService",
    "type": "[DraftOrderService](DraftOrderService.mdx)",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />
