This topic describes the components invoved when calculating orders in Episerver Commerce.
How it works
The following calculation services are available to calculate order totals in different levels.
- DefaultLineItemCalculator. Calculates extended price, discounted price, line item price and sales tax for item.
- DefaultShippingCalculator. Calculates shipping cost, shipping taxes, and total amount for items in shipment.
- DefaultTaxCalculator. Calculates taxes base on tax value, gets taxes value.
- DefaultOrderFormCalculator. Calculates totals, discount total and tax total on an order form.
- DefaultOrderGroupCalculator. Calculates totals, discount total and tax total on an order.
- DefaultReturnLineItemCalculator. Calculates extended price, discounted price and sales tax for return item.
- DefaultReturnOrderFormCalculator. Calculates totals, discount total and tax total on a return order form.
- DefaultReturnPurchaseOrderCalculator. Calculates totals, discount total on an order.
Improvements in the workings of calculators
Beginning with Commerce 12, Episerver has improved how calculators work when calculating orders.
No unnecessary recalculations
Previously, calculators recalculated prices and taxes even if an order had no changes or if the changes did not affect results. This practice is inefficient, especially when using an external tax service. It also creates problems with old orders, deleted products, expired promotions, new promotions, etc. In Commerce 12, if an order has no changes that affect results, no recalculations take place. Instead, the previously-calculated values are returned.
TaxCategoryId for LineItem property
A new property, TaxCategoryId for LineItem, is available to store TaxCategoryId. So, even if a product is deleted, Commerce retains tax information for processing the order later.
Storing results in relevant objects
In Commerce 12, if calculators process many calculations, such as using an external tax service or reading from a database, the results are stored in relevant objects. As examples, if any of the below properties changes, results are re-calculated and stored with the relevant object.
- OrderGroup/SerializableCart (calculates tax total)
- Shipment/SerializableShipment (calculates shipping tax and shipping cost)
- LineItems: adding/ removing line item
- LineItem/ SerializableLineItem (calculates sales tax)
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.
Last updated: Apr 16, 2018