Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Calculate orders

Describes the components involved when calculating orders in Optimizely Commerce Connect.

The following calculation services are available to calculate order totals at different levels:

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, 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.