---
displayed_sidebar: servicesSidebar
---

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

# DraftOrderService

Handles draft orders

## Implements

## constructor

### Parameters

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

___

## Properties

<ParameterTypes parameters={[{"name":"__container__","type":"`any`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"cartService_","type":"[CartService](services.CartService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"customShippingOptionService_","type":"[CustomShippingOptionService](services.CustomShippingOptionService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"draftOrderRepository_","type":"Repository&#60;[DraftOrder](../../entities/classes/entities.DraftOrder.mdx)&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"eventBus_","type":"[EventBusService](services.EventBusService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"lineItemService_","type":"[LineItemService](services.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](../../entities/classes/entities.Order.mdx)&#62; & `object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"paymentRepository_","type":"Repository&#60;[Payment](../../entities/classes/entities.Payment.mdx)&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"productVariantService_","type":"[ProductVariantService](services.ProductVariantService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shippingOptionService_","type":"[ShippingOptionService](services.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":[]},{"name":"__configModule__","type":"`Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"__moduleDeclaration__","type":"`Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]} />

___

## Accessors

### activeManager\_

#### Returns

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

___

## Methods

### atomicPhase\_

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.

#### Type Parameters

<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

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

___

### create

Creates a draft order.

#### Parameters

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

#### Returns

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

___

### delete

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

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

___

### list

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](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[DraftOrder](../../entities/classes/entities.DraftOrder.mdx)&#62;","description":"configurable attributes for find","optional":false,"defaultValue":"","expandable":false,"children":[]}]} />

#### Returns

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

___

### listAndCount

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](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[DraftOrder](../../entities/classes/entities.DraftOrder.mdx)&#62;","description":"query config","optional":false,"defaultValue":"","expandable":false,"children":[]}]} />

#### Returns

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

___

### registerCartCompletion

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

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

___

### retrieve

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](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[DraftOrder](../../entities/classes/entities.DraftOrder.mdx)&#62;","description":"query object for findOne","optional":false,"defaultValue":"{}","expandable":false,"children":[]}]} />

#### Returns

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

___

### retrieveByCartId

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](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[DraftOrder](../../entities/classes/entities.DraftOrder.mdx)&#62;","description":"query object for findOne","optional":false,"defaultValue":"{}","expandable":false,"children":[]}]} />

#### Returns

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

___

### shouldRetryTransaction\_

#### Parameters

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

#### Returns

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

___

### update

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

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

___

### withTransaction

#### Parameters

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

#### Returns

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