0

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?

5
  • What version of Magento are you on?
    – Haim
    Nov 5, 2020 at 3:09
  • Magento shows that by default with shoppingcart icon. Isn't it? Nov 5, 2020 at 4:39
  • Magento 2.4. And I'm using a custom header without the use of Magento's cart implementation. Nov 5, 2020 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, 2020 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. Nov 7, 2020 at 17:44

0

Your Answer

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