Jump to content

Display prices without tax in cart checkout (1.7)


Shira7

Recommended Posts

I'm trying to display item prices excluding tax, I have accomplished that in the category listings and product details, editing /themes/classic/templates/catalog/_partials/product-prices.tpl + miniatures/product.tpl and changing ($product.price} to {Tools::displayPrice($product.price_tax_exc)}

however the same does not work for the cart checkout in /themes/classic/templates/checkout/_partials/cart-summary-product-line.tpl

neither {$product.price_tax_exc} nor {Tools::displayPrice($product.price_tax_exc)} seems to do the trick here, it's just blank where the price should be.

How can I do it?

Link to comment
Share on other sites

  • 4 months later...
On 9/22/2020 at 6:47 AM, Guest said:

If you make a screen page where you want to edit, I will advise. 😉

I managed to create a tiny module where I show both prices (with and without tax) using:

$priceWithTax = Tools::displayPrice($product->getPrice(true, null, 6, null, false, false), $this->context->currency);
$priceWithoutTax = Tools::displayPrice($product->getPrice(false, null, 6, null, false, false), $this->context->currency);

Just need to find out how to display the discounted prices with and without tax

  • Thanks 1
Link to comment
Share on other sites

😁 I have my own module and I need someone to write the whole module for them ...

Use the hooks to display the price without VAT.
The following hooks are available:

{hook h='displayProductPriceBlock' product=$product type="old_price"}
{hook h='displayProductPriceBlock' product=$product type="before_price"}
{hook h='displayProductPriceBlock' product=$product type="after_price"}
{hook h='displayProductPriceBlock' product=$product type="price"}
{hook h='displayProductPriceBlock' product=$product type="unit_price"}
{hook h='displayProductPriceBlock' product=$product type="weight"}

In the module you will use eg:

public function hookHeader($params)
{
	$page_name = Dispatcher::getInstance()->getController();    
    // or create JavaScript and override original price

    if (Tools::getValue('id_product') && $page_name == 'product'){ // change only product page

		$product = new Product((int)Tools::getValue('id_product');

		$priceWithTax = Tools::displayPrice($product->getPrice(true, null, 6, null, false, false), $this->context->currency);
		$priceWithoutTax = Tools::displayPrice($product->getPrice(false, null, 6, null, false, false), $this->context->currency);

		Media::addJsDef(array(
			'priceWithTax' => $priceWithTax,
			'priceWithoutTax' => $priceWithoutTax,
		));	
		
		$this->context->controller->addJS(_PS_MODULE_DIR_.$this->name.'/js/custom.js'); // add custom javascript
        /**
		$(document).ready(function() {
        	$('.product-unit-price').html(priceWithTax+'<br><p class="price-without-tax">'+priceWithoutTax+'</p>');
    	});
        */
	}

	$this->context->controller->addCSS(_PS_MODULE_DIR_.$this->name.'/css/product.css'); // add custom css style
}

public function hookDisplayProductPriceBlock($params)
{
	$product = new Product((int)Tools::getValue('id_product');

	$priceWithTax = Tools::displayPrice($product->getPrice(true, null, 6, null, false, false), $this->context->currency);
	$priceWithoutTax = Tools::displayPrice($product->getPrice(false, null, 6, null, false, false), $this->context->currency); 

	if ($params['type'] == 'before_price'){
		return '<p class="price-with-tax">'.$priceWithTax.'</p>';
	}

	if ($params['type'] == 'after_price'){
		return '<p class="price-without-tax">'.$priceWithoutTax.'</p>';
	}
} 

It's just an outline of how to do it.

Link to comment
Share on other sites

But it's so simple !!!

./themes/classic/templates/checkout/_partials/cart-detailed-product-line.tpl

<div class="col-md-6 col-xs-2 price">
            <span class="product-price">
              <strong>
                {if isset($product.is_gift) && $product.is_gift}
                  <span class="gift">{l s='Gift' d='Shop.Theme.Checkout'}</span>
                {else}
                  {$product.total}    yyy
                {/if}
              </strong>
            </span>
          </div>
<div class="current-price">
        <span class="price">{$product.price} xxx</span>
        {if $product.unit_price_full}
          <div class="unit-price-cart">{$product.unit_price_full}</div>
        {/if}
      </div>

obrazek.png.6c8f3a588608099a3e60036d8e2ef9bf.png

change to xxx:

<div class="current-price">
        <span class="price">{$product.price}</span>

        {hook h='displayProductPriceBlock' product=$product type="after_price"}
        {if $product.unit_price_full}
          <div class="unit-price-cart">{$product.unit_price_full}</div>
        {/if}
      </div>

and

change to yyy:

<div class="col-md-6 col-xs-2 price">
            <span class="product-price">
              <strong>
                {if isset($product.is_gift) && $product.is_gift}
                  <span class="gift">{l s='Gift' d='Shop.Theme.Checkout'}</span>
                {else}
                  {$product.total}
                {/if}
              </strong>
            </span>
			{hook h='displayProductPriceBlock' product=$product type="after_price"}
          </div>
        </div>

 

Link to comment
Share on other sites

You can use an existing hook anywhere.
If it's not in the tpl template, I'll ask Colombo and rediscover America, or read the documentation and insert our own hook.
I've already given instructions on how to insert your own hook into the tpl template.
There is a search bar on the forum.
I recommend using !!!

Link to comment
Share on other sites

  • 2 months later...

If you need price without tax in a cart overview (./themes/classic/templates/checkout/_partials/cart-detailed-product-line.tpl)

{Tools::displayPrice($product.price_without_reduction_without_tax)}

or

{Tools::displayPrice($product.price_with_reduction_without_tax)}

PS 1.7.6.9

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 1 year later...
On 9/29/2020 at 6:19 PM, taniacr said:

I managed to create a tiny module where I show both prices (with and without tax) using:

$priceWithTax = Tools::displayPrice($product->getPrice(true, null, 6, null, false, false), $this->context->currency);
$priceWithoutTax = Tools::displayPrice($product->getPrice(false, null, 6, null, false, false), $this->context->currency);

Just need to find out how to display the discounted prices with and without tax

I know where I want to show $priceWithTax, but I don't know where to declare it first. If I do it in the same TPL the page breaks.
Can you help me?

image.png.ab4ab6134c6a419eff8b018182c2c733.png

Edited by Roger SA (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...