Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

TaxTotal in serialized carts incorrect in some cases with custom implementation

Vote:
 

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,

  1. I call our tax service when the page loads on the shopping cart. – This works
  2. I save the response in a property assigned to the ordergroup. – This works
  3. I have overriden CalculateTaxTotal in the OrderGroupCalculator to return whatever value is in that property. – This works
  4. I try to force the IsTaxTotalUpToDate to be set to false so that CalculateTaxTotal is triggered after calling the tax service using the suggestion from Quan here: https://world.episerver.com/forum/developer-forum/Commerce/Thread-Container/2018/5/recalculate-tax/
    1. I believe this is not working. The “IsTaxTotalUpToDate” property in the serializable cart is still true even after this runs. Is there a special way to force this value to be changed for serializable carts?
#257123
Edited, Jun 25, 2021 15:09
Vote:
 

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.

#257125
Jun 25, 2021 16:55
Vote:
 

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);
        }
#257226
Jun 28, 2021 8:09
Vote:
 

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;
                }
            }
#257256
Edited, Jun 28, 2021 15:16
Vote:
 

 
We can try to calculate tax for shipments using IShippingCalculator with CalculateShippingTax + CalculateSalesTax, I think using this approach we can bypass the IsShippingTaxUpToDate flag.

#257300
Jun 29, 2021 5:03
* 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.