Is there a way to tell the IOrderGroupCalculator to recalculate the tax when calling for the method GetOrderGroupTotals?
From what I understand, a IOrderGroupCalculatedAmount.IsTaxTotalUpToDate is set to false when for example when adding a new lineitem or updateing quantity, but is there a way to force it to recalculate outside of this?
Commerce Version: 12.2.0
You're right about how the flag works.
The field "IsTaxTotalUpToDate" is manipulated in many order levels: line item, shipment, order group. The calculated tax total is calculated, stored and match with 'UpToDate' flag value. Then the order tax total is made by grouping up from child levels.
If you rewrite GetOrderGroupTotals() and bypass the flag, it may works but still not consistent with the child levels and may cause error somewhere.
You may think about resetting flag at child levels, but since IOrderGroupCalculatedAmount is internal, it's not recommended.
Could you give more details, why the order should be recalculated?
Hi Viet Anh,
We allow for the user to insert a valid VAT number on the order. If this is added and verified, we then don't calculate any tax the order.
Where the problem occurs is when the user inserts this VAT number, we save this on the "extended properties" (no other modifications are made), then we do the "GetOrderGroupTotals".
What about a sneaky hack? What would happen if I would to increase then decrease back a line item - Would this recalculate the tax on all levels?
Yes, changing quantity can trigger the event to reset the flag. Then the tax is recalculated on relevant objects (that line item, its shipment and order group).
I'll check if there's any possible solution in case user input VAT.
/ Viet Anh
We left "forced recalculate taxes" as an open question - i.e. if there is a need for it we can add it later. The reason we did not want to include it in the first place was because it exposes the internal implementation, and it can be abused.
Right now the obvious workaround is to have a method like this (pseudo code)
private void ResetUptodateFlag(IOrderGroup order)
var pricesIncludeTax = order.PricesIncludeTax;
order.PricesIncludeTax = !pricesIncludeTax;
order.PricesIncludeTax = pricesIncludeTax;
Of course it's not beautiful, but I guess you would not want (and I personally don't recommend) to use reflection to access some internal/private methods