0

Magento 2.4.6

Getting this error in this piece of code ... I have been looking at it for a while now but can not find the problem ... can you help me out?

<ul
class="prices-tier items">
<% var basePriceTemplate = ' <span
class="price-wrapper price-excluding-tax"'
+ 'data-label="Exkl. Steuern">'
+ '<span
class="price">&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
class="price-container price-tier_price">'
+ '<span
data-price-amount="' + priceUtils.formatPrice(item.price, currencyFormat) + '"'
+ ' data-price-type=""' + ' class="price-wrapper price-including-tax">'
+ '<span
class="price">' + priceUtils.formatPrice(item.price, currencyFormat) + '</span>'
+ '</span>' + itemBasePrice + '</span>';
%><li
class="item">
<%= 'Kaufen Sie %1 für jeweils %2 und'
.replace('%1', item.qty)
.replace('%2', priceStr)
%>
<strong
class="benefit">
sparen Sie<span
class="percent tier-<%= key %>">&nbsp;<%= item.percentage %></span>%
</strong></li>
<% }); %></ul>

Thats how it gets printed to the console, I left it this way without formatting.

This code is contained in this.options.tierPriceTemplate in the following code in configurable.js.

$(this.options.tierPriceBlockSelector).html(
       mageTemplate(this.options.tierPriceTemplate, {
                            'tierPrices': tierPrices,
                            '$t': $t,
                            'currencyFormat':this.options.spConfig.currencyFormat,
                            'priceUtils': priceUtils
                        })
                    ).show();

Does not happen for all products, but for some.

The content of tier_price.phtml looks like this:

<script type="text/x-magento-template" id="tier-prices-template">
    <ul class="prices-tier items">
        <% var basePriceTemplate = ' <span class="price-wrapper price-excluding-tax"'
        + 'data-label="<?= $block->escapeHtml(__('Excl. Tax')) ?>">'
        + '<span class="price">&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 class="price-container price-tier_price">'
                    + '<span data-price-amount="' + priceUtils.formatPrice(item.price, currencyFormat) + '"'
                    + ' data-price-type=""' + ' class="price-wrapper price-including-tax">'
                    + '<span class="price">' + priceUtils.formatPrice(item.price, currencyFormat) + '</span>'
                    + '</span>' + itemBasePrice + '</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(__('start saving')) ?><span
                    class="percent tier-<%= key %>">&nbsp;<%= item.percentage %></span>%
            </strong>
        </li>
        <% }); %>
    </ul>
</script>
<div data-role="tier-price-block"></div>

When I debug, it looks like this: enter image description here, there are lots of \n ... could that be the reason?

Thanks for any idea!

2
  • 1
    I may be wrong here, but try putting + '<span class="price">&nbsp;%1</span>' on the same line. (lines 6 and 7 in your code). I think this should be found in the tier_price.phtml template
    – Marius
    Feb 20 at 8:50
  • Thanks, in the template it is on one line, I posted the phtml content above. I tried using the original from the theme, same problem. Feb 20 at 9:10

0

Your Answer

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