1

I am having trouble getting price tier breaks for Complex products to show "excluding" VAT only.

I am UK based so need to show prices both inc. and exc. tax in most places. We are running a modified LUMA theme.

Our tax settings are configured as the below screenshot.

What I want to achieve is loading all price tiers without tax as we predominantly deal with trade customers.

For simple products, the prices are loaded in "with and without VAT" on the luma theme. So this has been an easy fix using CSS.

For complex products, though the price that is loaded in is loaded inc VAT only.

What it currently Loads:


MAIN PRICE £20.00 Ex VAT, £24.00 Inc VAT

10 Qty |  £22.00 INC VAT | Saving %
20 Qty |  £21.00 INC VAT | Saving %
30 Qty |  £21.00 INC VAT | Saving %

What I want:


MAIN PRICE £20.00Ex VAT £24.00 Inc VAT
10 Qty |  £18.33 INC VAT | Saving %
20 Qty |  £17.50 INC VAT | Saving %
30 Qty |  £17.50 INC VAT | Saving %

I have a jquery script doing it, but it is very "hacky" and would prefer to load the page with it correct off the bat.

I can see \Magento_ConfigurableProduct\templates\product\price\tier_price.phtml is responsible for loading the data. But I am not sure how to amend what is pushed to the phtml. Any help much appreciated.

tax settings

1 Answer 1

0

Bit of a dirty fix here, but I hope this helps someone in the future.

So after countless hours of googling, it seems this was fixed in 2.4.2 - which is great except for muggins here who has a store running on 2.3x.

I don't even know where to begin when trying to patch my store just for this functionality. I gave it a go, but failed miserably.

Anway here's what I did:

We need to override price-utils so we can intercept the price when it loads into the tiered pricing phtml file.

ThemeDir/requirejs-config.js

var config = {
    'config': {
        'mixins': {
            'Magento_Catalog/js/price-utils': {
                'Magento_Catalog/js/price-utils-override': true
            }
        }
    }
};

ThemeDir/Magento_Catalog/web/js/price-utils-override.js

define([
        'jquery',
        'underscore'
    ],
    function ($, _) {
        'use strict';
        return function (target) {

            target.showExclVat = function formatPrice(amount, percent) {
                //Your custom format price here
                console.log(amount);
                var exclVat = (percent / 100) * amount;
                return amount - exclVat;
            };

            return target;
        };
    });

And finally:

ThemeDir/Magento_ConfigurableProduct/templates/product/price/tier_price.phtml

<script type="text/x-magento-template" id="tier-prices-template">
    <ul class="prices-tier items">
        <% _.each(tierPrices, function(item, key) { %>
        <%  var priceStr = '<span class="price-container price-tier_price">'
                + '<span data-price-amount="' + priceUtils.formatPrice(item.price, currencyFormat) + '"'
                + ' data-price-type=""' + ' class="price-wrapper ">'
                + '<span class="price">' + priceUtils.formatPrice(item.price, currencyFormat) + ' Inc VAT</span> '
                + '<span class="excl-vat-price">(' + priceUtils.formatPrice(priceUtils.showExclVat(item.price, 20), currencyFormat) + ' Excl VAT)</span>'
                + '</span>'
            + '</span>'; %>
        <li class="item">
            <%= '<?= $block->escapeHtml(__('Buy %1 for %2 each and', '%1', '%2')) ?>'
            .replace('%1', item.qty)
            .replace('%2', priceStr) %>
            <strong class="benefit">
                <?= $block->escapeHtml(__('save')) ?><span
                        class="percent tier-<%= key %>">&nbsp;<%= item.percentage %></span>%
            </strong>
        </li>
        <% }); %>
    </ul>
</script>
<div data-role="tier-price-block"></div>

As you can see, I've called my mixin function in the excl-vat-price element. As you can also see here, I've had to forcibly do the 20% (uk VAT) calculation here. Some smarter bods may know how to pull the correct tax rate from the config, but for now, this works (since it's a GB store anyway).

I think it should probably be simple to pull the tax rate from config in this template. If and when I figure that out, i'll update it.

Additional note - I've not tested this on simple products yet (I'm using the configurable products module) I may have to inject this price elsewhere if that doesn't work.

So yeah, there it is. Hope this helps someone else in need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.