Skip to main content
Skip to main content

FulfillmentService

admin/discounts.internal.FulfillmentService

Handles Fulfillments

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 get activeManager_(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Inherited from

TransactionBaseService.activeManager_

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.

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

Inherited from

TransactionBaseService.atomicPhase_


cancelFulfillment

cancelFulfillment(fulfillmentOrId): Promise<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

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

order to create fulfillment for
itemsToFulfillFulFillmentItemType[]Required
the items in the order to fulfill
potential custom values to add

Returns

Promise<Fulfillment[]>

PromisePromise<Fulfillment[]>Required
the created fulfillments

createShipment

createShipment(fulfillmentId, trackingLinks?, config?): Promise<Fulfillment>

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
potential configuration settings, such as no_notification and metadata

Returns

Promise<Fulfillment>

PromisePromise<Fulfillment>Required
the shipped fulfillment

getFulfillmentItems_

getFulfillmentItems_(order, items): Promise<(null | LineItem)[]>

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[]

Parameters

shippingMethodsShippingMethod[]Required
itemsLineItem[]Required

Returns

FulfillmentItemPartition[]

FulfillmentItemPartition[]FulfillmentItemPartition[]Required

retrieve

retrieve(fulfillmentId, config?): Promise<Fulfillment>

Retrieves a fulfillment by its id.

Parameters

fulfillmentIdstringRequired
the id of the fulfillment to retrieve
optional values to include with fulfillmentRepository query

Returns

Promise<Fulfillment>

PromisePromise<Fulfillment>Required
the fulfillment

shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

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

Returns

boolean

booleanboolean

Inherited from

TransactionBaseService.shouldRetryTransaction_


validateFulfillmentLineItem_

validateFulfillmentLineItem_(item, quantity): null | 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

Parameters

transactionManagerEntityManager

Returns

FulfillmentService

FulfillmentServiceFulfillmentServiceRequired

Inherited from

TransactionBaseService.withTransaction

Was this section helpful?