Skip to main content
Skip to main content

ProductVariantInventoryService

constructor

Parameters

__namedParametersInjectedDependenciesRequired

Properties

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

Accessors

activeManager_

Returns

EntityManagerEntityManagerRequired

inventoryService_

Returns

IInventoryServiceobjectRequired

stockLocationService_

Returns

IStockLocationServiceobjectRequired

Methods

withTransaction

Parameters

transactionManagerEntityManager

Returns

thisthisRequired

shouldRetryTransaction_

Parameters

errRecord<string, unknown> | objectRequired

Returns

booleanbooleanRequired

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

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

PromisePromise<TResult>Required
the result of the transactional work

confirmInventory

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

PromisePromise<Boolean>Required
boolean indicating if inventory is available

retrieve

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

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

listByItem

list registered inventory items

Parameters

itemIdsstring[]Required
list inventory item ids

Returns

PromisePromise<ProductVariantInventoryItem[]>Required
list of inventory items

listByVariant

List inventory items for a specific variant

Parameters

variantIdstring | string[]Required
variant id

Returns

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

listVariantsByItem

lists variant by inventory item id

Parameters

itemIdstringRequired
item id

Returns

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

listInventoryItemsByVariant

lists inventory items for a given variant

Parameters

variantIdstringRequired
variant id

Returns

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

attachInventoryItem

**attachInventoryItem**(attachments): Promise&#60;[ProductVariantInventoryItem](../../entities/classes/entities.ProductVariantInventoryItem.mdx)[]&#62;

Attach a variant to an inventory item

Parameters

attachmentsobject[]Required

Returns

PromisePromise<ProductVariantInventoryItem[]>Required
the variant inventory item

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

Parameters

variantIdstringRequired
inventoryItemIdstringRequired
requiredQuantitynumber

Returns

PromisePromise<ProductVariantInventoryItem[]>Required

detachInventoryItem

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

PromisePromise<void>Required
Remove a variant from an inventory item

reserveQuantity

Reserves a quantity of a variant

Parameters

variantIdstringRequired
variant id
quantitynumberRequired
quantity to reserve
contextReserveQuantityContextRequired
optional parameters

Default: {}

Returns

PromisePromise<void | ReservationItemDTO[]>Required
Reserves a quantity of a variant

adjustReservationsQuantityByLineItem

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

PromisePromise<void>Required
Adjusts the quantity of reservations for a line item by a given amount.

validateInventoryAtLocation

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

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

deleteReservationsByLineItem

delete a reservation of variant quantity

Parameters

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

Returns

PromisePromise<void>Required
delete a reservation of variant quantity

adjustInventory

Adjusts inventory of a variant on a location

Parameters

variantIdstringRequired
variant id
locationIdstringRequired
location id
quantitynumberRequired
quantity to adjust

Returns

PromisePromise<void>Required
Adjusts inventory of a variant on a location

setVariantAvailability

Parameters

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

Default: {}

Returns

PromisePromise<ProductVariant[] | PricedVariant[]>Required

getAvailabilityContext

Parameters

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

Default: {}

Returns

PromisePromise<Required<AvailabilityContext>>Required

setProductAvailability

Parameters

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

Returns

PromisePromise<(Product | PricedProduct)[]>Required

getVariantQuantityFromVariantInventoryItems

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

PromisePromise<number>Required
The available quantity of the variant from the inventoryItems
Was this section helpful?