Create a custom order calculator

The IOrderCalculator interface allows you to do every calculation related to the order by yourself. Although this is not a trivial task to do (to take over calculations), it gives you the flexibility to do anything you want with the calculation mechanism.

NOTE: Using a custom implementation of the IOrderCalculator interface overrides the build-in calculations done by the Ecommerce module. This means you have to perform all the calculations by yourself.

To create a custom order calculator, you must perform the following:

  1. Create a class for your custom order calculator.
    Create a class that will represent the order calculator. In this example the name CustomOrederCalculator is used.
  2. Inherit the EcommerceCalculatorBase class.
    Your custom order calculator class must inherit the EcommerceCalculatorBase class.
  3. Implement the IOrderCalculator interface, by implementing CalculateAndSaveChanges method.
  4. Implement the CalculateAndSaveChanges method.
    In this method you can perform manually all the calculations regarding the order. As an argument you receive the cart order.
  5. Register the custom order calculator.
    In the Global.asax file, register the custom order calculator in the following way:

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?