Skip to main content

Class: FulfillmentService

Handles Fulfillments

Hierarchy

  • "medusa-interfaces"

    FulfillmentService

Constructors

constructor

new FulfillmentService(__namedParameters)

Parameters

NameType
__namedParametersObject

Overrides

BaseService.constructor

Defined in

services/fulfillment.js:9

Methods

cancelFulfillment

cancelFulfillment(fulfillmentOrId): Promise<any>

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

NameTypeDescription
fulfillmentOrIdanythe fulfillment object or id.

Returns

Promise<any>

the result of the save operation

Defined in

services/fulfillment.js:223


createFulfillment

createFulfillment(order, itemsToFulfill, custom?): 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

NameTypeDescription
orderOrderorder to create fulfillment for
itemsToFulfill{ item_id: string ; quantity: number }[]-
customanypotential custom values to add

Returns

Fulfillment[]

the created fulfillments

Defined in

services/fulfillment.js:171


createShipment

createShipment(fulfillmentId, trackingLinks, config?): Fulfillment

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

Parameters

NameTypeDescription
fulfillmentIdOrderthe fulfillment to ship
trackingLinksTrackingLink[]tracking links for the shipment
configanypotential configuration settings, such as no_notification and metadata

Returns

Fulfillment

the shipped fulfillment

Defined in

services/fulfillment.js:270


getFulfillmentItems_

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

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

Parameters

NameTypeDescription
orderOrderthe order to get line items from
itemsObjectthe items to get
items.item_idstring-
items.quantitynumber-
transformerFunctiona function to apply to each of the items retrieved from the order, should return a line item. If the transformer returns an undefined value the line item will be filtered from the returned array.

Returns

Promise<LineItem[]>

the line items generated by the transformer.

Defined in

services/fulfillment.js:94


partitionItems_

partitionItems_(shippingMethods, items): { shipping_method: any = method }[]

Parameters

NameType
shippingMethodsany
itemsany

Returns

{ shipping_method: any = method }[]

Defined in

services/fulfillment.js:62


retrieve

retrieve(id, config?): Fulfillment

Retrieves a fulfillment by its id.

Parameters

NameTypeDescription
idstringthe id of the fulfillment to retrieve
configanyoptional values to include with fulfillmentRepository query

Returns

Fulfillment

the fulfillment

Defined in

services/fulfillment.js:142


validateFulfillmentLineItem_

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

NameTypeDescription
itemLineItemthe line item to check has sufficient fulfillable quantity.
quantitynumberthe quantity that is requested to be fulfilled.

Returns

LineItem

a line item that has the requested fulfillment quantity set.

Defined in

services/fulfillment.js:116


withTransaction

withTransaction(transactionManager): FulfillmentService

Parameters

NameType
transactionManagerany

Returns

FulfillmentService

Defined in

services/fulfillment.js:42