@vendure/core
Version:
A modern, headless ecommerce framework
34 lines • 1.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultOrderLineDiscountDistributionStrategy = void 0;
/**
* @description
* The default {@link 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
* {@link OrderLineDiscountDistributionStrategy}).
*
* @docsCategory orders
* @docsPage OrderLineDiscountDistributionStrategy
* @since 3.7.0
*/
class DefaultOrderLineDiscountDistributionStrategy {
// TODO (next major): consider making a placement-stable strategy (weighting lines by their
// originally-placed quantity) the default, so that refunds reconcile with the order total for
// unconditional order-level promotions. See https://github.com/vendure-ecommerce/vendure/issues/4811
getWeight(ctx, line, order) {
return line.quantity !== 0 ? line.proratedLinePriceWithTax : 0;
}
}
exports.DefaultOrderLineDiscountDistributionStrategy = DefaultOrderLineDiscountDistributionStrategy;
//# sourceMappingURL=default-order-line-discount-distribution-strategy.js.map