Loading...

Last updated: Apr 16 2018

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

Order form calculator

The OrderFormCalculator calculates the following for an order form: total, subtotal, handling total, shipping subtotal, order discount total, discount total, order form totals, and tax total.

  • Total. Calculates the total for an order form.
    public void GetTotal(IOrderForm orderForm, IMarket market, Currency currency, IOrderFormCalculator orderFormCalculator)
    {
        var total = orderFormCalculator.GetTotal(orderForm, market, currency);
        Debug.WriteLine("Total for order form '{0}': {1}", orderForm.OrderFormId, total);
    }
  • SubTotal. Calculates the total of all shipments in an order form.
    public void GetSubTotal(IOrderForm orderForm, Currency currency, IOrderFormCalculator orderFormCalculator)
    {
        var subTotal = orderFormCalculator.GetSubTotal(orderForm, currency);
        Debug.WriteLine("Subtotal for order form '{0}': {1}", orderForm.OrderFormId, subTotal);
    }
  • HandlingTotal. Calculates the handling total for an order form.
    public void GetHandlingTotal(IOrderForm orderForm, Currency currency, IOrderFormCalculator orderFormCalculator)
    {
        var handlingTotal = orderFormCalculator.GetHandlingTotal(orderForm, currency);
        Debug.WriteLine("Handling total for order form '{0}': {1}", orderForm.OrderFormId, handlingTotal);
    }
  • ShippingSubtotal. Calculates the shipping subtotal for an order form.
    public void GetShippingSubTotal(IOrderForm orderForm, IMarket market, Currency currency, IOrderFormCalculator orderFormCalculator)
    {
        var shippingSubTotal = orderFormCalculator.GetShippingSubTotal(orderForm, market, currency);
        Debug.WriteLine("Shipping subtotal for order form '{0}': {1}", orderForm.OrderFormId, shippingSubTotal);
    }
  • OrderDiscountTotal. Calculates the order form discount amount. It is the total of all order-level discounts of all line items in all shipments in an order form.
    public void GetOrderDiscountTotal(IOrderForm orderForm, Currency currency, IOrderFormCalculator orderFormCalculator)
    {
        var orderDiscountTotal = orderFormCalculator.GetOrderDiscountTotal(orderForm, currency);
        Debug.WriteLine("Order discount total for order form '{0}': {1}", orderForm.OrderFormId, orderDiscountTotal);
    }
  • DiscountTotal. Calculates the order form discount total. It is the total of
    • order-level discount amounts
    • line item discount amounts for all line items in all shipments
    • shipment discount amounts of all shipments in an order form
     public void GetDiscountTotal(IOrderForm orderForm, Currency currency, IOrderFormCalculator orderFormCalculator)
    {
        var discountTotal = orderFormCalculator.GetDiscountTotal(orderForm, currency);
        Debug.WriteLine("Discount total for order form '{0}': {1}", orderForm.OrderFormId, discountTotal);
    }
  • OrderFormTotals. Calculates the order form total.
    public void GetOrderFormTotals(IOrderForm orderForm, IMarket market, Currency currency, IOrderFormCalculator orderFormCalculator)
    {
        var orderFormTotals = orderFormCalculator.GetOrderFormTotals(orderForm, market, currency);
    
        Debug.WriteLine("Handling total for order form '{0}': {1}", orderForm.OrderFormId, orderFormTotals.HandlingTotal);
        Debug.WriteLine("Shipping subtotal for order form '{0}': {1}", orderForm.OrderFormId, orderFormTotals.ShippingTotal);
        Debug.WriteLine("Tax total for order form '{0}': {1}", orderForm.OrderFormId, orderFormTotals.TaxTotal);
        Debug.WriteLine("Subtotal for order form '{0}': {1}", orderForm.OrderFormId, orderFormTotals.SubTotal);
        Debug.WriteLine("Discount total for order form '{0}': {1}", orderForm.OrderFormId, orderFormTotals.DiscountTotal);
        Debug.WriteLine("Total for order form '{0}': {1}", orderForm.OrderFormId, orderFormTotals.Total);
    }
  • TaxTotal. Calculates an order form's tax total.
    public void GetTaxTotal(IOrderForm orderForm, IMarket market, Currency currency, IOrderFormCalculator orderFormCalculator)
    {
        var taxTotal = orderFormCalculator.GetTaxTotal(orderForm, market, currency);
        Debug.WriteLine("Tax total for order form '{0}': {1}", orderForm.OrderFormId, taxTotal);
    }

    Changing the default calculation

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

Changing the default validation

The default implementation validates that the total is not negative after the calculation. To change the behavior, override the appropriate method: ValidateTotal, ValidateSubtotal, ValidateHandlingTotal, ValidateShippingSubtotal, or ValidateTaxTotal.


Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/