---
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`<[`DraftOrder`](DraftOrder.mdx)\\>",
    "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`<[`Order`](Order.mdx)\\> & { `findOneWithRelations`: Method findOneWithRelations ; `findWithRelations`: Method findWithRelations  }",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "paymentRepository_",
    "type": "`Repository`<[`Payment`](Payment.mdx)\\>",
    "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_**<`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.

<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`<`TResult`\\>",
    "description": "the transactional work to be done",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "isolationOrErrorHandler",
    "type": "`IsolationLevel` \\| (`error`: `TError`) => `Promise`<`void` \\| `TResult`\\>",
    "description": "the isolation level to be used for the work.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "maybeErrorHandlerOrDontFail",
    "type": "(`error`: `TError`) => `Promise`<`void` \\| `TResult`\\>",
    "description": "Potential error handler",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`Promise`<`TResult`\>

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

___

### create

**create**(`data`): `Promise`<[`DraftOrder`](DraftOrder.mdx)\>

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`<[`DraftOrder`](DraftOrder.mdx)\>

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

___

### delete

**delete**(`draftOrderId`): `Promise`<`undefined` \| [`DraftOrder`](DraftOrder.mdx)\>

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`<`undefined` \| [`DraftOrder`](DraftOrder.mdx)\>

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

___

### list

**list**(`selector`, `config?`): `Promise`<[`DraftOrder`](DraftOrder.mdx)[]\>

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)<[`DraftOrder`](DraftOrder.mdx)\\>",
    "description": "configurable attributes for find",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`Promise`<[`DraftOrder`](DraftOrder.mdx)[]\>

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

___

### listAndCount

**listAndCount**(`selector`, `config?`): `Promise`<[[`DraftOrder`](DraftOrder.mdx)[], `number`]\>

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)<[`DraftOrder`](DraftOrder.mdx)\\>",
    "description": "query config",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`Promise`<[[`DraftOrder`](DraftOrder.mdx)[], `number`]\>

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

___

### registerCartCompletion

**registerCartCompletion**(`draftOrderId`, `orderId`): `Promise`<`UpdateResult`\>

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`<`UpdateResult`\>

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "`Promise`<`UpdateResult`\\>",
    "optional": false,
    "defaultValue": "",
    "description": "the created order",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieve

**retrieve**(`draftOrderId`, `config?`): `Promise`<[`DraftOrder`](DraftOrder.mdx)\>

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)<[`DraftOrder`](DraftOrder.mdx)\\>",
    "description": "query object for findOne",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`Promise`<[`DraftOrder`](DraftOrder.mdx)\>

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

___

### retrieveByCartId

**retrieveByCartId**(`cartId`, `config?`): `Promise`<[`DraftOrder`](DraftOrder.mdx)\>

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)<[`DraftOrder`](DraftOrder.mdx)\\>",
    "description": "query object for findOne",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

`Promise`<[`DraftOrder`](DraftOrder.mdx)\>

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "`Promise`<[`DraftOrder`](DraftOrder.mdx)\\>",
    "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`<[`DraftOrder`](DraftOrder.mdx)\>

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`<[`DraftOrder`](DraftOrder.mdx)\>

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "`Promise`<[`DraftOrder`](DraftOrder.mdx)\\>",
    "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": []
  }
]} />
