0

I am trying to modify tier_price.phtml to add a custom product attribute called "unit". No idea how to do that ... can anyone point me to the right direction?

Current code:

<script type="text/x-magento-template" id="tier-prices-template">

    <ul class="prices-tier items">
        <% var basePriceTemplate = '<span>'
        + '<span>&nbsp;%1</span>'
        + '</span>'
        %>

        <% _.each(tierPrices, function(item, key) { %>
        <% var itemBasePrice = item.hasOwnProperty('basePrice')
        ? basePriceTemplate.replace('%1', priceUtils.formatPrice(item['basePrice'], currencyFormat))
        : ''
        %>

        <% var priceStr = '<span>' + priceUtils.formatPrice(item.price, currencyFormat) + '</span>'
                    + '</span>' + itemBasePrice + '</span>';
        %>
        <li class="item">
            <%= '<?= $block->escapeHtml(__('Buy %1 for %2 each and', '%1', '%2')) ?>'
            .replace('%1', '<span>' + item.qty + '</span>')
            .replace('%2', priceStr)
            %>
            <strong class="benefit">
                <?= $block->escapeHtml(__('start saving')) ?><span class="percent tier-<%= key %>">&nbsp;<%= item.percentage %></span>%
            </strong>
        </li>
        <% }); %>
    </ul>
    
</script>

<div data-role="tier-price-block"></div>

Thanks :)!

1 Answer 1

1

Please try this code

<li class="item">
            <%= '<?= $block->escapeHtml(__('Buy %1 for %2 each and', '%1', '%2')) ?>'
            .replace('%1', item.qty)
            .replace('%2', priceStr)
            %> <span class="unit">Unit: <%= item.unit %></span>
            <strong class="benefit">
                <?= $block->escapeHtml(__('save')) ?><span
                    class="percent tier-<%= key %>">&nbsp;<%= item.percentage %></span>%
           </strong>
</li>
2
  • I solved it another way now (by overriding TierPriceBox.php) and can not test any longer ... but thanks for your post! Commented Jun 28 at 8:28
  • Thank you for letting me know! I'm glad to hear that you were able to solve it Commented Jun 28 at 8:45

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.