Developer forum

Forum » Development » Tax Provider OR Price Provider

Tax Provider OR Price Provider

Nuno Aguiar
Reply

Hi,

 

We have a client that want's to set tax free for specific users (users are international companies - DW usergroup) billing/shipping to outside our country (the international part of it :P)

 

We never developed a Price Provider nor a Tax Provider. What would be the best approach?

 

Nuno


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Nuno,

Well, it all depends on whether you use taxes or VAT / VAT groups to add the fee.

If you use taxes, you should probably create your own TaxProvider to do the calculation, and skip where appropriate. If you use VAT / VAT groups, you should implement a VatProvider (or a ConfigurableVatProvider if you only need to manipulate a select number of products) to override VAT calculation.

To me, it sounds like VAT is the way to go.

- Jeppe

 
Nuno Aguiar
Reply

Hi Jeppe,

 

VAT provider? I did not know about it, but since we use VAT groups everywhere, and after checking a basic example, seems like the way to go. If the active user meets the conditions, set VAT to 0.

 

But how would it handle setting a VAT updating the cart country? Would it be best to "remove" the possibility for those users to update the country?

From what I can see so far, VAT Providers act on the product, before they are added to the cart, afterwards, we need to update the orderline if we want to make some changes, right?

 

Nuno

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Currently, the prices for orderlines are cached internally, but unfortunately, manipulating the VAT does not clear this cache since the orderline doesn't actually know about the VatProvider. What you need to do is clear the cached price to force recalculation, however, no such clear cached method exists currently. There is a hack you can use until I get the ClearCachedPrices added to the code. Basically, you can set the quantity equals to quantity, which clears the prices.

        public override double FindVatPercent(double DefaultVatPercent, Product Product)
        {
            // Define countries for which VAT is 0.
            var vatExcemptCountries = new List { "SomeCountry", "SomeOtherCountry" };

            // Check VAT exception conditions.
            var cart = Context.Cart;
            if (cart != null && vatExcemptCountries.Contains(cart.CustomerCountry))
            {
                // Clear cached prices on OrderLines.
                // HACK!
                foreach (var ol in cart.OrderLines)
                {
                    ol.Quantity = ol.Quantity;
                }

                // Return VAT percent of 0.
                return 0.0;
            }

            // VAT exception conditions are not met,
            // return double.NaN to indicate we are not handling VAT.
            return double.NaN;
        }

I hope to get the ClearCachedPrices methods into the next hotfix for 8.4 (8.4.0.9) later today.

- Jeppe

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Ignore the "</string>" on line:25. The editor is behaving strangely, so that line is not part of the class :)

- Jeppe

 
Nuno Aguiar
Reply

Hi Jeppe,

 

Thanks for the help and for the hack ;)

 

Nuno

 
Martin Nielsen
Reply

Hi Jeppe,

As a sidenote to this issue.

If you have multiple countries with different VAT percentages fx. DK: 25%, GL: 0%, then the VAT in is calculated incorrectly, when changing the country in the cart, you get something like 23.17% because some of the cart is calculated with 0% and the other half with 25%.

Increasing and Decreasing all orderlines fixes this issue, as your hack suggests.

So please implement the ClearCachedPrices method in the logic for changing country in the cart. :-)

// Martin

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Martin,

Just so I understand, you mean that this is an issue with standard behavior where you change from a country with one VAT percent to a country with a different VAT percent, right? I've added a bug report for that, so we can get it fixed: #14481.

I added OrderLineCollection.ClearCachedPrices() and OrderLine.ChearCachedPrices() to 8.4.0.9, which was released yesterday, so it's possible to fix for custom solutions now.

- Jeppe

 
Martin Nielsen
Reply

Hi Jeppe,

Yes, there's an error in the standard behavior when changing between countries that have different VAT.

Is that a typo in the forum post or in the method name in the API? "OrderLine.ChearCachedPrices()".

// Martin

 

 

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

That's a bug on the forum ;) Both methods are called ClearCachedPrices.

- Jeppe

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Small update with regard to the bug number. The bug number to look for is now #14222.

 

You must be logged in to post in the forum