Skip to main content
Skip to main content

FulfillmentService

Handles Fulfillments

constructor

Parameters

__namedParametersInjectedDependenciesRequired

Properties

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

Accessors

activeManager_

Returns

EntityManagerEntityManagerRequired

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

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

PromisePromise<TResult>Required
the result of the transactional work

cancelFulfillment

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

PromisePromise<Fulfillment>Required
the result of the save operation

createFulfillment

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

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

Default: {}

Returns

PromisePromise<Fulfillment[]>Required
the created fulfillments

createShipment

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

Parameters

fulfillmentIdstringRequired
the fulfillment to ship
trackingLinksobject[]
tracking links for the shipment
configCreateShipmentConfigRequired
potential configuration settings, such as no_notification and metadata

Returns

PromisePromise<Fulfillment>Required
the shipped fulfillment

getFulfillmentItems_

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

Parameters

orderCreateFulfillmentOrderRequired
the order to get line items from
itemsFulFillmentItemType[]Required
the items to get

Returns

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

partitionItems_

Parameters

shippingMethodsShippingMethod[]Required
itemsLineItem[]Required

Returns

FulfillmentItemPartition[]FulfillmentItemPartition[]Required

retrieve

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

PromisePromise<Fulfillment>Required
the fulfillment

shouldRetryTransaction_

Parameters

errRecord<string, unknown> | objectRequired

Returns

booleanboolean

validateFulfillmentLineItem_

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 \| LineItemnull | LineItem
a line item that has the requested fulfillment quantity set.

withTransaction

Parameters

transactionManagerEntityManager

Returns

FulfillmentServiceobjectRequired
Handles Fulfillments
Was this section helpful?