Last updated: Apr 16 2018

Area: Episerver Commerce Applies to versions: 12 and higher
Other versions:

Order group calculator

The OrderGroupCalculator calculates an order's total, subtotal, handling total, shipping subtotal, order discount total, order group total, and tax total.

  • Total. Calculates the total for an order.
    public void GetTotal(IOrderGroup orderGroup, IOrderGroupCalculator orderGroupCalculator)
    {
        var total = orderGroupCalculator.GetTotal(orderGroup);
        Debug.WriteLine("Total for order group '{0}': {1}", orderGroup.OrderLink.OrderGroupId, total);
    }
  • SubTotal. Calculates the subtotal of all order forms for an order.
    public void GetSubTotal(IOrderGroup orderGroup, IOrderGroupCalculator orderGroupCalculator)
    {
        var subTotal = orderGroupCalculator.GetSubTotal(orderGroup);
        Debug.WriteLine("Subtotal for order group '{0}': {1}", orderGroup.OrderLink.OrderGroupId, subTotal);
    }
  • HandlingTotal. Calculates an order's handling total.
    public void GetHandlingTotal(IOrderGroup orderGroup, IOrderGroupCalculator orderGroupCalculator)
    {
        var handlingTotal = orderGroupCalculator.GetHandlingTotal(orderGroup);
        Debug.WriteLine("Handling total for order group '{0}': {1}", orderGroup.OrderLink.OrderGroupId, handlingTotal);
    }
  • ShippingSubTotal. Calculates an order's shipping subtotal.
    public void GetShippingSubTotal(IOrderGroup orderGroup, IOrderGroupCalculator orderGroupCalculator)
    {
        var shippingSubTotal = orderGroupCalculator.GetShippingSubTotal(orderGroup);
        Debug.WriteLine("Shipping subtotal for order group '{0}': {1}", orderGroup.OrderLink.OrderGroupId, shippingSubTotal);
    }
  • OrderDiscountTotal. Calculates the order group discount amount. It is the total of order-level discounts of all line items in all shipments in all order forms of an order group.
    public void GetOrderDiscountTotal(IOrderGroup orderGroup, IOrderGroupCalculator orderGroupCalculator)
    {
        var orderDiscountTotal = orderGroupCalculator.GetOrderDiscountTotal(orderGroup);
        Debug.WriteLine("Order discount total for order group '{0}': {1}", orderGroup.OrderLink.OrderGroupId, orderDiscountTotal);
    }
  • OrderGroupTotals. Calculates order group totals.
    public void GetOrderGroupTotals(IOrderGroup orderGroup, IOrderGroupCalculator orderGroupCalculator)
    {
        var orderGroupTotals = orderGroupCalculator.GetOrderGroupTotals(orderGroup);
        
        Debug.WriteLine("Handling total for order group '{0}': {1}", orderGroup.OrderLink.OrderGroupId, orderGroupTotals.HandlingTotal);
        Debug.WriteLine("Shipping subtotal for order group '{0}': {1}", orderGroup.OrderLink.OrderGroupId, orderGroupTotals.ShippingTotal);
        Debug.WriteLine("Tax total for order group '{0}': {1}", orderGroup.OrderLink.OrderGroupId, orderGroupTotals.TaxTotal);
        Debug.WriteLine("Subtotal for order group '{0}': {1}", orderGroup.OrderLink.OrderGroupId, orderGroupTotals.SubTotal);
        Debug.WriteLine("Total for order group '{0}': {1}", orderGroup.OrderLink.OrderGroupId, orderGroupTotals.Total);
    }
  • TaxTotal. Calculates the tax total for the order.
    public void GetTaxTotal(IOrderGroup orderGroup, IOrderGroupCalculator orderGroupCalculator)
    {
        var taxTotal = orderGroupCalculator.GetTaxTotal(orderGroup);
        Debug.WriteLine("Tax total for order group '{0}': {1}", orderGroup.OrderLink.OrderGroupId, taxTotal);
    }

Changing the default calculation

By inheriting from the default implementation of the interface, DefaultOrderGroupCalculator, you override the calculations. Just override one or more methods in DefaultOrderGroupCalculator.

 Changing the default validation

The default implementation validates that the total is not negative after the calculation. To change the behavior, override the validation methods, depending on which validation you should override.

Comments