Generated the following references: - `entities` - `file` - `fulfillment` - `inventory` - `js_client` - `medusa` - `medusa_config` - `medusa_react` - `modules` - `notification` - `payment` - `price_selection` - `pricing` - `product` - `search` - `services` - `stock_location` - `tax` - `tax_calculation` - `types` - `workflows` Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Co-authored-by: Shahed Nasser <27354907+shahednasser@users.noreply.github.com>
165 lines
12 KiB
Plaintext
165 lines
12 KiB
Plaintext
---
|
|
displayed_sidebar: servicesSidebar
|
|
---
|
|
|
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
|
|
|
# FulfillmentService
|
|
|
|
Handles Fulfillments
|
|
|
|
## constructor
|
|
|
|
### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"__namedParameters","type":"`InjectedDependencies`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="new FulfillmentService"/>
|
|
|
|
___
|
|
|
|
## Properties
|
|
|
|
<ParameterTypes parameters={[{"name":"manager_","type":"`EntityManager`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"transactionManager_","type":"`undefined` \\| `EntityManager`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"__container__","type":"`any`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"totalsService_","type":"[TotalsService](services.TotalsService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"lineItemService_","type":"[LineItemService](services.LineItemService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shippingProfileService_","type":"[ShippingProfileService](services.ShippingProfileService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillmentProviderService_","type":"[FulfillmentProviderService](services.FulfillmentProviderService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"fulfillmentRepository_","type":"Repository<[Fulfillment](../../entities/classes/entities.Fulfillment.mdx)>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"trackingLinkRepository_","type":"Repository<[TrackingLink](../../entities/classes/entities.TrackingLink.mdx)>","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"lineItemRepository_","type":"Repository<[LineItem](../../entities/classes/entities.LineItem.mdx)> & `object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"productVariantInventoryService_","type":"[ProductVariantInventoryService](services.ProductVariantInventoryService.mdx)","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"__configModule__","type":"`Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"__moduleDeclaration__","type":"`Record<string, unknown>`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="FulfillmentService"/>
|
|
|
|
___
|
|
|
|
## Accessors
|
|
|
|
### activeManager\_
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"EntityManager","type":"`EntityManager`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} sectionTitle="activeManager_"/>
|
|
|
|
___
|
|
|
|
## Methods
|
|
|
|
### withTransaction
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"transactionManager","type":"`EntityManager`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="withTransaction"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"this","type":"`this`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} sectionTitle="withTransaction"/>
|
|
|
|
### shouldRetryTransaction\_
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"err","type":"`Record<string, unknown>` \\| `object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="shouldRetryTransaction_"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"boolean","type":"`boolean`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} sectionTitle="shouldRetryTransaction_"/>
|
|
|
|
### 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
|
|
|
|
<ParameterTypes parameters={[{"name":"TResult","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"TError","type":"`object`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="atomicPhase_"/>
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"work","type":"(`transactionManager`: `EntityManager`) => Promise<TResult>","description":"the transactional work to be done","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"isolationOrErrorHandler","type":"`IsolationLevel` \\| (`error`: TError) => Promise<void \\| TResult>","description":"the isolation level to be used for the work.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"maybeErrorHandlerOrDontFail","type":"(`error`: TError) => Promise<void \\| TResult>","description":"Potential error handler","optional":true,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="atomicPhase_"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"Promise","type":"Promise<TResult>","optional":false,"defaultValue":"","description":"the result of the transactional work","expandable":false,"children":[]}]} sectionTitle="atomicPhase_"/>
|
|
|
|
### partitionItems\_
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"shippingMethods","type":"[ShippingMethod](../../entities/classes/entities.ShippingMethod.mdx)[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"items","type":"[LineItem](../../entities/classes/entities.LineItem.mdx)[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="partitionItems_"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"FulfillmentItemPartition[]","type":"`FulfillmentItemPartition`[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} sectionTitle="partitionItems_"/>
|
|
|
|
### getFulfillmentItems\_
|
|
|
|
Retrieves the order line items, given an array of items.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"order","type":"`CreateFulfillmentOrder`","description":"the order to get line items from","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"items","type":"`FulFillmentItemType`[]","description":"the items to get","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="getFulfillmentItems_"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"Promise","type":"Promise<(null \\| [LineItem](../../entities/classes/entities.LineItem.mdx))[]>","optional":false,"defaultValue":"","description":"the line items generated by the transformer.","expandable":false,"children":[]}]} sectionTitle="getFulfillmentItems_"/>
|
|
|
|
### 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
|
|
|
|
<ParameterTypes parameters={[{"name":"item","type":"`undefined` \\| [LineItem](../../entities/classes/entities.LineItem.mdx)","description":"the line item to check has sufficient fulfillable\n quantity.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"`number`","description":"the quantity that is requested to be fulfilled.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="validateFulfillmentLineItem_"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"null \\| LineItem","type":"`null` \\| [LineItem](../../entities/classes/entities.LineItem.mdx)","optional":false,"defaultValue":"","description":"a line item that has the requested fulfillment quantity\n set.","expandable":false,"children":[]}]} sectionTitle="validateFulfillmentLineItem_"/>
|
|
|
|
### retrieve
|
|
|
|
Retrieves a fulfillment by its id.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"fulfillmentId","type":"`string`","description":"the id of the fulfillment to retrieve","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"config","type":"[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)<[Fulfillment](../../entities/classes/entities.Fulfillment.mdx)>","description":"optional values to include with fulfillmentRepository query","optional":false,"defaultValue":"{}","expandable":false,"children":[]}]} sectionTitle="retrieve"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"Promise","type":"Promise<[Fulfillment](../../entities/classes/entities.Fulfillment.mdx)>","optional":false,"defaultValue":"","description":"the fulfillment","expandable":false,"children":[]}]} sectionTitle="retrieve"/>
|
|
|
|
### 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
|
|
|
|
<ParameterTypes parameters={[{"name":"order","type":"`CreateFulfillmentOrder`","description":"order to create fulfillment for","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"itemsToFulfill","type":"`FulFillmentItemType`[]","description":"the items in the order to fulfill","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"custom","type":"Partial<[Fulfillment](../../entities/classes/entities.Fulfillment.mdx)>","description":"potential custom values to add","optional":false,"defaultValue":"{}","expandable":false,"children":[]}]} sectionTitle="createFulfillment"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"Promise","type":"Promise<[Fulfillment](../../entities/classes/entities.Fulfillment.mdx)[]>","optional":false,"defaultValue":"","description":"the created fulfillments","expandable":false,"children":[]}]} sectionTitle="createFulfillment"/>
|
|
|
|
### 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
|
|
|
|
<ParameterTypes parameters={[{"name":"fulfillmentOrId","type":"`string` \\| [Fulfillment](../../entities/classes/entities.Fulfillment.mdx)","description":"the fulfillment object or id.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="cancelFulfillment"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"Promise","type":"Promise<[Fulfillment](../../entities/classes/entities.Fulfillment.mdx)>","optional":false,"defaultValue":"","description":"the result of the save operation","expandable":false,"children":[]}]} sectionTitle="cancelFulfillment"/>
|
|
|
|
### createShipment
|
|
|
|
Creates a shipment by marking a fulfillment as shipped. Adds
|
|
tracking links and potentially more metadata.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[{"name":"fulfillmentId","type":"`string`","description":"the fulfillment to ship","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"config","type":"`CreateShipmentConfig`","description":"potential configuration settings, such as no\\_notification and metadata","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"trackingLinks","type":"`object`[]","description":"tracking links for the shipment","optional":true,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="createShipment"/>
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[{"name":"Promise","type":"Promise<[Fulfillment](../../entities/classes/entities.Fulfillment.mdx)>","optional":false,"defaultValue":"","description":"the shipped fulfillment","expandable":false,"children":[]}]} sectionTitle="createShipment"/>
|