Skip to main content
Skip to main content

ProductVariantInventoryService

Constructors

constructor

**new ProductVariantInventoryService**(«destructured»)

Parameters

__namedParametersInjectedDependenciesRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
eventBusService_IEventBusServiceRequired
manager_EntityManagerRequired
productVariantService_ProductVariantServiceRequired
salesChannelInventoryService_SalesChannelInventoryServiceRequired
salesChannelLocationService_SalesChannelLocationServiceRequired
transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Protected get**activeManager_**(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

inventoryService_

Protected get**inventoryService_**(): [IInventoryService](/references/services/interfaces/IInventoryService)

Returns

IInventoryService

__joinerConfig() => ModuleJoinerConfigRequired
adjustInventory(inventoryItemId: string, locationId: string, adjustment: number, context?: SharedContext) => Promise<InventoryLevelDTO>Required
confirmInventory(inventoryItemId: string, locationIds: string[], quantity: number, context?: SharedContext) => Promise<boolean>Required
createInventoryItem(input: CreateInventoryItemInput, context?: SharedContext) => Promise<InventoryItemDTO>Required
createInventoryItems(input: CreateInventoryItemInput[], context?: SharedContext) => Promise<InventoryItemDTO[]>Required
createInventoryLevel(data: CreateInventoryLevelInput, context?: SharedContext) => Promise<InventoryLevelDTO>Required
createInventoryLevels(data: CreateInventoryLevelInput[], context?: SharedContext) => Promise<InventoryLevelDTO[]>Required
createReservationItem(input: CreateReservationItemInput, context?: SharedContext) => Promise<ReservationItemDTO>Required
createReservationItems(input: CreateReservationItemInput[], context?: SharedContext) => Promise<ReservationItemDTO[]>Required
deleteInventoryItem(inventoryItemId: string | string[], context?: SharedContext) => Promise<void>Required
deleteInventoryItemLevelByLocationId(locationId: string | string[], context?: SharedContext) => Promise<void>Required
deleteInventoryLevel(inventoryLevelId: string, locationId: string, context?: SharedContext) => Promise<void>Required
deleteReservationItem(reservationItemId: string | string[], context?: SharedContext) => Promise<void>Required
deleteReservationItemByLocationId(locationId: string | string[], context?: SharedContext) => Promise<void>Required
deleteReservationItemsByLineItem(lineItemId: string | string[], context?: SharedContext) => Promise<void>Required
listInventoryItems(selector: FilterableInventoryItemProps, config?: FindConfig<InventoryItemDTO>, context?: SharedContext) => Promise<[InventoryItemDTO[], number]>Required
listInventoryLevels(selector: FilterableInventoryLevelProps, config?: FindConfig<InventoryLevelDTO>, context?: SharedContext) => Promise<[InventoryLevelDTO[], number]>Required
listReservationItems(selector: FilterableReservationItemProps, config?: FindConfig<ReservationItemDTO>, context?: SharedContext) => Promise<[ReservationItemDTO[], number]>Required
restoreInventoryItem(inventoryItemId: string | string[], context?: SharedContext) => Promise<void>Required
retrieveAvailableQuantity(inventoryItemId: string, locationIds: string[], context?: SharedContext) => Promise<number>Required
retrieveInventoryItem(inventoryItemId: string, config?: FindConfig<InventoryItemDTO>, context?: SharedContext) => Promise<InventoryItemDTO>Required
retrieveInventoryLevel(inventoryItemId: string, locationId: string, context?: SharedContext) => Promise<InventoryLevelDTO>Required
retrieveReservationItem(reservationId: string, context?: SharedContext) => Promise<ReservationItemDTO>Required
retrieveReservedQuantity(inventoryItemId: string, locationIds: string[], context?: SharedContext) => Promise<number>Required
retrieveStockedQuantity(inventoryItemId: string, locationIds: string[], context?: SharedContext) => Promise<number>Required
updateInventoryItem(inventoryItemId: string, input: CreateInventoryItemInput, context?: SharedContext) => Promise<InventoryItemDTO>Required
updateInventoryLevel(inventoryItemId: string, locationId: string, update: UpdateInventoryLevelInput, context?: SharedContext) => Promise<InventoryLevelDTO>Required
updateInventoryLevels(updates: &#123; inventory_item_id: string ; location_id: string &#125; & UpdateInventoryLevelInput[], context?: SharedContext) => Promise<InventoryLevelDTO[]>Required
updateReservationItem(reservationItemId: string, input: UpdateReservationItemInput, context?: SharedContext) => Promise<ReservationItemDTO>Required

stockLocationService_

Protected get**stockLocationService_**(): [IStockLocationService](/references/services/interfaces/IStockLocationService)

Returns

IStockLocationService

__joinerConfig() => ModuleJoinerConfigRequired
create(input: CreateStockLocationInput, context?: SharedContext) => Promise<StockLocationDTO>Required
delete(id: string, context?: SharedContext) => Promise<void>Required
list(selector: FilterableStockLocationProps, config?: FindConfig<StockLocationDTO>, context?: SharedContext) => Promise<StockLocationDTO[]>Required
listAndCount(selector: FilterableStockLocationProps, config?: FindConfig<StockLocationDTO>, context?: SharedContext) => Promise<[StockLocationDTO[], number]>Required
retrieve(id: string, config?: FindConfig<StockLocationDTO>, context?: SharedContext) => Promise<StockLocationDTO>Required
update(id: string, input: UpdateStockLocationInput, context?: SharedContext) => Promise<StockLocationDTO>Required

Methods

adjustInventory

**adjustInventory**(variantId, locationId, quantity): Promise&#60;void&#62;

Adjusts inventory of a variant on a location

Parameters

variantIdstringRequired
variant id
locationIdstringRequired
location id
quantitynumberRequired
quantity to adjust

Returns

Promise<void>

PromisePromise<void>Required

adjustReservationsQuantityByLineItem

**adjustReservationsQuantityByLineItem**(lineItemId, variantId, locationId, quantity): Promise&#60;void&#62;

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

Parameters

lineItemIdstringRequired
The ID of the line item
variantIdstringRequired
The ID of the variant
locationIdstringRequired
The ID of the location to prefer adjusting quantities at
quantitynumberRequired
The amount to adjust the quantity by

Returns

Promise<void>

PromisePromise<void>Required

atomicPhase_

Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;

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

attachInventoryItem

**attachInventoryItem**(attachments): Promise&#60;[ProductVariantInventoryItem](/references/services/classes/ProductVariantInventoryItem)[]&#62;

Attach a variant to an inventory item

Parameters

attachments&#123; inventoryItemId: string ; requiredQuantity?: number ; variantId: string &#125;[]Required

Returns

Promise<ProductVariantInventoryItem[]>

PromisePromise<ProductVariantInventoryItem[]>Required
the variant inventory item

**attachInventoryItem**(variantId, inventoryItemId, requiredQuantity?): Promise&#60;[ProductVariantInventoryItem](/references/services/classes/ProductVariantInventoryItem)[]&#62;

Parameters

variantIdstringRequired
inventoryItemIdstringRequired
requiredQuantitynumber

Returns

Promise<ProductVariantInventoryItem[]>

PromisePromise<ProductVariantInventoryItem[]>Required

confirmInventory

**confirmInventory**(variantId, quantity, context?): Promise&#60;[Boolean](/references/services/#boolean)&#62;

confirms if requested inventory is available

Parameters

variantIdstringRequired
id of the variant to confirm inventory for
quantitynumberRequired
quantity of inventory to confirm is available
contextobjectRequired
optionally include a sales channel if applicable

Default: {}

context.salesChannelIdnull | string

Returns

Promise<Boolean>

PromisePromise<Boolean>Required
boolean indicating if inventory is available

deleteReservationsByLineItem

**deleteReservationsByLineItem**(lineItemId, variantId, quantity): Promise&#60;void&#62;

delete a reservation of variant quantity

Parameters

lineItemIdstring | string[]Required
line item id
variantIdstringRequired
variant id
quantitynumberRequired
quantity to release

Returns

Promise<void>

PromisePromise<void>Required

detachInventoryItem

**detachInventoryItem**(inventoryItemId, variantId?): Promise&#60;void&#62;

Remove a variant from an inventory item

Parameters

inventoryItemIdstringRequired
inventory item id
variantIdstring
variant id or undefined if all the variants will be affected

Returns

Promise<void>

PromisePromise<void>Required

getAvailabilityContext

Private **getAvailabilityContext**(variants, salesChannelId, existingContext?): Promise&#60;[Required](/references/services/types/Required)&#60;[AvailabilityContext](/references/services/types/AvailabilityContext)&#62;&#62;

Parameters

variantsstring[]Required
salesChannelIdundefined | string | string[]Required
existingContextAvailabilityContextRequired

Default: {}

Returns

Promise<Required<AvailabilityContext>>

PromisePromise<Required<AvailabilityContext>>Required

getVariantQuantityFromVariantInventoryItems

**getVariantQuantityFromVariantInventoryItems**(variantInventoryItems, channelId): Promise&#60;number&#62;

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

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

Returns

Promise<number>

PromisePromise<number>Required
The available quantity of the variant from the inventoryItems

listByItem

**listByItem**(itemIds): Promise&#60;[ProductVariantInventoryItem](/references/services/classes/ProductVariantInventoryItem)[]&#62;

list registered inventory items

Parameters

itemIdsstring[]Required
list inventory item ids

Returns

Promise<ProductVariantInventoryItem[]>

PromisePromise<ProductVariantInventoryItem[]>Required
list of inventory items

listByVariant

**listByVariant**(variantId): Promise&#60;[ProductVariantInventoryItem](/references/services/classes/ProductVariantInventoryItem)[]&#62;

List inventory items for a specific variant

Parameters

variantIdstring | string[]Required
variant id

Returns

Promise<ProductVariantInventoryItem[]>

PromisePromise<ProductVariantInventoryItem[]>Required
variant inventory items for the variant id

listInventoryItemsByVariant

**listInventoryItemsByVariant**(variantId): Promise&#60;[InventoryItemDTO](/references/services/types/InventoryItemDTO)[]&#62;

lists inventory items for a given variant

Parameters

variantIdstringRequired
variant id

Returns

Promise<InventoryItemDTO[]>

PromisePromise<InventoryItemDTO[]>Required
lidt of inventory items for the variant

listVariantsByItem

**listVariantsByItem**(itemId): Promise&#60;[ProductVariant](/references/services/classes/ProductVariant)[]&#62;

lists variant by inventory item id

Parameters

itemIdstringRequired
item id

Returns

Promise<ProductVariant[]>

PromisePromise<ProductVariant[]>Required
a list of product variants that are associated with the item id

reserveQuantity

**reserveQuantity**(variantId, quantity, context?): Promise&#60;void \| [ReservationItemDTO](/references/services/types/ReservationItemDTO)[]&#62;

Reserves a quantity of a variant

Parameters

variantIdstringRequired
variant id
quantitynumberRequired
quantity to reserve
contextReserveQuantityContextRequired
optional parameters

Default: {}

Returns

Promise<void | ReservationItemDTO[]>

PromisePromise<void | ReservationItemDTO[]>Required

retrieve

**retrieve**(inventoryItemId, variantId): Promise&#60;[ProductVariantInventoryItem](/references/services/classes/ProductVariantInventoryItem)&#62;

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

Parameters

inventoryItemIdstringRequired
The ID of the inventory item to retrieve.
variantIdstringRequired
The ID of the variant to retrieve.

Returns

Promise<ProductVariantInventoryItem>

PromisePromise<ProductVariantInventoryItem>Required
A promise that resolves with the product variant inventory item.

setProductAvailability

**setProductAvailability**(products, salesChannelId): Promise&#60;([Product](/references/services/classes/Product) \| [PricedProduct](/references/services/types/PricedProduct))[]&#62;

Parameters

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

Returns

Promise<(Product | PricedProduct)[]>

PromisePromise<(Product | PricedProduct)[]>Required

setVariantAvailability

**setVariantAvailability**(variants, salesChannelId, availabilityContext?): Promise&#60;[ProductVariant](/references/services/classes/ProductVariant)[] \| [PricedVariant](/references/services/types/PricedVariant)[]&#62;

Parameters

variantsProductVariant[] | PricedVariant[]Required
salesChannelIdundefined | string | string[]Required
availabilityContextAvailabilityContextRequired

Default: {}

Returns

Promise<ProductVariant[] | PricedVariant[]>

PromisePromise<ProductVariant[] | PricedVariant[]>Required

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters

errRecord<string, unknown> | &#123; code: string &#125;Required

Returns

boolean

booleanboolean

validateInventoryAtLocation

**validateInventoryAtLocation**(items, locationId): Promise&#60;void&#62;

Validate stock at a location for fulfillment items

Parameters

itemsOmit<LineItem, "beforeInsert">[]Required
Fulfillment Line items to validate quantities for
locationIdstringRequired
Location to validate stock at

Returns

Promise<void>

PromisePromise<void>Required
nothing if successful, throws error if not

withTransaction

**withTransaction**(transactionManager?): [ProductVariantInventoryService](/references/services/classes/ProductVariantInventoryService)

Parameters

transactionManagerEntityManager

Returns

ProductVariantInventoryService

ProductVariantInventoryServiceProductVariantInventoryServiceRequired
Was this section helpful?