Skip to main content

MultiChannelStockLocationStrategy

MultiChannelStockLocationStrategy

The MultiChannelStockLocationStrategy is an implementation of the StockLocationStrategy. which is suitable for both single- and multichannel setups. It takes into account the active channel when determining stock levels, and also ensures that allocations are made only against stock locations which are associated with the active channel.

This strategy became the default in Vendure 3.1.0. If you want to use the previous strategy which does not take channels into account, update your VendureConfig to use to DefaultStockLocationStrategy.

Signature
class MultiChannelStockLocationStrategy extends BaseStockLocationStrategy {
protected cacheService: CacheService;
protected channelIdCache: Cache;
protected eventBus: EventBus;
protected globalSettingsService: GlobalSettingsService;
protected requestContextCache: RequestContextCacheService;
getAvailableStock(ctx: RequestContext, productVariantId: ID, stockLevels: StockLevel[]) => Promise<AvailableStock>;
forAllocation(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number) => Promise<LocationWithQuantity[]>;
}
  • Extends: BaseStockLocationStrategy

cacheService

property

channelIdCache

property

eventBus

property

globalSettingsService

requestContextCache

getAvailableStock

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

Returns the available stock for the given ProductVariant, taking into account the active Channel.

forAllocation

method
(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number) => Promise<LocationWithQuantity[]>

This method takes into account whether the stock location is applicable to the active channel. It furthermore respects the trackInventory and outOfStockThreshold settings of the ProductVariant, in order to allocate stock only from locations which are relevant to the active channel and which have sufficient stock available.