🚨 Announcing Vendure v2 Beta

OrderCalculator

OrderCalculator

This helper is used when making changes to an Order, to apply all applicable price adjustments to that Order, including:

  • Promotions
  • Taxes
  • Shipping

Signature

class OrderCalculator {
  constructor(configService: ConfigService, zoneService: ZoneService, taxRateService: TaxRateService, shippingMethodService: ShippingMethodService, shippingCalculator: ShippingCalculator, requestContextCache: RequestContextCacheService)
  async applyPriceAdjustments(ctx: RequestContext, order: Order, promotions: Promotion[], updatedOrderLines: OrderLine[] = [], options?: { recalculateShipping?: boolean }) => Promise<OrderItem[]>;
  public calculateOrderTotals(order: Order) => ;
}

Members

constructor

method
type:
(configService: ConfigService, zoneService: ZoneService, taxRateService: TaxRateService, shippingMethodService: ShippingMethodService, shippingCalculator: ShippingCalculator, requestContextCache: RequestContextCacheService) => OrderCalculator

applyPriceAdjustments

async method
type:
(ctx: RequestContext, order: Order, promotions: Promotion[], updatedOrderLines: OrderLine[] = [], options?: { recalculateShipping?: boolean }) => Promise<OrderItem[]>
Applies taxes and promotions to an Order. Mutates the order object. Returns an array of any OrderItems which had new adjustments applied, either tax or promotions.

calculateOrderTotals

public method
type:
(order: Order) =>

Sets the totals properties on an Order by summing each OrderLine, and taking into account any Surcharges and ShippingLines. Does not save the Order, so the entity must be persisted to the DB after calling this method.

Note that this method does not evaluate any taxes or promotions. It assumes that has already been done and is solely responsible for summing the totals.