Files
medusa-store/docs/content/references/services/classes/FulfillmentService.md
2022-06-01 18:33:08 +02:00

5.6 KiB

Class: FulfillmentService

Handles Fulfillments

Hierarchy

  • "medusa-interfaces"

    FulfillmentService

Constructors

constructor

new FulfillmentService(__namedParameters)

Parameters

Name Type
__namedParameters Object

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

Name Type Description
fulfillmentOrId any the 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

Name Type Description
order Order order to create fulfillment for
itemsToFulfill { item_id: string ; quantity: number }[] -
custom any potential 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

Name Type Description
fulfillmentId Order the fulfillment to ship
trackingLinks TrackingLink[] tracking links for the shipment
config any potential 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

Name Type Description
order Order the order to get line items from
items Object the items to get
items.item_id string -
items.quantity number -
transformer Function a 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

Name Type
shippingMethods any
items any

Returns

{ shipping_method: any = method }[]

Defined in

services/fulfillment.js:62


retrieve

retrieve(id, config?): Fulfillment

Retrieves a fulfillment by its id.

Parameters

Name Type Description
id string the id of the fulfillment to retrieve
config any optional 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

Name Type Description
item LineItem the line item to check has sufficient fulfillable quantity.
quantity number the 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

Name Type
transactionManager any

Returns

FulfillmentService

Defined in

services/fulfillment.js:42