StockLevelService

StockLevelService

Package: @vendure/core File: stock-level.service.ts
v2.0.0

The StockLevelService is responsible for managing the stock levels of ProductVariants. Whenever you need to adjust the stockOnHand or stockAllocated for a ProductVariant, you should use this service.

Signature

class StockLevelService {
  constructor(connection: TransactionalConnection, stockLocationService: StockLocationService, configService: ConfigService)
  async getStockLevel(ctx: RequestContext, productVariantId: ID, stockLocationId: ID) => Promise<StockLevel>;
  async getStockLevelsForVariant(ctx: RequestContext, productVariantId: ID) => Promise<StockLevel[]>;
  async getAvailableStock(ctx: RequestContext, productVariantId: ID) => Promise<AvailableStock>;
  async updateStockOnHandForLocation(ctx: RequestContext, productVariantId: ID, stockLocationId: ID, change: number) => ;
  async updateStockAllocatedForLocation(ctx: RequestContext, productVariantId: ID, stockLocationId: ID, change: number) => ;
}

Members

constructor

method
type:
(connection: TransactionalConnection, stockLocationService: StockLocationService, configService: ConfigService) => StockLevelService

getStockLevel

method
type:
(ctx: RequestContext, productVariantId: ID, stockLocationId: ID) => Promise<StockLevel>
Returns the StockLevel for the given ProductVariant and StockLocation.

getStockLevelsForVariant

method
type:
(ctx: RequestContext, productVariantId: ID) => Promise<StockLevel[]>

getAvailableStock

method
type:
(ctx: RequestContext, productVariantId: ID) => Promise<AvailableStock>
Returns the available stock (on hand and allocated) for the given ProductVariant. This is determined by the configured StockLocationStrategy.

updateStockOnHandForLocation

method
type:
(ctx: RequestContext, productVariantId: ID, stockLocationId: ID, change: number) =>
Updates the stockOnHand for the given ProductVariant and StockLocation.

updateStockAllocatedForLocation

method
type:
(ctx: RequestContext, productVariantId: ID, stockLocationId: ID, change: number) =>
Updates the stockAllocated for the given ProductVariant and StockLocation.