I've created a custom header that works fine. I replaced Magento's cart, and instead added a shopping basket icon in the header. Like so:

enter image description here

When pressed it redirects to the cart.

What I want to do is add the number if items in the users cart using JavaScript so that when a user pressed "add to cart" it also updates the number next to the bag showing how many items are in the basket.

I followed the suggestion here: Magento 2 Get Cart Quote Total in minicart.phtml

I placed <span data-bind="html: getCartParam('subtotal')"></span> in the HTML but got an error getCartParam is undefined

Any ideas where I'm going wrong?

  • What version of Magento are you on? – Haim Nov 5 '20 at 3:09
  • Magento shows that by default with shoppingcart icon. Isn't it? – Abdul Samad Abbasi Nov 5 '20 at 4:39
  • Magento 2.4. And I'm using a custom header without the use of Magento's cart implementation. – BugHunterUK Nov 5 '20 at 4:51
  • That is a function of the elements js file being called by knockout. Looks like the function isn't available to knockout. Check your headers supporting js files. – Mark Rees Nov 7 '20 at 11:39
  • Thanks Mark. You could be right because I replaced the header the cart js is not being included. I shall check this. – BugHunterUK Nov 7 '20 at 17:44

Your Answer

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

Browse other questions tagged or ask your own question.