StockLocationStrategy

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.

Signature

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[]>;
}

Extends

Members

getAvailableStock

method
type:
(ctx: RequestContext, productVariantId: ID, stockLevels: StockLevel[]) => AvailableStock | Promise<AvailableStock>
Returns the available stock for the given ProductVariant, taking into account the stock levels at each StockLocation.

forAllocation

method
type:
(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number) => LocationWithQuantity[] | Promise<LocationWithQuantity[]>
Determines which StockLocations should be used to when allocating stock when and Order is placed.

forRelease

method
type:
(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number) => LocationWithQuantity[] | Promise<LocationWithQuantity[]>
Determines which StockLocations should be used to when releasing allocated stock when an OrderLine is cancelled before being fulfilled.

forSale

method
type:
(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number) => LocationWithQuantity[] | Promise<LocationWithQuantity[]>
Determines which StockLocations should be used to when creating a Sale and reducing the stockOnHand upon fulfillment.

forCancellation

method
type:
(ctx: RequestContext, stockLocations: StockLocation[], orderLine: OrderLine, quantity: number) => LocationWithQuantity[] | Promise<LocationWithQuantity[]>
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.

Signature

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

Members

stockOnHand

property
type:
number

stockAllocated

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.

Signature

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

Members

location

property

quantity

property
type:
number