Posted on 06/11/2019 10:09:35
Thanks for trying.
In this scenario, on 9.6, when you call set unit price with a double, Dynamicweb will encapsulate that value first in a priceraw and then in a PriceCalculated. PriceCalculated is the one holding the VAT - the PriceCalculated instance that is created when calling this overload will be using Common.Context.Currency and Common.Context.Country - holding the information on currency and country which controls the VAT. So you need to ensure that those 2 are correct - try to add a debugger and see if especially that the country is correct.
The orderlineservice also has an overload SetUnitPrice(orderLine As OrderLine, priceInfo As PriceInfo, forcePriceRecalculation As Boolean) where you can pass a PriceInfo - and the priceinfo will hold the amount with and without vat and vat percentage. A somewhat more complicated object, but gives you full control. This can be an alternative.
Usually when overriding prices in Dynamicweb, you would implement a priceprovider instead - that is meant for this scenario - and will be called all the right places. See an example here: https://doc.dynamicweb.com/api/html/46b0e0a8-5a77-3712-038d-c7fbc4e96346.htm. You have access to all the same information, so it is also worth considering.
We are changing quite a bit in this area (prices, currencies and countries) to make things like this more explicit.
In 9.8 we are changing these things quite dramatically to not rely that much on the context - but on the order instance instead. That should simplify manipulations like the one you have here.
BR Nicolai