Skip to main content

Class: ProductVariantInventoryService

Hierarchy

  • TransactionBaseService

    ProductVariantInventoryService

Constructors

constructor

new ProductVariantInventoryService(__namedParameters)

Parameters

NameType
__namedParametersInjectedDependencies

Overrides

TransactionBaseService.constructor

Defined in

medusa/src/services/product-variant-inventory.ts:49

Properties

__configModule__

Protected Optional Readonly __configModule__: Record<string, unknown>

Inherited from

TransactionBaseService.__configModule__

Defined in

medusa/src/interfaces/transaction-base-service.ts:14


__container__

Protected Readonly __container__: any

Inherited from

TransactionBaseService.__container__

Defined in

medusa/src/interfaces/transaction-base-service.ts:13


__moduleDeclaration__

Protected Optional Readonly __moduleDeclaration__: Record<string, unknown>

Inherited from

TransactionBaseService.__moduleDeclaration__

Defined in

medusa/src/interfaces/transaction-base-service.ts:15


cacheService_

Protected Readonly cacheService_: ICacheService

Defined in

medusa/src/services/product-variant-inventory.ts:47


eventBusService_

Protected Readonly eventBusService_: IEventBusService

Defined in

medusa/src/services/product-variant-inventory.ts:46


inventoryService_

Protected Readonly inventoryService_: IInventoryService

Defined in

medusa/src/services/product-variant-inventory.ts:45


manager_

Protected manager_: EntityManager

Overrides

TransactionBaseService.manager_

Defined in

medusa/src/services/product-variant-inventory.ts:38


productVariantService_

Protected Readonly productVariantService_: ProductVariantService

Defined in

medusa/src/services/product-variant-inventory.ts:43


salesChannelInventoryService_

Protected Readonly salesChannelInventoryService_: SalesChannelInventoryService

Defined in

medusa/src/services/product-variant-inventory.ts:42


salesChannelLocationService_

Protected Readonly salesChannelLocationService_: SalesChannelLocationService

Defined in

medusa/src/services/product-variant-inventory.ts:41


stockLocationService_

Protected Readonly stockLocationService_: IStockLocationService

Defined in

medusa/src/services/product-variant-inventory.ts:44


transactionManager_

Protected transactionManager_: undefined | EntityManager

Overrides

TransactionBaseService.transactionManager_

Defined in

medusa/src/services/product-variant-inventory.ts:39

Accessors

activeManager_

Protected get activeManager_(): EntityManager

Returns

EntityManager

Inherited from

TransactionBaseService.activeManager_

Defined in

medusa/src/interfaces/transaction-base-service.ts:8

Methods

adjustInventory

adjustInventory(variantId, locationId, quantity): Promise<void>

Adjusts inventory of a variant on a location

Parameters

NameTypeDescription
variantIdstringvariant id
locationIdstringlocation id
quantitynumberquantity to adjust

Returns

Promise<void>

Defined in

medusa/src/services/product-variant-inventory.ts:618


adjustReservationsQuantityByLineItem

adjustReservationsQuantityByLineItem(lineItemId, variantId, locationId, quantity): Promise<void>

Adjusts the quantity of reservations for a line item by a given amount.

Parameters

NameTypeDescription
lineItemIdstringThe ID of the line item
variantIdstringThe ID of the variant
locationIdstringThe ID of the location to prefer adjusting quantities at
quantitynumberThe amount to adjust the quantity by

Returns

Promise<void>

Defined in

medusa/src/services/product-variant-inventory.ts:428


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.

Type parameters

Name
TResult
TError

Parameters

NameTypeDescription
work(transactionManager: EntityManager) => Promise<TResult>the transactional work to be done
isolationOrErrorHandler?IsolationLevel | (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>

the result of the transactional work

Inherited from

TransactionBaseService.atomicPhase_

Defined in

medusa/src/interfaces/transaction-base-service.ts:56


attachInventoryItem

attachInventoryItem(variantId, inventoryItemId, requiredQuantity?): Promise<ProductVariantInventoryItem>

Attach a variant to an inventory item

Parameters

NameTypeDescription
variantIdstringvariant id
inventoryItemIdstringinventory item id
requiredQuantity?numberquantity of variant to attach

Returns

Promise<ProductVariantInventoryItem>

the variant inventory item

Defined in

medusa/src/services/product-variant-inventory.ts:256


confirmInventory

confirmInventory(variantId, quantity, context?): Promise<Boolean>

confirms if requested inventory is available

Parameters

NameTypeDescription
variantIdstringid of the variant to confirm inventory for
quantitynumberquantity of inventory to confirm is available
contextObjectoptionally include a sales channel if applicable
context.salesChannelId?null | string-

Returns

Promise<Boolean>

boolean indicating if inventory is available

Defined in

medusa/src/services/product-variant-inventory.ts:75


deleteReservationsByLineItem

deleteReservationsByLineItem(lineItemId, variantId, quantity): Promise<void>

delete a reservation of variant quantity

Parameters

NameTypeDescription
lineItemIdstringline item id
variantIdstringvariant id
quantitynumberquantity to release

Returns

Promise<void>

Defined in

medusa/src/services/product-variant-inventory.ts:586


detachInventoryItem

detachInventoryItem(inventoryItemId, variantId?): Promise<void>

Remove a variant from an inventory item

Parameters

NameTypeDescription
inventoryItemIdstringinventory item id
variantId?stringvariant id or undefined if all the variants will be affected

Returns

Promise<void>

Defined in

medusa/src/services/product-variant-inventory.ts:318


getAvailabilityContext

Private getAvailabilityContext(variants, salesChannelId, existingContext?): Promise<Required<AvailabilityContext>>

Parameters

NameType
variantsstring[]
salesChannelIdundefined | string | string[]
existingContextAvailabilityContext

Returns

Promise<Required<AvailabilityContext>>

Defined in

medusa/src/services/product-variant-inventory.ts:718


getVariantQuantityFromVariantInventoryItems

getVariantQuantityFromVariantInventoryItems(variantInventoryItems, channelId): Promise<number>

Get the quantity of a variant from a list of variantInventoryItems The inventory quantity of the variant should be equal to the inventory item with the smallest stock, adjusted for quantity required to fulfill the given variant.

Parameters

NameTypeDescription
variantInventoryItemsProductVariantInventoryItem[]List of inventoryItems for a given variant, These must all be for the same variant
channelIdstringSales channel id to fetch availability for

Returns

Promise<number>

The available quantity of the variant from the inventoryItems

Defined in

medusa/src/services/product-variant-inventory.ts:825


listByItem

listByItem(itemIds): Promise<ProductVariantInventoryItem[]>

list registered inventory items

Parameters

NameTypeDescription
itemIdsstring[]list inventory item ids

Returns

Promise<ProductVariantInventoryItem[]>

list of inventory items

Defined in

medusa/src/services/product-variant-inventory.ts:178


listByVariant

listByVariant(variantId): Promise<ProductVariantInventoryItem[]>

List inventory items for a specific variant

Parameters

NameTypeDescription
variantIdstring | string[]variant id

Returns

Promise<ProductVariantInventoryItem[]>

variant inventory items for the variant id

Defined in

medusa/src/services/product-variant-inventory.ts:195


listInventoryItemsByVariant

listInventoryItemsByVariant(variantId): Promise<InventoryItemDTO[]>

lists inventory items for a given variant

Parameters

NameTypeDescription
variantIdstringvariant id

Returns

Promise<InventoryItemDTO[]>

lidt of inventory items for the variant

Defined in

medusa/src/services/product-variant-inventory.ts:234


listVariantsByItem

listVariantsByItem(itemId): Promise<ProductVariant[]>

lists variant by inventory item id

Parameters

NameTypeDescription
itemIdstringitem id

Returns

Promise<ProductVariant[]>

a list of product variants that are associated with the item id

Defined in

medusa/src/services/product-variant-inventory.ts:216


reserveQuantity

reserveQuantity(variantId, quantity, context?): Promise<void | ReservationItemDTO[]>

Reserves a quantity of a variant

Parameters

NameTypeDescription
variantIdstringvariant id
quantitynumberquantity to reserve
contextReserveQuantityContextoptional parameters

Returns

Promise<void | ReservationItemDTO[]>

Defined in

medusa/src/services/product-variant-inventory.ts:348


retrieve

retrieve(inventoryItemId, variantId): Promise<ProductVariantInventoryItem>

Retrieves a product variant inventory item by its inventory item ID and variant ID.

Parameters

NameTypeDescription
inventoryItemIdstringThe ID of the inventory item to retrieve.
variantIdstringThe ID of the variant to retrieve.

Returns

Promise<ProductVariantInventoryItem>

A promise that resolves with the product variant inventory item.

Defined in

medusa/src/services/product-variant-inventory.ts:151


setProductAvailability

setProductAvailability(products, salesChannelId): Promise<(Product | PricedProduct)[]>

Parameters

NameType
products(Product | PricedProduct)[]
salesChannelIdundefined | string | string[]

Returns

Promise<(Product | PricedProduct)[]>

Defined in

medusa/src/services/product-variant-inventory.ts:785


setVariantAvailability

setVariantAvailability(variants, salesChannelId, availabilityContext?): Promise<ProductVariant[] | PricedVariant[]>

Parameters

NameType
variantsProductVariant[] | PricedVariant[]
salesChannelIdundefined | string | string[]
availabilityContextAvailabilityContext

Returns

Promise<ProductVariant[] | PricedVariant[]>

Defined in

medusa/src/services/product-variant-inventory.ts:659


shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

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

Returns

boolean

Inherited from

TransactionBaseService.shouldRetryTransaction_

Defined in

medusa/src/interfaces/transaction-base-service.ts:37


validateInventoryAtLocation

validateInventoryAtLocation(items, locationId): Promise<void>

Validate stock at a location for fulfillment items

Parameters

NameTypeDescription
itemsOmit<LineItem, "beforeInsert">[]Fulfillment Line items to validate quantities for
locationIdstringLocation to validate stock at

Returns

Promise<void>

nothing if successful, throws error if not

Defined in

medusa/src/services/product-variant-inventory.ts:529


withTransaction

withTransaction(transactionManager?): ProductVariantInventoryService

Parameters

NameType
transactionManager?EntityManager

Returns

ProductVariantInventoryService

Inherited from

TransactionBaseService.withTransaction

Defined in

medusa/src/interfaces/transaction-base-service.ts:20

Was this page helpful?