4

I want to check inside my /app/design/frontend/theme/theme/Magento_Checkout/web/template/minicart/subtotal/totals.html file if the subtotal is larger than 29.95.

I want to display some additional text if subtotal is larger or smaller than 29.95. The problem is that it is loaded inside a .html file so I cannot use php for this.

How can I achieve this?

2

You can have following knockout code in html file to achieve your desired result.

<!-- ko if: cart().subtotalAmount < 29.95 -->
    <span>custom message if subtotal is less then 29.95</span>
<!-- /ko -->

<!-- ko if: cart().subtotalAmount > 29.95 -->
    <span>custom message if subtotal is greater then 29.95</span>
<!-- /ko -->

Hope this helps.

| improve this answer | |
  • Thanks! I tried it, but it does display the message both. So it does not check if the subtotal is greater than 29.95. – JGeer Feb 17 '19 at 20:17
  • This is something related to static content deploy so after making the change you need to remove var/view_preprocessor/* and pub/static/frontend/* then php bin/magento setup:static-content:deploy -f and finally php bin/magento cache:flush ... To make sure weather ur changes reflected or not try appending some custom text without any conditions ... – Yash Shah Feb 17 '19 at 20:21
  • Thanks! I did indeed deploy the static content, but it seems that the if element does not work. I added the code into /app/design/frontend/theme/theme/Magento_Checkout/web/template/minicartsubtotal.html – JGeer Feb 17 '19 at 20:42
  • Strange !!! I tested the code and was working for me ... Anyways good luck ... – Yash Shah Feb 17 '19 at 20:50
  • It indeed works fine, it was the static folder that did not flush well. Many thanks. But the only thing I face now, is that the best way to implement this, would be to create a new template file, instead of adding it to the /app/design/frontend/theme/theme/Magento_Checkout/web/template/minicart/subtotal.html Is there a easy way to add a new file and display this above the subtotal.html file? – JGeer Feb 17 '19 at 21:07
0

Yash Shah's answer worked for me, but only after I found the right place for the code. I added it inside an existing 'ko' element (I'm not familiar with Knockout).

I edited my subtotal.html from this...

<div class="subtotal">
    <span class="label">
        <!-- ko i18n: 'Cart Subtotal' --><!-- /ko -->
    </span>

    <!-- ko foreach: elems -->
        <!-- ko template: getTemplate() --><!-- /ko -->
    <!-- /ko -->
</div>

...to this...

<div class="subtotal">
    <span class="label">
        <!-- ko i18n: 'Cart Subtotal' --><!-- /ko -->
    </span>

    <!-- ko foreach: elems -->
        <!-- ko template: getTemplate() --><!-- /ko -->

        <!-- ko if: cart().subtotalAmount < 50.00 -->
            <span>Message for orders under £50</span>
        <!-- /ko -->

        <!-- ko if: cart().subtotalAmount > 50.00 -->
            <span>Message for orders over £50</span>
        <!-- /ko -->

    <!-- /ko -->
</div>
| improve this answer | |
0

Something like this would work in Magento 2.

<!-- ko if: getCartParam('summary_count') > 1 || getCartParam('summary_count') == 0 -->
<span>items</span>
<!-- /ko -->
<!-- ko if: getCartParam('summary_count') == 1 -->
<span>item</span>
<!-- /ko -->
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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