Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Return order form calculator

Describes ReturnOrderFormCalculator, which calculates the total, subtotal, handling total, shipping subtotal, order discount total, discount total, and tax total for a return order form in Optimizely Customized Commerce.

Total

Calculates the total for a return order form.

public void GetTotal(IReturnOrderForm returnOrderForm, IMarket market, Currency currency, IReturnOrderFormCalculator returnOrderFormCalculator)
          { 
            var total = returnOrderFormCalculator.GetTotal(returnOrderForm, market, currency);
            Debug.WriteLine("Total for return order form '{0}': {1}", returnOrderForm.OrderFormId, total);
          }

SubTotal

Calculates the total of all shipments in a return order form.

public void GetSubTotal(IReturnOrderForm returnOrderForm, Currency currency, IReturnOrderFormCalculator returnOrderFormCalculator)
          {
            var subTotal = returnOrderFormCalculator.GetSubTotal(returnOrderForm, currency);
            Debug.WriteLine("Subtotal for return order form '{0}': {1}", returnOrderForm.OrderFormId, subTotal);
          }

HandlingTotal

Calculates the handling total for a return order form.

public void GetHandlingTotal(IReturnOrderForm returnOrderForm, Currency currency, IReturnOrderFormCalculator returnOrderFormCalculator)
          {
            var handlingTotal = returnOrderFormCalculator.GetHandlingTotal(returnOrderForm, currency);
            Debug.WriteLine("Handling total for return order form '{0}': {1}", returnOrderForm.OrderFormId, handlingTotal);
          }

ShippingSubtotal

Calculates the shipping subtotal for a return order form.

public void GetShippingSubTotal(IReturnOrderForm returnOrderForm, 
                                        IMarket market, 
                                        Currency currency, 
                                        IReturnOrderFormCalculator returnOrderFormCalculator)
          {
            var shippingSubTotal = returnOrderFormCalculator.GetShippingSubTotal(returnOrderForm, market, currency);
            Debug.WriteLine("Shipping subtotal for return order form '{0}': {1}", returnOrderForm.OrderFormId, shippingSubTotal);
          }

OrderDiscountTotal

Calculates a return order form discount amount. It is the total of order-level discounts of all line items in all shipments in a return order form.

public void GetOrderDiscountTotal(IReturnOrderForm returnOrderForm, Currency currency, IReturnOrderFormCalculator returnOrderFormCalculator)
          {
            var orderDiscountTotal = returnOrderFormCalculator.GetOrderDiscountTotal(returnOrderForm, currency);
            Debug.WriteLine("Order discount total for return order form '{0}': {1}", returnOrderForm.OrderFormId, orderDiscountTotal);
          }

DiscountTotal

Calculates a return order form discount total. It is the total of order-level discount amount and line item discount amount of all line items in all shipments and shipment discount amount of all shipments in a return order form.

public void GetDiscountTotal(IReturnOrderForm returnOrderForm, Currency currency, IReturnOrderFormCalculator returnOrderFormCalculator)
          {
            var discountTotal = returnOrderFormCalculator.GetDiscountTotal(returnOrderForm, currency);
            Debug.WriteLine("Discount total for return order form '{0}': {1}", returnOrderForm.OrderFormId, discountTotal);
          }

TaxTotal

Calculates the tax total for a return order form.

public void GetReturnTaxTotal(IReturnOrderForm returnOrderForm, IMarket market, Currency currency, IReturnOrderFormCalculator returnOrderFormCalculator)
          {
            var returnTaxTotal = returnOrderFormCalculator.GetReturnTaxTotal(returnOrderForm, market, currency);
            Debug.WriteLine("Tax total for return order form '{0}': {1}", returnOrderForm.OrderFormId, returnTaxTotal);
          }

Change the default calculation

By inheriting from the default implementation of the interface, DefaultReturnOrderFormCalculator, you can override the calculations. Just override one or several of the methods in DefaultReturnOrderFormCalculator.

public class ReturnOrderFormCalculatorOverridingDefault : DefaultReturnOrderFormCalculator
      {
        public ReturnOrderFormCalculatorOverridingDefault(IShippingCalculator shippingCalculator, ITaxCalculator taxCalculator)
          : base(shippingCalculator, taxCalculator)
          { }
        protected override Money CalculateTotal(IReturnOrderForm returnOrderForm, IMarket market, Currency currency)
          {
            return new Money(0, currency);
          }
        protected override Money CalculateSubtotal(IReturnOrderForm returnOrderForm, Currency currency)
          {
            return new Money(0, currency);
          }
        protected override Money CalculateHandlingTotal(IReturnOrderForm returnOrderForm, Currency currency)
          {
            return new Money(0, currency);
          }
        protected override Money CalculateShippingSubTotal(IReturnOrderForm returnOrderForm, IMarket market, Currency currency)
          {
            return new Money(0, currency);
          }
        protected override Money CalculateReturnTaxTotal(IReturnOrderForm returnOrderForm, IMarket market, Currency currency)
          {
            return new Money(0, currency);
          }
      }

Change the default validation

The default implementation validates that the totals are not negative after the calculation. To change the behavior, override the ValidateTotal, ValidateSubtotal, ValidateHandlingTotal, ValidateShippingSubTotal, or ValidateTaxTotal method, depending on which validation you should override.

public class ReturnOrderFormCalculatorOverridingDefault : DefaultReturnOrderFormCalculator
      {
        public ReturnOrderFormCalculatorOverridingDefault(IShippingCalculator shippingCalculator, ITaxCalculator taxCalculator)
          : base(shippingCalculator, taxCalculator)
          { }
        protected override void ValidateTotal(Money money)
          {
            if (money.Amount <= 0)
              {
                throw new ValidationException("Total must be greater than 0");
              }
          }
        protected override void ValidateSubtotal(Money money)
          {
            if (money.Amount <= 0)
              {
                throw new ValidationException("Subtotal must be greater than 0");
              }
          }
        protected override void ValidateHandlingTotal(Money money)
          {
            if (money.Amount <= 0)
              {
                throw new ValidationException("Handling total must be greater than 0");
              }
          }
        protected override void ValidateShippingSubTotal(Money money)
          {
            if (money.Amount <= 0)
              {
                throw new ValidationException("Shipping subtotal must be greater than 0");
              }
          }
        protected override void ValidateReturnTaxTotal(Money money)
          {
            if (money.Amount <= 0)
              {
                throw new ValidationException("Return tax total must be greater than 0");
              }
          }
      }