Why does OrderRepository.SaveAsPurchaseOrder clear my TaxTotal?

Vote:
 

I have an OrderGroup with a non-zero TaxTotal & ShippingTotal.

I used this code to save it as a PurchaseOrder:

        var po = orderRepository.SaveAsPurchaseOrder(orderGroup);

...but, it removed the TaxTotal and ShippingTotal from the OrderGroup I passed in!  They are both zero now.

The resulting PurchaseOrder also has TaxTotal & ShippingTotal of zero.

Why is this happening?  This is not what happens when using Cart.SaveAsPurchaseOrder().

Edit:

I'm using EPiServer Commerce Framework
Version: 9.24 (build: 1)

#173193
Edited, Dec 15, 2016 21:37
Vote:
 

Hi,

What is the full code you are using? Are those values missing from po, or orderGroup?

#173216
Dec 16, 2016 8:52
Vote:
 

Hi Ken

It is happening because the orderRepository is part of the new order handling and as such it will apply the IOrderGroupTotalsCalculator upon saving.

This would be similar to running the CartValidateWorkflow or any other workflow that uses the CalculateTotalsActivity.

You can implement your own calculators and register them to have everything the way you like it, but from what i can gather from your post you might actually get away a lot easier, by just setting your values on the OrderForm instead of on the OrderGroup.

#173226
Dec 16, 2016 10:05
Vote:
 

@Quan - in my example, the value is set on orderGroup before I make the call. 

But after the call, the values are missing from both: orderGroup (the one I passed in), and the po returned to me.

@Erik - You suggested that I work with OrderForm.TaxTotal instead. 

I just tried that, but I see the same behavior --  after I call:

var po = orderRepository.SaveAsPurchaseOrder(orderGroup);

... I see that orderGroup.OrderForms[0].TaxTotal becomes 0.  Also po.OrderForms[0].TaxTotal is 0.  So I don't think that works.

.

Would you recommend using Workflows for the Cart & PurchaseOrder after calling OrderRepository.SaveAsPurchaseOrder ? 

Or do you recommend implementing a custom calculator?  (is there a good example of how to do it?)

#173249
Dec 16, 2016 21:01
Vote:
 

Did the OrderForm approach work for the HandlingTotal?

I would recommend to start with implementing your own ITaxCalculator, possibly inheriting form DeafultTaxCalculator, overriding the CalculateTax method is my first guess and as it operates on shipment that is probably why it won't work when setting on orderform.

You can find some pointers here: http://world.episerver.com/documentation/developer-guides/commerce/orders/calculating-orders/

#173324
Dec 20, 2016 17:27
* 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.