Developer forum

Forum » Swift » Mini cart counter only updated with last added item

Mini cart counter only updated with last added item

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

When you add products to the cart from a product list, the counter on the mini cart only shows the count of the most recently added item. Consider a product list with Add to cart below each product:

- When I click Add to cart for the first product, the counter changes to 1. (Correct)

- When I then click the second product, the counter changes to 1 again (not correct, should be 2)

- When I then click the third product, the counter changes to 12 (not correct, should be 14)

- When I then do a full page refresh, the counter displays 14 (correct)

It looks like it only takes the current added quantity into account, now what's already in the cart. 

Imar

 

 

 


Replies

 
Cristina Santos
Reply
This post has been marked as an answer

Hello Imar,

We show a notification before adding products to a custom mini cart. 

Two options buttons: View cart button, and Continue shopping button.

Only if we reloaded the page, or if we redirect to other page,  the counter where correct. 

Our solution was extending the event listener.

<button type="button" class="btn btn-secondary btn-seguir btn-sm js-add-to-cart-button" onclick="swift.Cart.Update(event); this.addEventListener('updated.swift.cart', Continueshopping(event))">Continue shopping</button>

<button type="button" class="btn btn-primary btn-sm js-add-to-cart-button" onclick="swift.Cart.Update(event); this.addEventListener('updated.swift.cart', Viewcart(event))">View cart</button>

<script>
    function Continueshopping(event) {
        var tiempo = setTimeout(function () {
            location.assign("/products");  
        }, 220);
    };
    function Viewcart(event) {
        var tiempo = setTimeout(function () {
            location.assign("/cart");  
        }, 220);
    };  
</script>

Best regards,

Cristina

Votes for this answer: 1

 

You must be logged in to post in the forum