Nosferya
Nosferya

Reputation: 31

Prestashop - display both price (vat exc and vat inc) in the product page

I'm making a B2B website with prestashop. So in the customer groups setting I have set that they all see the price with VAT excluded, but I want that in my product pages to display both price. I know that $product.price display the price according to the customer group settings, and $product.price_tax_exc display the price with vat excluded, but what I'm looking for is a way to display the VAT included price, but I have no clue how to do it. My product price is called in the product-add-to-cart.tpl. I'm using prestashop 1.7.5.2 and panda theme.

here is what my code look like for now :

 {assign var=myURI value=$smarty.server.REQUEST_URI}
<span class="price_ht" {if $sttheme.google_rich_snippets} itemprop="price" content="{$product.price_amount}" {/if}>{$product.price_tax_exc|string_format:"%.2f"} {$currency.sign} {if $myURI|strstr:"/fr/"} HT {elseif $myURI|strstr:"/gb/"} "(VAT exc)" {/if}</span>
 <span class="price" {if $sttheme.google_rich_snippets} itemprop="price" content="{$product.price_amount}" {/if}>{$product.price}{if $myURI|strstr:"/fr/"} TTC {elseif $myURI|strstr:"/gb/"} "(VAT inc)"{/if} </span>

But both of my prices display the price with vat excluded, because the variable $product.price display the price according to the customer group settings.

here is an example of what I'm trying to do : https://www.stockresto.com/fr/trancheuse/755-trancheuse-o-195-mm-professionnelle-3611630006279.html

Both prices are displayed on product pages, and the customer group settings on this website is the same as mine.

Does anyone know how I can display the price with VAT included ?

Upvotes: 0

Views: 1699

Answers (2)

Oliver CG
Oliver CG

Reputation: 1

For those who are still awating a reply on this matter, I've found the solution after several hours.

Thing is that, and as it's stated before, when you want to set your PrestaShop as a B2B e-commerce platform, it's useful to show all prices without tax. However, the ProductLazyArray class replace the price and price_tax_exc variables with the price without tax, causing us to not have that information anymore.

I've tried some solutions including the functions:

  • $product->getPrice(false, $smarty.const.NULL). It's not valid anymore for PrestaShop 1.7 since the ProductLazyArray class doesn't have that function.
  • The { convertPrice ... } smarty function is not valid either since it was discontinued in PrestaShop 1.6. Instead, you'll have to use the function Tools::displayPrice().

After checking the Product.php class, I've found that there is a static class to get the price of a given id_product called getPriceStatic. For that, I've added the following code to my .tpl file and it's finally showing the price with tax.

{
  Tools::displayPrice(Product::getPriceStatic($product.id_product))
}

I hope it helps!

Upvotes: 0

Abderraxim
Abderraxim

Reputation: 13

check your edit product in backoffice ,you will find a specific price with vat and without vat. The variables in your template are well set

Upvotes: 0

Related Questions