Cart counter is not updating - debut theme

Hi!

My site is: www.bellavirtuorganics.com. I have updated my site so that when on a collection page the user clicks add to cart it stays on the collection page. However, after making this change my cart counter does not work. I believe I need to add this code:

 success: function(data){
        var current_count = data.item_count;
        $('.header-cart-count').html(current_count);
    }

But I’m not sure where to put it? It seems like if I add the code, it prevents my ‘stay on collections page’ function from working. Here’s my Ajaxify-cart.liquid code, thanks for your help!

{% comment %}
If you want to animate your feedback message.
{% endcomment %}

{% comment %}
{{ ‘//cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.0/animate.min.css’ | stylesheet_tag }}
{% endcomment %}

{{ ‘//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css’ | stylesheet_tag }}

.ajaxified-cart-feedback { display: block; line-height: 36px; font-size: 90%; vertical-align: middle; } .ajaxified-cart-feedback.success { color: #3D9970; } .ajaxified-cart-feedback.error { color: #FF4136; } .ajaxified-cart-feedback a { border-bottom: 1px solid; }

@Campionk

Sorry for facing this issue, it’s my pleasure to help us.

product page working fine but the collection page doesn’t work it can be done custom code

Yes, as specified in my original message, the issue is with the add to cart
button on the collection page.

Is this the right code to add?

success: function(data){
var current_count = data.item_count;
$(‘.header-cart-count’).html(current_count);
}

This code updates the counter, but then it opens the cart page when I want
to stay in the collections page. Thanks for your help.

@Campionk

Yes may changes custom scrip to ajax cart

So what is the solution?

Thank you.

@Campionk

it’s depend on back end customization code

Is there any chance you found a way of doing this?

Stuck on this myself pal!

Unfortunately not! If I ever find a solution I’ll let you know!

Finally found a solution to the header cart icon not updating after adding to cart on the debut theme.

in the following section of ajaxify-cart.liquid

if (_config.cartCountSelector && $(_config.cartCountSelector).length()) {
                var value = $(_config.cartCountSelector).html() || '0';
                $(_config.cartCountSelector).html(value.replace(/[0-9]+/,cart.item_count)).removeClass('hidden-count');
              }
              if (_config.cartTotalSelector && $(_config.cartTotalSelector).length()) {

remove the following

&& $(_config.cartCountSelector).length()

so that section now reads

if (_config.cartCountSelector) {
                var value = $(_config.cartCountSelector).html() || '0';
                $(_config.cartCountSelector).html(value.replace(/[0-9]+/,cart.item_count)).removeClass('hidden-count');
              }
              if (_config.cartTotalSelector) {

looks like there is an error with the .length function.

@edit4ever You are an absolute legend!!! This has stumped me forever. If you lived in Denver I’d buy you a beer. Cheers to you!

Funny - I used to live in Denver! But you just can’t beat the San Diego weather!!

BTW - one other error I was getting was about the Uncaught TypeError: Shopify.formatMoney is not a function

I got rid of this by adding the following line to the top of my ajaxify-cart.liquid file

{{ 'api.jquery.js' | shopify_asset_url | script_tag }}

Not sure if everyone needs this - but it removed the error for me.

Hi, I have the same issue on my debut theme that my cart does not count. I have carefully read this solution but in my ajaxify liquid file this code does not axactly the same way you have written.

Here I will copy and paste my code. Where should I change could you please describe me again?

Sorry for asking the same question again. I would appreciate if you could review.

{% comment %}
If you want to animate your feedback message.
{% endcomment %}

{% comment %}
{{ ‘//cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.0/animate.min.css’ | stylesheet_tag }}
{% endcomment %}

{{ ‘//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css’ | stylesheet_tag }}

.ajaxified-cart-feedback { display: block; line-height: 36px; font-size: 90%; vertical-align: middle; } .ajaxified-cart-feedback.success { color: #3D9970; } .ajaxified-cart-feedback.error { color: #FF4136; } .ajaxified-cart-feedback a { border-bottom: 1px solid; }

My ajaxify liquid file does not have (_config.cartCountSelector) length But it has size

@edit4ever

Try changing this line:

if (_config.cartCountSelector && $(_config.cartCountSelector).size()) {

to this:

if (_config.cartCountSelector {

Hi, Thank you for advising and quick reply. Unfortunately it did not work

Is the cart counter showing but not changing the number or is it hidden?

What you need to do is go through the function that updates the cart
counter and search for the .length attribute - it’s deprecated and likely
what the issue is. Just remove it section by section, compile and keep
going till it works.

Sorry I can’t help anymore but I’m currently not in work and don’t have
access to my code to pinpoint where the issue is.