November Happy Hour will be moved to Thursday December 5th.

Unable to Override the "CalculateShippingTax " method from "IShippingCalculator" in Custom shipping Calculation

P
P
Vote:
 

Hi,

As we wants to override the method of "CalculateShippingTax" it's unable to hit when we called.

Otherthan this methods are being called. For example "CalculateReturnSalesTax", "CalculateSalesTax".

But "CalculateShippingTax" method is not going to fire. Really wondering that why it's happening with this method only.

Here is my code snippet, Please let me know if anything I missed.

public class CustomShippingTaxCalculator : DefaultShippingCalculator
{

   public CustomShippingTaxCalculator ()
   : base(
     ServiceLocator.Current.GetInstance<ILineItemCalculator>(),
     ServiceLocator.Current.GetInstance<IReturnLineItemCalculator>(),
     ServiceLocator.Current.GetInstance<ITaxCalculator>(),
    ServiceLocator.Current.GetInstance<ServiceCollectionAccessor<IShippingPlugin>>(),
    ServiceLocator.Current.GetInstance<ServiceCollectionAccessor<IShippingGateway>>()
    )
  {

    protected override Money CalculateShippingTax(IShipment shipment, IMarket market, Currency currency)
      {
          var shippingTax = GetShippingGstAmount(shipment, market, currency);

           return new Money(currency.Round(shippingTax), currency);

      }

    protected override Money CalculateSalesTax(IShipment shipment, IMarket market, Currency currency)
     {
          var shippingTax = GetShippingGstAmount(shipment, market, currency);

          return new Money(currency.Round(shippingTax), currency);
     }

  }

}

Calling these methods using this code:

var _calc = ServiceLocator.Current.GetInstance<IShippingCalculator>();

var returnTax = _calc.GetReturnSalesTax(shipment, market, currency);
var salesTax = _calc.GetSalesTax(shipment, market, currency);
var shippTax = _shippingCalculator.GetShippingTax(shipment, market, currency);

Thank you!!

#228257
Sep 22, 2020 7:29
Vote:
 

You need to register your CustomShippingTaxCalculator as the implementation of IShippingCalculator as well 

For example, in one of your IConfigurableModule.ConfigureContainer 

services.AddTransient<IShippingCalculator , CustomShippingTaxCalculator >();

#228261
Sep 22, 2020 8:47
P - Sep 22, 2020 12:01

Thanks for you reply.

I have added below code in the "DependencyResolverInitialization"

context.Services.AddSingleton
Vote:
 

It took me a while to finally have time, but here it is https://vimvq1987.com/register-your-custom-implementation-the-sure-way/ 

#228585
Sep 30, 2020 10:01
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.