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

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.

| improve this answer | |
  • file path please? – Bojjaiah Jan 5 '17 at 12:08
  • @magentotwo app/design/frontend/{Vendor}/{themename}/Magento_Checkout/templates/cart/minicart.phtml – Rakesh Jesadiya Jan 5 '17 at 12:32
  • @RakeshJesadiya, got this error.Uncaught TypeError: Unable to process binding "css: function(){return { empty:cart().summary_count == 0} } – jafar pinjar Jul 11 '19 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 – jafar pinjar Jul 16 '19 at 7:00
  • Thank you that fixed it.. don't forget to rebuild static files and clear magento cache after making those above changes. – Jonathan Marzullo Feb 5 at 18:52
2

Finally i got it by using below code,

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

We can solve this issue by removing the following condition:

if: cart().summary_count
| improve this answer | |
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>
| improve this answer | |

Your Answer

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