Developer forum

Forum » Ecommerce - Standard features » Change VAT and initial price but keep total price

Change VAT and initial price but keep total price

Christian Hansen Nørgaard
Reply

HI DW.

I'm not sure if this has been answered before but I couldn't find a match to my query. I'll try to explain as good as I can:

I have a solution with a shop and a website with the Danish language. An English language layer has been added to this website.

I have 2 Currencies (DKK and EUR) and have attached these to each of my website languages (Danish and English).

I have created multiple countries in Internationalization, each with their own VAT rate.

I've created a product with a price like 1000 EUR.

I've found that changing country in the checkout/cart will update the prices and VAT, but I need to have some sort of fixed total price no matter which country I pick but I still need the subtotal and the VAT to change accordingly. Is this possible somehow?

Regards,

Christian


Replies

 
Nicolai Pedersen
Reply

Hi Christian

So you want the price with vat to 1000 no matter if the vat is 25% or 15%?

BR Nicolai

 
Christian Hansen Nørgaard
Reply

Yes I want the total price to be 1000 no matter the VAT. But I still need the subtotal and VAT to change according to the countrys VAT rate so they always are 1000 when combined.

 
Nicolai Pedersen
Reply

That is a tough one... To do that, I think you need to make your own priceprovider. In that you can do the math and calcualte backwards.

Good luck :-)

here is the starting point:

using Dynamicweb.Ecommerce.International;
using Dynamicweb.Ecommerce.Prices;
using Dynamicweb.Ecommerce.Products;
using Dynamicweb.Security.UserManagement;

namespace DynamicwebTemplates.ItemTemplates.Dynamicweb.Ecommerce.PriceProvider
{
    public class MyPriceProvider : PriceProvider
    {
        public override PriceRaw FindPrice(Product product, double quantity, string variantId, Currency currency, string unitId, User user)
        {
            // Get the price from the DefaultPriceProvider
            DefaultPriceProvider defaultProvider = new DefaultPriceProvider();
            PriceRaw rawPrice = defaultProvider.FindPrice(product, quantity, variantId, currency, unitId, user);

            //TODO: Add code here
            return null;
        }
    }
}

 
Christian Hansen Nørgaard
Reply

Hi again.

I am trying to make a "simple" workaround which means I've set a price for each country in Prices on a product. But it seems like I cannot retrieve this list. The VAT changes like it should when I change country but the price remains the same. I've tried looping though a list I found but the only price in this list is the initial price added to the cart and not the price of the product from the Prices list according to the selected country. Any thoughts?


@foreach (LoopItem orderline in GetLoop("OrderLines"))
 {
     foreach (var p in orderline.GetLoop("Product.Prices"))
     {
         <script>console.log(@(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(p.Values)));</script>
     }
}

 
Nicolai Pedersen
Reply

Hi Christian

Can I see a dump of your one of your prices in the UI of the product?

BR Nicolai

 
Christian Hansen Nørgaard
Reply

Is this what you were looking for?

dump.png
 
Nicolai Pedersen
Reply

No, UI = User Interface. So from the backend where you set it up. But I can see the country is set in your data.

Dynamicweb needs to know which country to find the price for before it is added to the cart, so Dynamicweb will use the country set on the ecommerce tab on websites. So before the GB price will be used, it has to be set on the website settings.

You can also override the country on the user context - either by using a querstring parameter: CountryCode=DK etc or by setting the country on the user if it is a logged in user (set on the billing/country code).

Dynamicweb cannot use the country set on the order before that is not applied before the product is added to the cart, and that is after the price have been calculated.

 

You must be logged in to post in the forum