November Happy Hour will be moved to Thursday December 5th.

Loading...
Applies to versions: 10 and 11
Other versions:
ARCHIVED This content is retired and no longer maintained. See the version selector for other versions of this topic.

Calculating orders

Recommended reading 

The following calculation services are available to calculate order totals in different levels.

  • DefaultLineItemCalculator. Calculates extended price.
  • DefaultShippingCalculator. Calculates shipment cost, and total amount for items in shipment.
  • DefaultTaxCalculator. Calculates taxes.
  • DefaultOrderFormCalculator. Calculates totals on an order form.
  • DefaultOrderGroupCalculator. Calculates totals on an order.

Shipment required for correct calculation

When you create an order (cart, purchase order, or payment plan) through the IOrderRepository, a shipment is created. Order calculators calculate only line items that belong to a shipment. This is a changed behavior from the way it worked with workflow activities. 

Calculate all

The IOrderGroupTotalsCalculator makes calculations for the IOrderGroup, its IOrderForms, IShipments, and ILineItems.

  • The order group.
  • The order group's order forms.
  • Shipments on the order forms.
  • Line items on the shipments.

The method calls all calculators to calculate the values.

Line item calculator

The LineItemCalculator calculates a line item's extended price and discounted price.

  • Extended price. Includes order-level discount amount (spread over all line items in the shipment) and any line item discount amount.
    public void GetExtendedPrice(ILineItem lineItem, ILineItemCalculator lineItemCalculator)
    {
        var extendedPrice = lineItemCalculator.GetExtendedPrice(lineItem, Currency.USD);
        Debug.WriteLine("Extended price for '{0}': {1}", lineItem.Code, extendedPrice);
    }

  • Discounted price. Only calculates the price with the "line item discount amount," that is, the discount for a specific item.
    public void GetDiscountedPrice(ILineItem lineItem, ILineItemCalculator lineItemCalculator)
    {
        var extendedPrice = lineItemCalculator.GetDiscountedPrice(lineItem, Currency.USD);
        Debug.WriteLine("Discounted price for '{0}': {1}", lineItem.Code, extendedPrice);
    }

Change the default calculation of extended price

By inheriting from the default implementation of the interface, DefaultLineItemCalculator, you can override the extended price calculation. Just override the CalculateExtendedPrice method.

Change the validation for extended price

The default implementation validates that the extended price is not negative after the calculation. To change the behavior, override the ValidateExtendedPrice method.

Shipping calculator

The ShippingCalculator calculates the shipping cost of an order, order form, and shipment. It also calculates the total amount of line items in the shipment.

Change the default calculation of shipping cost and shipping item total

By inheriting from the default implementation of the interface, DefaultShippingCalculator, you can override the shipping cost calculation. To change that calculation, override one or several CalculateShippingCost methods. To change the calculation of shipping items' total, override the CalculateShippingItemsTotal method.

Change the validation

The default implementation validates that the shipment cost is not negative after the calculation. To change the behavior, override the method ValidateShipmentCostForOrderValidateShipmentCostForOrderForm, ValidateShipmentCostForShipment, or ValidateShippingItemTotal, depending on which validation you should override.

Tax calculator

The TaxCalculator calculates the tax for order group, order form and shipment.

Change the default calculation of tax total

By inheriting from the default implementation of the interface, DefaultTaxCalculator, you can override the calculation of tax total. Just override one or several  of the following:

  • CalculateTaxTotal for order group
  • CalculateTaxTotal for order form
  • CalculateReturnTaxTotal
  • CalculateShippingTaxTotal
  • CalculateShippingReturnTaxTotal
  • GetTaxCategoryNameById
  • GetsTaxValues

Change the validation

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

  • CalculateTaxTotal for order form
  • CalculateReturnTaxTotalValidateTaxTotalForOrder method
  • CalculateTaxTotal for order form
  • CalculateReturnTaxTotalValidateTaxTotalForOrderForm method

Order form calculator

The OrderFormCalculator calculates the handling total, sub total, and total for an order form.

Change the default calculations

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

  • CalculateTaxTotal for order form, CalculateReturnTaxTotalCalculateHandlingTotal
  • CalculateTaxTotal for order form, CalculateReturnTaxTotalCalculateSubtotal 
  • CalculateTaxTotal for order form, CalculateReturnTaxTotalCalculateTotal

Change the validation

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

  • CalculateTaxTotal for order form, CalculateReturnTaxTotalValidateHandlingTotal
  • CalculateTaxTotal for order form, CalculateReturnTaxTotalValidateSubtotal
  • CalculateTaxTotal for order form, CalculateReturnTaxTotalValidateTotal 

Order calculator

The OrderGroupCalculator calculates an order's handling total, sub total, and total.

Change the default calculations

By inheriting from the default implementation of the interface, DefaultOrderGroupCalculator, you override the calculations. Just override one or several CalculateHandlingTotalCalculateSubtotal, or CalculateTotal methods.

Change the validation

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

Do you find this information helpful? Please log in to provide feedback.

Last updated: Apr 16, 2018

Recommended reading