This section describes the calculation of the order grand total.
Order grand total is the final amount that the end customer has to pay to the merchant.
The following diagram shows the formula used to calculate the order grand total. Please see the Pricing fields of an order article for the exact fields that these values are recorded in and the formulas used.

The actual calculations are done in the pricing rules plugin. The plugin can be changed to accomodate custom logic if required. More information on implementation can be found in this article.
Order of calculations
Each of the above items in the order grand total calculation are made in separate sections in the implementation. The calculations are made in the following order:
- Delivery cost.
- Fees.
- Campaigns (campaigns may re-calculate delivery cost, fees, order row total and VAT seperately).
- Order row total.
- VAT, the last step of the VAT calculation is to make the order grand total calculation shown above.
How to initiate the order grand total calculation
If you are using web controls provided by Litium to update the shopping cart, such as the buy button, this calculation is done automatically, and the programmer does not have to do anything extra.
However, in the checkout-flow template, you need to call an order grand total calculation, when information that would change the order grand total is available. For example, after the delivery address and delivery method is available, you can calculate the delivery cost.
You may initiate the order grand total calculation in two ways:
- Using the order object: call the
Order::CalculateOrderTotals(SecurityToken token) method.
- Using the order carrier: call the
Module<ModuleECommerce>.Instance.Orders.CalculateOrderTotals(CurrentState.Current.ShoppingCart.OrderCarrier, CurrentState.Current.Token); method.
When to calculate the order grand total:
Order grand total has to be calculated on the following occasions. All calculations should be made for a new order, which is in Init state, before it is confirmed:
- When adding, removing or changing the quantity of an item in the order.
- When the user saves the shopping cart for future use, and reloads it when logging in at a later date.
- When the user's personal information changes.
- When the currency of the order changes.
When NOT to calculate the order grand total
The order grand total calculations should not be initiated after the user has confirmed an order. The exact states of an order depends on your own implementation, in the default implementation this is the Confirmed order state, which comes after the Init state.
Whatever your implementation will be, there will be a step where the buyer and seller agrees for a final purchase price and related conditions. At this point, a sale is made, and a legally binding contract is started. This contract will be in violation, if any of the conditions, prices or anything else changes without the agreement of both parties.
Since a price re-calculation may involve campaigns, and new prices being fetched from price lists etc., there is a chance of changing the final grand total if a price calculation is initiated after the order has been confirmed. Therefore, it is strongly recommended NOT to initiate a price recalculation, or change anything related to the order after an order has been set to Confirmed.
Therefore, all information and calculations should be done, before the order confirmation.