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)
applyPriceAdjustments(ctx: RequestContext, order: Order, promotions: Promotion[], updatedOrderLines: OrderLine[] = [], options?: { recalculateShipping?: boolean }) => Promise<Order>;
calculateOrderTotals(order: Order) => ;
}
constructor
method
(configService: ConfigService, zoneService: ZoneService, taxRateService: TaxRateService, shippingMethodService: ShippingMethodService, shippingCalculator: ShippingCalculator, requestContextCache: RequestContextCacheService) => OrderCalculator
applyPriceAdjustments
method
(ctx: RequestContext, order: Order, promotions: Promotion[], updatedOrderLines: OrderLine[] = [], options?: { recalculateShipping?: boolean }) => Promise<Order>
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
method
(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.