Calculate orders
2 min
The following calculation services are available to calculate order totals at different levels:
- Line item calculatorLine item calculator – Calculates extended price, discounted price, line item price, and sales tax for an item.
- Shipping calculatorShipping calculator – Calculates shipping cost, shipping taxes, and total amount for items in a shipment.
- Tax calculatorTax calculator – Calculates taxes based on tax value and retrieves tax values.
- Order form calculatorOrder form calculator – Calculates totals, discount total, and tax total on an order form.
- Order group calculatorOrder group calculator – Calculates totals, discount total, and tax total on an order.
- Return line item calculatorReturn line item calculator – Calculates extended price, discounted price, and sales tax for a return item.
- Return order form calculatorReturn order form calculator – Calculates totals, discount total, and tax total on a return order form.
- Return purchase order calculatorReturn purchase order calculator – Calculates totals and discount total on a return purchase order.
Improvements to calculator behavior
Starting in Commerce Connect 12, the order calculation functionality was improved as follows:
- Avoid unnecessary recalculations – Previously, calculators recalculated prices and taxes even if an order had no changes, or if the changes did not affect results. This was inefficient, especially when using an external tax service, and it caused problems with stale data, such as old orders, deleted products, and expired or newly added promotions. In Commerce Connect 12, if an order has no changes that affect results, no recalculation occurs. Instead, the previously calculated values are returned.
- TaxCategoryId property on LineItem – A new TaxCategoryId property on LineItem stores the tax category for the line item. As a result, Commerce Connect retains tax information for later order processing even if the product is deleted.
- Store results on relevant objects – In Commerce Connect 12, when a calculation requires expensive work, such as calling an external tax service or reading from a database, the result is stored on the relevant object. If any of the following properties change, the result is recalculated and saved with the corresponding object.
- OrderGroup or SerializableCart (calculates tax total)
- MarketId
- CurrencyCode
- Shipment or SerializableShipment (calculates shipping tax and shipping cost)
- ShippingMethodId
- ShippingAddress
- LineItems (adding or removing a line item)
- ShipmentDiscount
- LineItem or SerializableLineItem (calculates sales tax)
- PlacedPrice
- Quantity
- OrderAmount
- EntryAmount
- TaxCategoryId
Shipment is required for correct calculation
When you create an order (cart, purchase order, or payment plan) through `IOrderRepository`IOrderRepository, a shipment is created automatically. Order calculators only calculate line items that belong to a shipment — this is a change from the prior workflow-activity behavior.