wp-e-commerce / WP-e-Commerce

WP eCommerce - The most popular independent eCommerce platform for WordPress
https://wpecommerce.org
GNU General Public License v2.0
216 stars 216 forks source link

Cart sometimes has the wrong product quantity #2342

Open jbeales opened 7 years ago

jbeales commented 7 years ago

Sometimes when I add products to my cart the quantities are wrong. Here's a video of the problem in action.

I've seen this in two different sites - the one in the video, which is very stripped-down, (just up-to-date versions of WP, WPeC, the Twenty Fourteen theme, and a 1-line plugin to enable Theme Engine v2), and another that I have under development, (slightly more complicated, but still pretty stripped-down).

Sometimes the problem goes away, and sometimes it comes back, and I don't know why. I've seen it both when logged-in as the admin, and when completely logged-out like in the video. I haven't tried logged-in as a non-admin.

As a side note: In the video, when something's added to the cart, I can't get the right-hand part of the pop-up cart summary to appear. Is there a missing setting somewhere?

mihaijoldis commented 7 years ago

Was able to replicate by just going to the /store/ and adding the same product to cart 5 times in a row. The notification shows 5 in the cart but on the /store/cart/ there is only 1

what i noticed is that when you first add to cart there is 1 ajax request that adds to cart. If you then hit the same add to cart for the same product there's no other requests firing. so basically it "knows" only 1 item has been added to the cart. It needs to fire the ajax request again.

Not even if i reload the page and try to add the same product to cart it won't fire the ajax request.

Edit: Looks like as long as product X is in cart you can't add it again ?

jbeales commented 7 years ago

There's a second possible way to fix this, different from the approach in #2343. The model fires a 'change' event when the quantity, (or really anything), is updated, so it would be possible to have an event handler on the 'change' event that calls the sync method. It's just beyond my (current) Backbone understanding, and I don't know if it would end up sending a lot of unnecessary AJAX requests.

JustinSainton commented 7 years ago

Assigning to @jtsternberg for review on our next WPEC sprint - thanks for the issue and PR @jbeales!