FulfillmentService
Handles Fulfillments
Constructors
constructor
**new FulfillmentService**(«destructured»)
Parameters
Properties
__configModule__Record<string, unknown>__container__anyRequired__moduleDeclaration__Record<string, unknown>manager_EntityManagerRequiredtransactionManager_undefined | EntityManagerRequiredAccessors
activeManager_
Protected get**activeManager_**(): EntityManager
Returns
EntityManager
EntityManagerEntityManagerRequiredMethods
atomicPhase_
Protected **atomicPhase_**<TypeParameter TResult, TypeParameter 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.
TResultobjectRequiredTErrorobjectRequiredParameters
work(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>Returns
Promise<TResult>
PromisePromise<TResult>RequiredcancelFulfillment
**cancelFulfillment**(fulfillmentOrId): Promise<[Fulfillment](/references/services/classes/Fulfillment)>
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
Returns
Promise<Fulfillment>
createFulfillment
**createFulfillment**(order, itemsToFulfill, custom?): Promise<[Fulfillment](/references/services/classes/Fulfillment)[]>
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
Default: {}
Returns
Promise<Fulfillment[]>
createShipment
**createShipment**(fulfillmentId, trackingLinks?, config?): Promise<[Fulfillment](/references/services/classes/Fulfillment)>
Creates a shipment by marking a fulfillment as shipped. Adds tracking links and potentially more metadata.
Parameters
fulfillmentIdstringRequiredtrackingLinks{ tracking_number: string }[]Returns
Promise<Fulfillment>
getFulfillmentItems_
**getFulfillmentItems_**(order, items): Promise<(null \| [LineItem](/references/services/classes/LineItem))[]>
Retrieves the order line items, given an array of items.
Parameters
Returns
Promise<(null | LineItem)[]>
partitionItems_
**partitionItems_**(shippingMethods, items): [FulfillmentItemPartition](/references/services/types/FulfillmentItemPartition)[]
Parameters
Returns
retrieve
**retrieve**(fulfillmentId, config?): Promise<[Fulfillment](/references/services/classes/Fulfillment)>
Retrieves a fulfillment by its id.
Parameters
fulfillmentIdstringRequiredDefault: {}
Returns
Promise<Fulfillment>
shouldRetryTransaction_
Protected **shouldRetryTransaction_**(err): boolean
Parameters
errRecord<string, unknown> | { code: string }RequiredReturns
boolean
booleanbooleanvalidateFulfillmentLineItem_
**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
quantitynumberRequiredReturns
null | LineItem
`null` \| LineItemnull | LineItemwithTransaction
**withTransaction**(transactionManager?): [FulfillmentService](/references/services/classes/FulfillmentService)
Parameters
transactionManagerEntityManager