Question

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>
Was it helpful?

Solution 2

Finally i got it by using below code,

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

OTHER TIPS

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.

We can solve this issue by removing the following condition:

if: cart().summary_count

This fix is working on Magento 2.3.4

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

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top