4

When I open the page in Private Browsing / Quote no initialize at that time it show the empty value in minicart count, but it should show 0.

If I add product(s) in cart then I can see the number of items in cart. After that I remove all products from the cart then also I can see the 0 in Cart count.

initial page load I cant see the Item counts in minicart. I have used below code,

<span class="counter qty empty" data-bind="css: { empty: cart().summary_count == 0 }, blockLoader: isLoading">
            <span class="counter-number"><!-- ko text: cart().summary_count --><!-- /ko --></span>
        </span>

5 Answers 5

5

Open your root directory and open minicar‌​t.phtml.

The file path is:

app/design/frontend/{Vendor}/{themename}/Magento_Checkout/te‌​mplates/cart/minicar‌​t.phtml

You have to just replace span with below code,

    <span class="counter qty empty"
          data-bind="css: { empty: cart().summary_count == 0 }, blockLoader: isLoading">

        <!-- ko if: cart().summary_count -->
            <span class="counter-number"><!-- ko text: cart().summary_count --><!-- /ko --></span>
        <!-- /ko -->
        <!-- ko ifnot: cart().summary_count -->
            <span class="counter-number">0</span>
        <!-- /ko -->

        <span class="counter-label">
        <!-- ko if: cart().summary_count -->
            <!-- ko text: cart().summary_count --><!-- /ko -->
            <!-- ko i18n: 'items' --><!-- /ko -->
        <!-- /ko -->
        </span>
    </span>

Run command, php bin/magento setup:static-content:deploy remove var folder and check again.

6
  • file path please?
    – Bojjaiah
    Commented Jan 5, 2017 at 12:08
  • @magentotwo app/design/frontend/{Vendor}/{themename}/Magento_Checkout/templates/cart/minicart.phtml Commented Jan 5, 2017 at 12:32
  • @RakeshJesadiya, got this error.Uncaught TypeError: Unable to process binding "css: function(){return { empty:cart().summary_count == 0} } Commented Jul 11, 2019 at 12:56
  • @RakeshJesadiya, Also i have one more issue, suppose there are 2 items in cart, on page loading this shows 0 then once page loaded the correct count is showing Commented Jul 16, 2019 at 7:00
  • Thank you that fixed it.. don't forget to rebuild static files and clear magento cache after making those above changes. Commented Feb 5, 2020 at 18:52
3

Finally i got it by using below code,

<span class="counter-number"><!-- ko text: **cart().summary_count || 0** --><!-- /ko --></span>
4
  • you can also use above code, Its also working fine. Commented Jun 23, 2016 at 10:25
  • @Nagamani file path please?
    – Bojjaiah
    Commented Jan 5, 2017 at 12:08
  • Uncaught SyntaxError: Unable to parse bindings. Bindings value: text: cart().summary_count || 0 Commented Jul 11, 2019 at 12:53
  • This fix doesn't work on Magento 2.3.4. Commented Feb 19, 2020 at 10:13
1

We can solve this issue by removing the following condition:

if: cart().summary_count
1

This fix is working on Magento 2.3.4

<span class="counter-number"><!-- ko text: getCartParam('summary_count') || 0 --><!-- /ko --></span>
0

If you get an error, then you should use

getCartParam('summary_count')

instead

cart().summary_count 

So, in

app/design/frontend/{Vendor}/{themename}/Magento_Checkout/te‌​mplates/cart/minicar‌​t.phtml

replace span with below code

<span class="counter qty empty"
          data-bind="css: { empty: !!getCartParam('summary_count') == false && !isLoading() }, blockLoader: isLoading">
        <!-- ko if: getCartParam('summary_count') -->
            <span class="counter-number"><!-- ko text: getCartParam('summary_count') --><!-- /ko --></span>
        <!-- /ko -->
        <!-- ko ifnot: getCartParam('summary_count') -->
            <span class="counter-number">0</span>
        <!-- /ko -->
        <span class="counter-label">
        <!-- ko if: getCartParam('summary_count') -->
            <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
            <!-- ko i18n: 'items' --><!-- /ko -->
        <!-- /ko -->
        </span>
    </span>

Your Answer

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