Try our conversational search powered by Generative AI!

Taxes: Activity or Calculator?

Vote:
 

Hi,

I'm upgrading from Commerce 11 to 12 and I saw there's now calculators that we can use to do our custom calculations(ex: taxes and totals).

In version 11, we had activity flows with custom classes from OrderGroupActivityBase to calculate our taxes and Totals.

Do we still need those or can I only use a custom class from DefaultTaxCalculator to calculate my taxes?

I tried removing my custom activity flows (removed the project from the solution and edited my ecf.workflow.config) and registering my custom tax class like this:

context.StructureMap().Configure(c =>
{
      c.For().Use();

but it never gets called.

#194666
Jun 27, 2018 17:02
Vote:
 
  • ecf.workflow.config is no longer used since Commerce 9.
  • You must make your IConfigurableModule to depend on EPiServer.Commerce.Initialization.InitializationModule to make sure that your registration happens after the default implementation.
#194669
Jun 27, 2018 18:27
Vote:
 

My initialization module is declared as: 

[InitializableModule]
[ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))]
public class InitializationModule : IConfigurableModule

{

and I use the ConfigureContainer like :

public void ConfigureContainer(ServiceConfigurationContext context)
{
   context.StructureMap().Configure(c =>
  {
     c.For<ITaxCalculator>().Use<MyTaxCalculator>();

In a block controller, if I add ITaxCalculator to a constructor, I get my object(MyTaxCalculator).

In our code, we still call CartHelper.RunWorkflow(OrderGroupWorkflowManager.CartPrepareWorkflowName);

I know cart helper has been replaced and will soon be obsolete, but we can't do the change now.

Is it because I don't use yet the IOrderRepository that the calculators don't works?

#194670
Jun 27, 2018 19:29
Vote:
 

Hmm, it might be a bug here. I'm not sure - I have to check and will get back to you. 

#194672
Jun 27, 2018 20:24
Vote:
 

Any news?

#194736
Jun 29, 2018 13:33
Vote:
 

I asked a developer who has more experience in this area than me (he actually worked in this change in Commerce 12), still waiting for his response) 

#194737
Jun 29, 2018 13:37
Vote:
 

Hi Yan,

In calculators, we are cache the tax value of order group, shipment and line item. So, if it cached, it will not call to the tax calculator anymore.

Please check the value of flag like:

IOrderGroupCalculatedAmount.IsTaxTotalUpToDate

IShipmentCalculatedAmount.IsShippingTaxUpToDate or 

ILineItemCalculatedAmount.IsSalesTaxUpToDate

/Tuan

#194755
Jul 02, 2018 6:36
Vote:
 

Where can I check these flags? Like I said earlier, we still use carthelper and we call the default workflows (like CartPrepare, CartValidate and CartCheckout).

I did another test, this time by using the OrderGroupCalculator.

I've added breakpoints in each functions and they never get called:

public class TestCalculator : DefaultOrderGroupCalculator
{
public TestCalculator(IOrderFormCalculator orderFormCalculator)
: base(orderFormCalculator)
{ }

protected override Money CalculateTotal(IOrderGroup orderGroup)
{
var test = orderGroup.Name;
return base.CalculateTotal(orderGroup);
}

protected override void ValidateTotal(Money money)
{
var test = money.Amount;
base.ValidateTotal(money);
}

protected override Money CalculateSubTotal(IOrderGroup orderGroup)
{
var test = orderGroup.Name;
return base.CalculateSubTotal(orderGroup);
}

protected override void ValidateSubTotal(Money money)
{
var test = money.Amount;
base.ValidateSubTotal(money);
}

protected override Money CalculateHandlingTotal(IOrderGroup orderGroup)
{
var test = orderGroup.Name;
return base.CalculateHandlingTotal(orderGroup);
}

protected override void ValidateHandlingTotal(Money money)
{
var test = money.Amount;
base.ValidateHandlingTotal(money);
}

protected override Money CalculateShippingSubTotal(IOrderGroup orderGroup)
{
var test = orderGroup.Name;
return base.CalculateShippingSubTotal(orderGroup);
}

protected override void ValidateShippingSubTotal(Money money)
{
var test = money.Amount;
ValidateShippingSubTotal(money);
}

protected override void ValidateTaxTotal(Money money)
{
var test = money.Amount;
base.ValidateTaxTotal(money);
}

protected override Money CalculateTaxTotal(IOrderGroup orderGroup)
{
var test = orderGroup.Name;
return base.CalculateTaxTotal(orderGroup);
}

Here's how I registered my class:

[InitializableModule]
[ModuleDependency(typeof(EPiServer.Commerce.Initialization.InitializationModule))]
public class InitializationModule : IConfigurableModule
{
...
public void ConfigureContainer(ServiceConfigurationContext context)
{
context.StructureMap().Configure(c =>
{
c.For<IOrderGroupCalculator>().Singleton().Use<TestCalculator>();

#194815
Jul 04, 2018 2:49
Vote:
 

Ok, i've found out why my calculators were never called, it was because of this specific line in ecf.app.config:

<add feature="WorkflowsVNext" state="Disabled" type="Mediachase.Commerce.Core.Features.WorkflowsVNext, Mediachase.Commerce"/>

I just commented this line and it now works

#194865
Jul 04, 2018 22:54
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.