I discovered that PricesIncludeTax dooes not trigger the IsTaxTotalUpToDate flag to change on the serializable carts. Either the marketId or currency needs to be changed to trigger that flag to change.
My new question is this: Is there a less hacky way to do this? It would be nice if epi offered a cleaner solution for manually forcing shipping or tax recalculations.
I had did this in a similar situation in the OrderGroupCalculator, taxes getting calculated in an external system:
public new OrderGroupTotals GetOrderGroupTotals(IOrderGroup orderGroup)
{
if (orderGroup is IOrderGroupCalculatedAmount calculatedAmount)
{
calculatedAmount.IsTaxTotalUpToDate = false;
}
return base.GetOrderGroupTotals(orderGroup);
}
Thanks Jeroen. I tried adding the above method to my OrderGroupCalculator but it never gets called. Then I tried adding the below code to the end of the cart validate functionality on the shopping cart page and it appears to work. (I also neeeded to reset the IsShippingCostUpToDate.)
I am a bit concerned about using this approach however, based on Viet Anh's resonses in this thread about that possibly being inconsistant. https://world.episerver.com/forum/developer-forum/Commerce/Thread-Container/2018/5/recalculate-tax/
if (orderGroup is IOrderGroupCalculatedAmount calculatedAmount)
{
calculatedAmount.IsTaxTotalUpToDate = false;
}
foreach (var shipment in orderGroup.Forms.SelectMany(x => x.Shipments))
{
if (shipment is IShipmentCalculatedAmount shipmentAmount)
{
shipmentAmount.IsShippingCostUpToDate = false;
}
}
We can try to calculate tax for shipments using IShippingCalculator with CalculateShippingTax + CalculateSalesTax, I think using this approach we can bypass the IsShippingTaxUpToDate flag.
Our shipping and tax calls are very slow, so we only want to make these calls when absolutely necessary (on the shopping cart page).
This works perfectly if I change the quantity of the items or add to cart on the shopping cart page.
This problem that I am having is that if any changes occur on a page before reaching the shopping cart page, the “TaxTotal” that is saved in the serialized cart is not correct but the special property that I made to save the tax response is correct.
For the tax portion I have done the following,