Skip to content

Latest commit

 

History

History
161 lines (107 loc) · 7.44 KB

stock-location-strategy.md

File metadata and controls

161 lines (107 loc) · 7.44 KB
title isDefaultIndex generated
StockLocationStrategy
false
true

import MemberInfo from '@site/src/components/MemberInfo'; import GenerationInfo from '@site/src/components/GenerationInfo'; import MemberDescription from '@site/src/components/MemberDescription';

StockLocationStrategy

The StockLocationStrategy is responsible for determining which StockLocations should be used to fulfill an OrderLine and how much stock should be allocated from each location. It is also used to determine the available stock for a given ProductVariant.

:::info

This is configured via the catalogOptions.stockLocationStrategy property of your VendureConfig.

:::

interface StockLocationStrategy extends InjectableStrategy {
    getAvailableStock(
        ctx: RequestContext,
        productVariantId: ID,
        stockLevels: StockLevel[],
    ): AvailableStock | Promise<AvailableStock>;
    forAllocation(
        ctx: RequestContext,
        stockLocations: StockLocation[],
        orderLine: OrderLine,
        quantity: number,
    ): LocationWithQuantity[] | Promise<LocationWithQuantity[]>;
    forRelease(
        ctx: RequestContext,
        stockLocations: StockLocation[],
        orderLine: OrderLine,
        quantity: number,
    ): LocationWithQuantity[] | Promise<LocationWithQuantity[]>;
    forSale(
        ctx: RequestContext,
        stockLocations: StockLocation[],
        orderLine: OrderLine,
        quantity: number,
    ): LocationWithQuantity[] | Promise<LocationWithQuantity[]>;
    forCancellation(
        ctx: RequestContext,
        stockLocations: StockLocation[],
        orderLine: OrderLine,
        quantity: number,
    ): LocationWithQuantity[] | Promise<LocationWithQuantity[]>;
}

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>, stockLevels: <a href='/reference/typescript-api/entities/stock-level#stocklevel'>StockLevel</a>[]) => <a href='/reference/typescript-api/products-stock/stock-location-strategy#availablestock'>AvailableStock</a> | Promise&#60;<a href='/reference/typescript-api/products-stock/stock-location-strategy#availablestock'>AvailableStock</a>&#62;} />

Returns the available stock for the given ProductVariant, taking into account the stock levels at each StockLocation.

forAllocation

<MemberInfo kind="method" type={(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, stockLocations: <a href='/reference/typescript-api/entities/stock-location#stocklocation'>StockLocation</a>[], orderLine: <a href='/reference/typescript-api/entities/order-line#orderline'>OrderLine</a>, quantity: number) => <a href='/reference/typescript-api/products-stock/stock-location-strategy#locationwithquantity'>LocationWithQuantity</a>[] | Promise&#60;<a href='/reference/typescript-api/products-stock/stock-location-strategy#locationwithquantity'>LocationWithQuantity</a>[]&#62;} />

Determines which StockLocations should be used to when allocating stock when and Order is placed.

forRelease

<MemberInfo kind="method" type={(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, stockLocations: <a href='/reference/typescript-api/entities/stock-location#stocklocation'>StockLocation</a>[], orderLine: <a href='/reference/typescript-api/entities/order-line#orderline'>OrderLine</a>, quantity: number) => <a href='/reference/typescript-api/products-stock/stock-location-strategy#locationwithquantity'>LocationWithQuantity</a>[] | Promise&#60;<a href='/reference/typescript-api/products-stock/stock-location-strategy#locationwithquantity'>LocationWithQuantity</a>[]&#62;} />

Determines which StockLocations should be used to when releasing allocated stock when an OrderLine is cancelled before being fulfilled.

forSale

<MemberInfo kind="method" type={(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, stockLocations: <a href='/reference/typescript-api/entities/stock-location#stocklocation'>StockLocation</a>[], orderLine: <a href='/reference/typescript-api/entities/order-line#orderline'>OrderLine</a>, quantity: number) => <a href='/reference/typescript-api/products-stock/stock-location-strategy#locationwithquantity'>LocationWithQuantity</a>[] | Promise&#60;<a href='/reference/typescript-api/products-stock/stock-location-strategy#locationwithquantity'>LocationWithQuantity</a>[]&#62;} />

Determines which StockLocations should be used to when creating a Sale and reducing the stockOnHand upon fulfillment.

forCancellation

<MemberInfo kind="method" type={(ctx: <a href='/reference/typescript-api/request/request-context#requestcontext'>RequestContext</a>, stockLocations: <a href='/reference/typescript-api/entities/stock-location#stocklocation'>StockLocation</a>[], orderLine: <a href='/reference/typescript-api/entities/order-line#orderline'>OrderLine</a>, quantity: number) => <a href='/reference/typescript-api/products-stock/stock-location-strategy#locationwithquantity'>LocationWithQuantity</a>[] | Promise&#60;<a href='/reference/typescript-api/products-stock/stock-location-strategy#locationwithquantity'>LocationWithQuantity</a>[]&#62;} />

Determines which StockLocations should be used to when creating a Cancellation of an OrderLine which has already been fulfilled.

AvailableStock

The overall available stock for a ProductVariant as determined by the logic of the StockLocationStrategy's getAvailableStock method.

interface AvailableStock {
    stockOnHand: number;
    stockAllocated: number;
}

stockOnHand

<MemberInfo kind="property" type={number} />

stockAllocated

<MemberInfo kind="property" type={number} />

LocationWithQuantity

Returned by the StockLocationStrategy methods to indicate how much stock from each location should be used in the allocation/sale/release/cancellation of an OrderLine.

interface LocationWithQuantity {
    location: StockLocation;
    quantity: number;
}

location

<MemberInfo kind="property" type={<a href='/reference/typescript-api/entities/stock-location#stocklocation'>StockLocation</a>} />

quantity

<MemberInfo kind="property" type={number} />