Determines the weight used to distribute (prorate) an order-level promotion discount across the
OrderLines of an Order. The weights returned for all lines are fed into the
prorate() helper, which splits the total order-level discount amount proportionally.
This makes it possible to control what happens to the distribution when a line is canceled or refunded. The default strategy gives a fully-canceled line (quantity 0) a weight of 0, so its share of the discount is redistributed across the remaining lines. A custom strategy can instead weight lines by their originally-placed quantity, keeping each surviving line's share stable when another line is refunded.
Example
This is configured via the orderOptions.orderLineDiscountDistributionStrategy property of
your VendureConfig.
InjectableStrategy(ctx: RequestContext, line: OrderLine, order: Order) => number | Promise<number>Returns the (non-negative) weight for the given OrderLine. Returning 0 excludes the line from receiving any share of the order-level discount.
The order argument provides the full Order context (e.g. the other lines, the
originally-placed quantities, the order state), allowing a custom strategy to weight a line
relative to the rest of the order rather than in isolation.
The default OrderLineDiscountDistributionStrategy. Weights each line by its current prorated line price (incl. tax) and assigns zero weight to fully-canceled lines (quantity 0). This reproduces Vendure's historical distribution behavior exactly.
This default is consistent with Vendure's promotion model, in which order-level promotions are re-evaluated on every order modification. When an order line is canceled, its share of an order-level discount is redistributed across the surviving lines.
Note that for unconditional order-level promotions (e.g. a flat "$50 off" with no minimum), this redistribution means a partial refund reduces the order total by more than the amount refunded, since the canceled line's discount share moves onto the retained lines. Stores that require the discount distributions to be immutable by refunds should provide a custom strategy that weights lines by their originally-placed quantity (see the example on OrderLineDiscountDistributionStrategy).
OrderLineDiscountDistributionStrategy(ctx: RequestContext, line: OrderLine, order: Order) => number