EvgeniyMukhamedjanov / liquid-ajax-cart

Build a Shopify Ajax-cart without JavaScript coding
https://liquid-ajax-cart.js.org
194 stars 22 forks source link

Sometimes getting double add to cart requests #28

Closed SeanMythen closed 2 years ago

SeanMythen commented 2 years ago

Hello! First of all, really awesome project! I've almost got my cart finished thanks to you!

One thing I'm noticing, and I'm not sure if it is a Shopify thing, is sometimes randomly when the add to cart button is added, it will double the quantity that I want to add to the cart and send that to the cart.

I'm using the dawn theme. Have you seen something like this before? I've seen these posts here and here, and I'm unsure if it is related, but I'm having trouble pinpointing where the issue is coming from.

Here is a screenshot

Thank you!

Update: I actually found one of the ways the issue occurs, when coming in from out of focus, and immediately clicking the add to cart button as your first click, I was still allowing the add to cart button to be clicked even though I shouldn't have been allowing that because a request was already in progress.

Still though, I randomly get the issue when I maintain focus and continuously press the add to cart button. It could be that I'm just edge case testing and clicking too quickly, where are normal user would never do that.

EvgeniyMukhamedjanov commented 2 years ago

Hey @SeanMythen! As far as I know Dawn has its own Ajax "add to cart" functionality. For example, if you remove the Liquid Ajax Cart, you will still be able to add a product to cart without page reloading. And when you set Liquid Ajax Cart on top of it, you get two different scripts that are responsible for adding a product to the cart. Maybe this is the reason why it happens. So my advice is to choose one of the ways:

  1. remove liquid ajax cart and write your own scripts to extend dawn functionality
  2. find the Dawn ajax script and remove it Btw, can you share a preview link, I'll check if this is the problem with the Dawn script.
SeanMythen commented 2 years ago

Thanks @EvgeniyMukhamedjanov!

After a bit more tinkering and really removed all the other cart logic and building very basic add to cart product forms for the product pages, there isn't any issues :)