---
title: Order form calculator
slug: commerce-connect-15/docs/order-form-calculator
docTags: 
createdAt: 2026-07-30T20:34:43.000Z
---

## total

Calculates the total for an order form.

```csharp
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.

```csharp
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.

```csharp
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.

```csharp
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, which is the sum of all order-level discounts applied to line items across every shipment in the order form.

```csharp
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, which is the sum of:

- Order-level discount amounts.
- Line item discount amounts for all line items in all shipments.
- Shipment discount amounts for all shipments in the order form.

```csharp
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 all totals for the order form (handling total, shipping subtotal, tax total, subtotal, discount total, and total).

```csharp
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.

```csharp
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);
}
```

## Change the default calculation

Inherit from `DefaultOrderFormCalculator`, the default implementation of `IOrderFormCalculator`, and override one or more of its methods to change the calculation behavior.

```csharp
public class OrderFormCalculatorOverridingDefault: DefaultOrderFormCalculator {
  public OrderFormCalculatorOverridingDefault(IShippingCalculator shippingCalculator, ITaxCalculator taxCalculator): base(shippingCalculator, taxCalculator) {}
  protected override Money CalculateTotal(IOrderForm orderForm, IMarket market, Currency currency) {
    return new Money(0, currency);
  }
  protected override Money CalculateSubtotal(IOrderForm orderForm, Currency currency) {
    return new Money(0, currency);
  }
  protected override Money CalculateHandlingTotal(IOrderForm orderForm, Currency currency) {
    return new Money(0, currency);
  }
  protected override Money CalculateShippingSubTotal(IOrderForm orderForm, IMarket market, Currency currency) {
    return new Money(0, currency);
  }
  protected override Money CalculateTaxTotal(IOrderForm orderForm, IMarket market, Currency currency) {
    return new Money(0, currency);
  }
}
```

## Change the default validation

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

```csharp
public class OrderFormCalculatorOverridingDefault: DefaultOrderFormCalculator {
  public OrderFormCalculatorOverridingDefault(IShippingCalculator shippingCalculator, ITaxCalculator taxCalculator): base(shippingCalculator, taxCalculator) {}
  protected override void ValidateTotal(Money money) {
    if (money.Amount < 0) {
      throw new ValidationException("Order total must not be negative.");
    }
  }
  protected override void ValidateSubtotal(Money money) {
    if (money.Amount < 0) {
      throw new ValidationException("Subtotal must not be negative.");
    }
  }
  protected override void ValidateHandlingTotal(Money money) {
    if (money.Amount < 0) {
      throw new ValidationException("Handling total must not be negative.");
    }
  }
  protected override void ValidateShippingSubTotal(Money money) {
    if (money.Amount < 0) {
      throw new ValidationException("Shipping subtotal must not be negative.");
    }
  }
  protected override void ValidateTaxTotal(Money money) {
    if (money.Amount < 0) {
      throw new ValidationException("Tax total must not be negative.");
    }
  }
}
```
