---
title: "StockLevelService"
generated: true
---
<GenerationInfo sourceFile="packages/core/src/service/services/stock-level.service.ts" sourceLine="23" packageName="@vendure/core" since="2.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.

```ts title="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) => ;
}
```

<div className="members-wrapper">

### constructor

<MemberInfo kind="method" type={`(connection: <a href='/reference/typescript-api/data-access/transactional-connection#transactionalconnection'>TransactionalConnection</a>, stockLocationService: <a href='/reference/typescript-api/services/stock-location-service#stocklocationservice'>StockLocationService</a>, configService: ConfigService) => StockLevelService`}   />


### getStockLevel

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, productVariantId: <a href='/reference/typescript-api/common/id#id'>ID</a>, stockLocationId: <a href='/reference/typescript-api/common/id#id'>ID</a>) => Promise<<a href='/reference/typescript-api/entities/stock-level#stocklevel'>StockLevel</a>>`}   />

Returns the StockLevel for the given <DocsLink href="/reference/typescript-api/entities/product-variant#productvariant">ProductVariant</DocsLink> and <DocsLink href="/reference/typescript-api/entities/stock-location#stocklocation">StockLocation</DocsLink>.
### getStockLevelsForVariant

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, productVariantId: <a href='/reference/typescript-api/common/id#id'>ID</a>) => Promise<<a href='/reference/typescript-api/entities/stock-level#stocklevel'>StockLevel</a>[]>`}   />


### getAvailableStock

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, productVariantId: <a href='/reference/typescript-api/common/id#id'>ID</a>) => Promise<<a href='/reference/typescript-api/products-stock/stock-location-strategy#availablestock'>AvailableStock</a>>`}   />

Returns the available stock (on hand and allocated) for the given <DocsLink href="/reference/typescript-api/entities/product-variant#productvariant">ProductVariant</DocsLink>. This is determined
by the configured <DocsLink href="/reference/typescript-api/products-stock/stock-location-strategy#stocklocationstrategy">StockLocationStrategy</DocsLink>.
### updateStockOnHandForLocation

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, productVariantId: <a href='/reference/typescript-api/common/id#id'>ID</a>, stockLocationId: <a href='/reference/typescript-api/common/id#id'>ID</a>, change: number) => `}   />

Updates the `stockOnHand` for the given <DocsLink href="/reference/typescript-api/entities/product-variant#productvariant">ProductVariant</DocsLink> and <DocsLink href="/reference/typescript-api/entities/stock-location#stocklocation">StockLocation</DocsLink>.
### updateStockAllocatedForLocation

<MemberInfo kind="method" type={`(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, productVariantId: <a href='/reference/typescript-api/common/id#id'>ID</a>, stockLocationId: <a href='/reference/typescript-api/common/id#id'>ID</a>, change: number) => `}   />

Updates the `stockAllocated` for the given <DocsLink href="/reference/typescript-api/entities/product-variant#productvariant">ProductVariant</DocsLink> and <DocsLink href="/reference/typescript-api/entities/stock-location#stocklocation">StockLocation</DocsLink>.


</div>
