Skip to main content
Skip to main content

FulfillmentService

Handles Fulfillments

Constructors

constructor

**new FulfillmentService**(«destructured»)

Parameters
__namedParametersInjectedDependenciesRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
fulfillmentProviderService_FulfillmentProviderServiceRequired
fulfillmentRepository_Repository<Fulfillment>Required
lineItemRepository_Repository<LineItem> & { findByReturn: Method findByReturn }Required
lineItemService_LineItemServiceRequired
manager_EntityManagerRequired
productVariantInventoryService_ProductVariantInventoryServiceRequired
shippingProfileService_ShippingProfileServiceRequired
totalsService_TotalsServiceRequired
trackingLinkRepository_Repository<TrackingLink>Required
transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Protected activeManager_: [object Object]

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.

Type Parameters
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

cancelFulfillment

**cancelFulfillment**(fulfillmentOrId): Promise&#60;[Fulfillment](/references/services/classes/Fulfillment)&#62;

Cancels a fulfillment with the fulfillment provider. Will decrement the fulfillment_quantity on the line items associated with the fulfillment. Throws if the fulfillment has already been shipped.

Parameters
fulfillmentOrIdstring | FulfillmentRequired
the fulfillment object or id.
Returns

Promise<Fulfillment>

PromisePromise<Fulfillment>Required
the result of the save operation

createFulfillment

**createFulfillment**(order, itemsToFulfill, custom?): Promise&#60;[Fulfillment](/references/services/classes/Fulfillment)[]&#62;

Creates an order fulfillment If items needs to be fulfilled by different provider, we make sure to partition those items, and create fulfillment for those partitions.

Parameters
order to create fulfillment for
itemsToFulfillFulFillmentItemType[]Required
the items in the order to fulfill
customPartial<Fulfillment>Required
potential custom values to add

Default: {}

Returns

Promise<Fulfillment[]>

PromisePromise<Fulfillment[]>Required
the created fulfillments

createShipment

**createShipment**(fulfillmentId, trackingLinks?, config?): Promise&#60;[Fulfillment](/references/services/classes/Fulfillment)&#62;

Creates a shipment by marking a fulfillment as shipped. Adds tracking links and potentially more metadata.

Parameters
fulfillmentIdstringRequired
the fulfillment to ship
trackingLinks{ tracking_number: string }[]
tracking links for the shipment
configCreateShipmentConfigRequired
potential configuration settings, such as no_notification and metadata
Returns

Promise<Fulfillment>

PromisePromise<Fulfillment>Required
the shipped fulfillment

getFulfillmentItems_

**getFulfillmentItems_**(order, items): Promise&#60;(null \| [LineItem](/references/services/classes/LineItem))[]&#62;

Retrieves the order line items, given an array of items.

Parameters
the order to get line items from
itemsFulFillmentItemType[]Required
the items to get
Returns

Promise<(null | LineItem)[]>

PromisePromise<(null | LineItem)[]>Required
the line items generated by the transformer.

partitionItems_

**partitionItems_**(shippingMethods, items): [FulfillmentItemPartition](/references/services/types/FulfillmentItemPartition)[]

Parameters
shippingMethodsShippingMethod[]Required
itemsLineItem[]Required
Returns

FulfillmentItemPartition[]

FulfillmentItemPartition[]FulfillmentItemPartition[]Required

retrieve

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

Retrieves a fulfillment by its id.

Parameters
fulfillmentIdstringRequired
the id of the fulfillment to retrieve
configFindConfig<Fulfillment>Required
optional values to include with fulfillmentRepository query

Default: {}

Returns

Promise<Fulfillment>

PromisePromise<Fulfillment>Required
the fulfillment

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

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

boolean

booleanboolean

validateFulfillmentLineItem_

**validateFulfillmentLineItem_**(item, quantity): null \| [LineItem](/references/services/classes/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
itemundefined | LineItemRequired
the line item to check has sufficient fulfillable quantity.
quantitynumberRequired
the quantity that is requested to be fulfilled.
Returns

null | LineItem

null \| LineItemnull | LineItem
a line item that has the requested fulfillment quantity set.

withTransaction

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

Parameters
transactionManagerEntityManager
Returns

FulfillmentService

FulfillmentServiceFulfillmentServiceRequired
Was this section helpful?