3

I want to display the total items count using Knockout, in Magento_Checkout::header/minicart.phtml, e.g. if I have 2 items with the same SKU in the basket then the total items count is 1.

I have tried using data-bind="text: getCartParam('items_count')" but this returns the total quantity (i.e. 2).

I could use <?php echo $this->helper('\Magento\Checkout\Helper\Cart')->getItemsCount(); ?> but I'd like to try and use a Knockout binding instead - is this possible?

1

Go to Admin -> Stores -> Configuration -> Sales -> Checkout -> MyCart -> Display Cart Summary

There you can change the setting.enter image description here

  • What version of Magento 2 are you using? On 2.1.6 there is no Checkout option under Sales. – Ben Crook Jun 23 '17 at 13:56
  • I've attached a screenshot. I'm using 2.1.5 but it is there in 2.1.6 too on my local testing machine. – steros Jun 23 '17 at 21:11
  • Ohh is that under stores > config? You didn't mention that in your answer so I was going to admin > sales not admin > stores > config > sales. – Ben Crook Jun 26 '17 at 8:44
  • 1
    Ah I see. Of course that would be found under configuration. Sorry I'll edit the answer to make it more clear. – steros Jun 26 '17 at 9:01
  • Thanks, unchecking "Use system value" and changing to "Display number of items in cart" worked for me - although I had to edit the basket to get the minicart to show the new totals while developing locally. – user2759013 Jun 26 '17 at 9:38
0

you can use like this in template file

<span class="number"><!-- ko text: cartSidebar().items.length --><!-- /ko --></span>

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.