Developer forum

Forum » Integration » How to display products with different VAT rates with liveintegration

How to display products with different VAT rates with liveintegration

Frederik Rossen
Frederik Rossen
Reply

Hi, 

We have a customer where certain products are sold with 0% VAT and others with 25% VAT.

It works fine in the cart/checkout, since the "CalculateOrder" call returns prices with and without VAT from the ERP. 

But when going to a productdetail page, the "GetProductsInfo" call just returns a single price "ProductPrice", which doesn't state if it's with or without VAT.

 

What is the recommended way of handling products with different VAT on the productdetail page? 


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Frederik,

it calculates the product price depending on a currently logged in customer. So if customer has "Prices Including VAT" checked then the returned price is with VAT,
otherwise it is without VAT.

On the Dynamicweb side you can configure to show prouducts prices with or without vat.

You can also write a custom extension on D365BC side that will add the new field for the price with/without VAT using our extensibility points
or write custom VAT provider on Dynamciweb side that can apply different VAT percent based on product.

BR, Dmitrij

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Dmitrij,

In this particular case, it's not about the user / the entire cart, it's about specific products. Some products are tax exempt (books, training) and others could be in a low or high rate (think VAT groups in Dynamicweb). What we're trying to achieve is to make live integration aware of this. As Frederik mentioned, it works for the cart, but not for product prices.

I think there are two parts to this question:

1. ERP - As you say, we'll need update the code unit to return a VAT aware price. That would be relatively easy to do custom (however, it would also be nice to have this in the standard code units out of the box)

2. The live pricing part in Dynamicweb - it seems that we can't solve this using a PriceProvider as FindPrice returns a PriceRaw that is VAT unaware. All we can do is return  a decimal value (and a currency) but no VAT info.

A VatProvider seems overkill to me, but even then I don't think we can solve the above issue, can we? If it is the solution, can you give us some pointers on how to implement it?

Would it be an option to add a method to the PriceProvider similar to FindPrice that but that returns a price with VAT? The cart can handle it, so it's mostly just a matter of displaying the correct prices on list and details pages coming from the PriceProvider.

Thanks!

Imar

 

 
Nicolai Pedersen
Reply

Hi Imar

You can actually return a PriceInfo from the priceprovider by implementing ISupportPriceInfo (before 9.12) or IPriceInfoProvider (9.12+) on the PriceProvider implementation.

Using this approach you can take over the VAT calculation.

Other interfaces for the PriceProvider:

  • IPriceReferenceInfo
  • IPriceSourceInfo
  • ISupportInformativePriceInfo (Pre 9.12)
  • IInformativePriceInfoProvider (9.12+)
  • IInformativePriceInfo

BR Nicolai

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply
This post has been marked as an answer

Hi Imar,

Here is a sample code that can be used to implement the ISupportPriceInfo over the Live integrations ProductPriceProvider.
So you can implement some custom logic in the FindPriceInfo method and make a change on ERP side to return the product price with/without VAT and
send it from the ERP on some product custom fields so that they can be then read/filled into the ProductInfo object.

We will look how to implement this feature in a standard Dynamicweb live integration solution in future.

Kind regards, Dmitrij

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

namespace Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Examples
{
    public class CustomProductProvider : ProductProviderBase
    {
        public override double? GetPrice(ProductInfo product, double quantity)
        {
            if (product.ContainsKey("ProductId"))
            {
                string id = product["ProductId"].ToString();
                //Do not query ERP until the flag is set
                if (Context.Current?.Items != null && !Context.Current.Items.Contains(id))
                {
                    return null;
                }
            }
            return base.GetPrice(product, quantity);
        }
    }

    public class CustomProductPriceProvider : ProductPriceProvider, ISupportPriceInfo
    {
        public PriceInfo FindPriceInfo(Product product, double quantity, string variantId, Currency currency, string unitId, User user)
        {
            CustomProductProvider provider = new CustomProductProvider();
            string id = provider.GetProductIdentifier(product);
            //Set a flag to allow FindPrice to query ERP
            if (Context.Current?.Items != null && !Context.Current.Items.Contains(id)) 
            {
                Context.Current.Items.Add(id, null);
            }
            PriceInfo priceInfo = null;
            PriceRaw priceRaw = FindPrice(product, quantity, variantId, currency, unitId, user);
            if(priceRaw != null)
            {
                priceInfo = new PriceInfo(priceRaw.Currency);
                priceInfo.PriceWithVAT = priceRaw.Price;
                priceInfo.VAT = 0.25 * priceRaw.Price;
                priceInfo.PriceWithoutVAT = 0.75 * priceRaw.Price;
            }
            if (Context.Current?.Items != null)
            {
                Context.Current.Items.Remove(id);
            }
            return priceInfo;
        }
    }
}

Votes for this answer: 2
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Thanks guys, we'll give this a try. It looks great!

Imar

 
Stephen Anthony Jackson
Reply

Hi Dimitriy. Where is the "Prices Including VAT" option? I cannot find in the user settings. Also. Is it possible to that do that for an entire group, or only per user?

 

Cheers

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Stephen,
it is located on the NAV/BC customer card page:

But I am not sure if you still need it, since our newer versions of the NAV and D365BC codeunit plugins already output customer-product specific prices with both values: with and without vat, so the response for this request:
<GetEcomData ExternalUserId="20000" AccessUserCustomerNumber="20000">
  <tables>
    <Products type="filter">
      <Product>
        <ProductId>1002</ProductId>
        <ProductVariantId />
        <ProductNumber>1002</ProductNumber>
        <ProductIdentifier>1002</ProductIdentifier>
        <CurrencyCode></CurrencyCode>
        <Quantity>1</Quantity>
      </Product>
    </Products>
  </tables>
</GetEcomData>
looks like that:
 <item table="EcomProducts">
      <column columnName="ProductId"><![CDATA[1002]]></column>
      <column columnName="ProductVariantId"><![CDATA[]]></column>
      <column columnName="ProductIdentifier"><![CDATA[ProductIdentifier]]></column>
      <column columnName="ProductNumber"><![CDATA[1002]]></column>
      <column columnName="ProductName"><![CDATA[test]]></column>
      <column columnName="ProductPrice"><![CDATA[166.667]]></column>
      <column columnName="ProductPriceWithVat"><![CDATA[200]]></column>
      <column columnName="ProductStock"><![CDATA[0]]></column>
      <column columnName="ProductCurrencyCode"><![CDATA[]]></column>
      <column columnName="ProductDefaultUnitId"><![CDATA[Unit_BOX]]></column>
    </item>
BR, Dmitrij

 

You must be logged in to post in the forum