Skip to main content

StockLevelService

StockLevelService

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)
getStockLevel(ctx: RequestContext, productVariantId: ID, stockLocationId: ID) => Promise<StockLevel>;
getStockLevelsForVariant(ctx: RequestContext, productVariantId: ID) => Promise<StockLevel[]>;
getAvailableStock(ctx: RequestContext, productVariantId: ID) => Promise<AvailableStock>;
updateStockOnHandForLocation(ctx: RequestContext, productVariantId: ID, stockLocationId: ID, change: number) => ;
updateStockAllocatedForLocation(ctx: RequestContext, productVariantId: ID, stockLocationId: ID, change: number) => ;
}

constructor

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

getStockLevel

method
(ctx: RequestContext, productVariantId: ID, stockLocationId: ID) => Promise<StockLevel>

Returns the StockLevel for the given ProductVariant and StockLocation.

getStockLevelsForVariant

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

getAvailableStock

method
(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
(ctx: RequestContext, productVariantId: ID, stockLocationId: ID, change: number) =>

Updates the stockOnHand for the given ProductVariant and StockLocation.

updateStockAllocatedForLocation

method
(ctx: RequestContext, productVariantId: ID, stockLocationId: ID, change: number) =>

Updates the stockAllocated for the given ProductVariant and StockLocation.