0

I have a weird bug.

Every time I add a product to my cart it shows as if it were loading.

enter image description here

However, it adds the product to the cart, if I switch to another page or reload the loading disappears and shows the amount in the cart. Do you know what could it be?

This problem began when I moved the cart to top links.

  • Could you check the magento log and browser console? – Khoa TruongDinh Aug 8 at 2:46
  • There are no errors related to this case in my logs – Oscar Vazquez Aug 8 at 14:08
1

I once got that problem when tried to overwrite catalog-add-to-cart.js. This file is located in vendor\magento\module-catalog\view\frontend\web\js.

At line 95 of that file: $(self.options.minicartSelector).trigger('contentLoading'); this will execute whenever Add to cart button is clicked.

From line 153 to line 156: if (res.minicart) { $(self.options.minicartSelector).replaceWith(res.minicart); $(self.options.minicartSelector).trigger('contentUpdated'); } this block of code must be excuted to make the minicart status become normal. I'm using magento 2.3.2 CE. Hope that may help you.

  • thank you, but what should I do in that file? – Oscar Vazquez Aug 9 at 17:28
  • In my situation, I tried to override this file in my module, and made the function return before the minicart can trigger the 'contentUpdated' event. So if you also try to override this file like I did, take a look at this file in your module. – Hieu Duong Aug 10 at 1:21
  • Open your browser's developer tool (press F12 in many browsers), go to network tab and try to add a product to cart. You will see something like ?sections=cart%2Cmessages&force_new_section_timestamp=true&_=1565400355595. This is update cart request which contain updated minicart's html in server's response. – Hieu Duong Aug 10 at 1:29
  • hello I think it works now, I moved $(self.options.minicartSelector).trigger('contentLoading'); function before $(self.options.minicartSelector).replaceWith(res.minicart); and it seems to work. – Oscar Vazquez Aug 12 at 15:03

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.