Display Product Prices Including and Excluding TAX

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 anos atrás
Hi

This so private question so no one help ?
8 anos atrás
Hi,

Has anyone come up with a solution to this problem yet?

Surely all B2B sites within the UK using Nop are struggling with this as Google now forces you to display VAT, but as B2B, showing VAT is non standard and makes you look expensive.

I really want to continue using Nop as Ive been using it for years, but I now have to display two prices, with and without Vat.

I'm open to all suggestions / fixes :)

Thanks
8 anos atrás
bump
8 anos atrás
neilzb wrote:
Hi,

Has anyone come up with a solution to this problem yet?

Surely all B2B sites within the UK using Nop are struggling with this as Google now forces you to display VAT, but as B2B, showing VAT is non standard and makes you look expensive.

I really want to continue using Nop as Ive been using it for years, but I now have to display two prices, with and without Vat.

I'm open to all suggestions / fixes :)

Thanks


It's possible if you're willing to customise the nop code.  As it stands there's only a single price property on the ProductPriceModel which is populated with the inc/ex VAT price (depending on the admin setting) before the model is passed to the _ProductPrice view.  So I don't think it's possible just hack the views. You'd need to add an additional property to the ProductPriceModel to hold the inc. VAT price, then update the ProductControllers PrepareProductDetailsPageModel function to populate that property with the inc. VAT price.  I haven't looked into exactly what's involved but this is the code block that is populating the price property (along with a few other related properties) while taking into account any discounts that might exist:
decimal taxRate;
decimal oldPriceBase = _taxService.GetProductPrice(product, product.OldPrice, out taxRate);
decimal finalPriceWithoutDiscountBase = _taxService.GetProductPrice(product, _priceCalculationService.GetFinalPrice(product, _workContext.CurrentCustomer, includeDiscounts: false), out taxRate);
decimal finalPriceWithDiscountBase = _taxService.GetProductPrice(product, _priceCalculationService.GetFinalPrice(product, _workContext.CurrentCustomer, includeDiscounts: true), out taxRate);

decimal oldPrice = _currencyService.ConvertFromPrimaryStoreCurrency(oldPriceBase, _workContext.WorkingCurrency);
decimal finalPriceWithoutDiscount = _currencyService.ConvertFromPrimaryStoreCurrency(finalPriceWithoutDiscountBase, _workContext.WorkingCurrency);
decimal finalPriceWithDiscount = _currencyService.ConvertFromPrimaryStoreCurrency(finalPriceWithDiscountBase, _workContext.WorkingCurrency);

if (finalPriceWithoutDiscountBase != oldPriceBase && oldPriceBase > decimal.Zero)
    model.ProductPrice.OldPrice = _priceFormatter.FormatPrice(oldPrice);

model.ProductPrice.Price = _priceFormatter.FormatPrice(finalPriceWithoutDiscount);

if (finalPriceWithoutDiscountBase != finalPriceWithDiscountBase)
    model.ProductPrice.PriceWithDiscount = _priceFormatter.FormatPrice(finalPriceWithDiscount);

model.ProductPrice.PriceValue = finalPriceWithoutDiscount;
model.ProductPrice.PriceWithDiscountValue = finalPriceWithDiscount;

It would probably also require some changes to the _taxService.GetProductPrice function to force enable it to force the tax inclusive price irrespective of the admin tax display setting.

That's the gist of what's required but it could get more in depth if you were to look at it properly.  Things like tier prices might complicate the matter.

Having said that, we run a B2B site and don't display tax inclusive pricing.  We don't use Google Products though which I assume is what you're referring to when you say Google forces you to display VAT?
8 anos atrás
Hi,

I was just troubleshooting an issue with the NOPCommerce and came across this post.

I am facing the same problem. I would really appreciate if someone can share inputs on this.

Many thanks in advance.

-Myk
8 anos atrás
Firstly note this is the first time Ive very briefly looked at the NopCommerce source simply as a customer requested if this feature could be added.

This is food for thought but I dont see why you cannot just alter the razor source.

I have only altered it in one place and it would need changing in other places from what im seeing. Mostly in the same page but maybe others.

In the view
\NopCommerce\Presentation\Nop.Web\Views\Product\_ProductPrice.cshtml


after line 47
@*render price*@


I replaced the line
@Html.Raw(Model.Price)


with
 
@{
    Regex ex = new Regex(@"\p{Sc}");
    string currencySymbol = ex.Match(Model.Price).Value;

    ex = new Regex(@"\d.*");
    decimal priceIncVat = Convert.ToDecimal(ex.Match(Model.Price).Value);

    @* Assuming VAT rate of 20% in the UK *@
    decimal priceExcVat = (priceIncVat / ((decimal)20 / 100 + 1));
  }

@Html.Raw(Model.Price +" Inc VAT<br>"+
          currencySymbol + priceExcVat.ToString("N", new CultureInfo("en-gb")) + " Exc VAT")


This is how I would approach it as a simple fix. Maybe somebody who is more knowledgeable of the source could add to this.
8 anos atrás
This is how I have suggested implementing it.

Ive tryed to do it in a way that is the least intrusive and requires the least amount of updates.


NopCommerce version: 3.70

Add the following partial page:
....\Nop.Web\Views\Product\_ProductPriceWithVat.cshtml


Insert the following code:
@*
  Pass in the string containing the price including vat this may have the currency
  indicator which shall be removed for the calculation removing the vat.

  @Html.Partial("_ProductPriceWithVat", [THE_PRICE_STRING])

*@

@model string

@using System.Globalization
@using System.Text.RegularExpressions

@if (!String.IsNullOrEmpty(@Model))
{
    Regex ex = new Regex(@"\p{Sc}");
    string currencySymbol = ex.Match(@Model).Value;

    ex = new Regex(@"\d.*");
    decimal priceIncVat = Convert.ToDecimal(ex.Match(@Model).Value);

    @* Assuming VAT rate of 20% in the UK. Change to your required VAT rate *@
    decimal priceExcVat = (priceIncVat/((decimal) 20/100 + 1));
    
    @* Assuming UK Culture CultureInfo("en-gb"). Change to your required culture. *@
    @Html.Raw(currencySymbol + priceIncVat.ToString("N", new CultureInfo("en-gb"))
            + " Inc VAT<br>"
            + currencySymbol + priceExcVat.ToString("N", new CultureInfo("en-gb"))
            + " Exc VAT")
}



Edit the following file:
....\Nop.Web\Views\Product\_ProductPrice.cshtml


Line 25:
Replace
<span>@Model.RentalPrice</span>

With
<span>@Html.Partial("_ProductPriceWithVat", Model.RentalPrice)</span>


Line 33:
Replace
<span>@Model.OldPrice</span>

With
<span>@Html.Partial("_ProductPriceWithVat", Model.OldPrice)</span>


Line 47:
Replace
@Html.Raw(Model.Price)

With
@Html.Partial("_ProductPriceWithVat", Model.Price)


Line 56:
Replace
@Html.Raw(Model.PriceWithDiscount)

With
@Html.Partial("_ProductPriceWithVat", Model.PriceWithDiscount)


Line 63:
Replace
@Html.Raw(Model.BasePricePAngV)

With
@Html.Partial("_ProductPriceWithVat", Model.BasePricePAngV)


Note: Im not a NopCommerce developer nor do I ever use it, this was simply a question I was asked by a customer. I would be interested to see if other code changes are required by somebody who is experianced with this codebase.
8 anos atrás
In addition to the last post

Edit the following file:
....\Nop.Web\Views\Product\Shared\ _ProductBox.cshtml

Line 56:
Replace
<span class="price old-price">@Model.ProductPrice.OldPrice</span>

With
<span class="price old-price">
  @Html.Partial("~/Views/Product/_ProductPriceWithVat.cshtml",
                Model.ProductPrice.OldPrice)
</span>


Line 58:
Replace
<span class="price actual-price">@Model.ProductPrice.Price</span>

With
<span class="price old-price">
  @Html.Partial("~/Views/Product/_ProductPriceWithVat.cshtml",
                Model.ProductPrice.Price)
</span>
7 anos atrás
Hello,

I figured this out and if someone still need it, this is the way you can implement this. Of cource you need to customize your source code and be able to rebuild the project.

The first step is to go Nop.Web/Models/Catalog/ProductDetailsModel.cs
Inside that file you should search for ProductPriceModel : BaseNopModel.
Here you must add this:
public decimal PriceWithoutVatIncluded { get; set; }


Secondly go to Nop.Web/Models/Catalog/ProductOverviewModel.cs.
Search for ProductPriceModel : BaseNopModel.
Here you must add this as well:
public decimal PriceWithoutVatIncluded { get; set; }


Now that we have filled our Models with the new properties, we should fill them from our controllers.
Find the Nop.Web/Controllers/ProductController.cs.
In the PrepareProductDetailsPageModel you must locate the region which refers to ProductPrice.
When you find it you will see a code block like this:
 else
                    {
                        decimal taxRate;
                        decimal oldPriceBase = _taxService.GetProductPrice(product, product.OldPrice, out taxRate);
                        decimal finalPriceWithoutDiscountBase = _taxService.GetProductPrice(product, _priceCalculationService.GetFinalPrice(product, _workContext.CurrentCustomer, includeDiscounts: false), out taxRate);
                        decimal finalPriceWithDiscountBase = _taxService.GetProductPrice(product, _priceCalculationService.GetFinalPrice(product, _workContext.CurrentCustomer, includeDiscounts: true), out taxRate);

                      

                        decimal oldPrice = _currencyService.ConvertFromPrimaryStoreCurrency(oldPriceBase, _workContext.WorkingCurrency);
                        decimal finalPriceWithoutDiscount = _currencyService.ConvertFromPrimaryStoreCurrency(finalPriceWithoutDiscountBase, _workContext.WorkingCurrency);
                        decimal finalPriceWithDiscount = _currencyService.ConvertFromPrimaryStoreCurrency(finalPriceWithDiscountBase, _workContext.WorkingCurrency);

                        if (finalPriceWithoutDiscountBase != oldPriceBase && oldPriceBase > decimal.Zero)
                            model.ProductPrice.OldPrice = _priceFormatter.FormatPrice(oldPrice);

                        model.ProductPrice.Price = _priceFormatter.FormatPrice(finalPriceWithoutDiscount);

                        if (finalPriceWithoutDiscountBase != finalPriceWithDiscountBase)
                            model.ProductPrice.PriceWithDiscount = _priceFormatter.FormatPrice(finalPriceWithDiscount);

                        model.ProductPrice.PriceValue = finalPriceWithDiscount;

                        //property for German market
                        //we display tax/shipping info only with "shipping enabled" for this product
                        //we also ensure this it's not free shipping
                        model.ProductPrice.DisplayTaxShippingInfo = _catalogSettings.DisplayTaxShippingInfoProductDetailsPage
                            && product.IsShipEnabled &&
                            !product.IsFreeShipping;

                        //PAngV baseprice (used in Germany)
                        model.ProductPrice.BasePricePAngV = product.FormatBasePrice(finalPriceWithDiscountBase,
                            _localizationService, _measureService, _currencyService, _workContext, _priceFormatter);

                        //currency code
                        model.ProductPrice.CurrencyCode = _workContext.WorkingCurrency.CurrencyCode;

                        //rental
                        if (product.IsRental)
                        {
                            model.ProductPrice.IsRental = true;
                            var priceStr = _priceFormatter.FormatPrice(finalPriceWithDiscount);
                            model.ProductPrice.RentalPrice = _priceFormatter.FormatRentalProductPeriod(product, priceStr);
                        }
                    }


After this line :
decimal finalPriceWithDiscountBase = _taxService.GetProductPrice(product, _priceCalculationService.GetFinalPrice(product, _workContext.CurrentCustomer, includeDiscounts: true), out taxRate);
  Go ahead and add this :
  decimal vatCalculation = finalPriceWithoutDiscountBase * taxRate / 100;
                        decimal priceWithoutVatIncluded = finalPriceWithoutDiscountBase - vatCalculation;

                        model.ProductPrice.PriceWithoutVatIncluded = priceWithoutVatIncluded;


Now that you're done with the productController you should be adding a little more code before the magic.
Go to Nop.Web/Extensions/ControllerExtensions.
On line 258 go and add this :
 decimal vatCalculation = finalPriceBase * taxRate / 100;
                                            decimal priceWithoutVatIncluded = finalPriceBase - vatCalculation;

                                            priceModel.PriceWithoutVatIncluded = priceWithoutVatIncluded;


At this point you should be able to rebuild your project.

Finally you have to render what you created.
Go to Nop.Web/Themes/DefaultClean/Views/Product/_ProductPrice.cshtml
After this code block:
 @*render price*@
            <span @if (String.IsNullOrWhiteSpace(Model.PriceWithDiscount)) { <text> itemprop="price" class="price-value-@(Model.ProductId)" </text>  }>
                @Html.Raw(Model.Price)
            </span>

Add this:
<span>@Html.Raw(Model.PriceWithoutVatIncluded)</span>


And then go to Nop.Web/Themes/DefaultClean/Views/Shared/_ProductBox.cshtml
Find the prices div and add this inside:
@Model.ProductPrice.PriceWithoutVatIncluded


And now you have finished.
Hope it works for everyone.
If anything occurs please let me know.
I will be glad to help you out.
Best regards,
Konstantinos.
2 anos atrás
Did anyone make this customization for NOP version 4.2?

I tried it, but this code is completely different from the one mentioned above in the Nop.Web / Controllers / ProductController.cs. it's different.

I found ProductModelFactory.cs but here it is: else
                 {
                     // prices
                     var minPossiblePriceWithoutDiscount = _priceCalculationService.GetFinalPrice (product, _workContext.CurrentCustomer, includeDiscounts: false);
                     var minPossiblePriceWithDiscount = _priceCalculationService.GetFinalPrice (product, _workContext.CurrentCustomer, includeDiscounts: true);

Can anyone help, please ?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.