Shopify / dawn

Shopify's first source available reference theme, with Online Store 2.0 features and performance built-in.
Other
2.54k stars 3.43k forks source link

🔥 Ajax Cart Quantity Bug #2994

Open openxthinking opened 1 year ago

openxthinking commented 1 year ago

Describe the current behavior

When attempting to add a quantity of products larger than what's available, the theme:

If I then try to reduce the product quantity, the theme throws another error that the specified number of products is already in the cart. However, the "drawer" and "cart bubble" only reflect the correct quantity after a page refresh.

Describe the expected behavior

When sending an Ajax request that results in an error, the theme should not add any products to the cart. Additionally, the "drawer" and "cart bubble" should always reflect the correct quantity of products in the cart without requiring a page refresh.

Version information (Dawn, browsers and operating systems)

Possible solution

The issue seems to originate from the cart API. A potential solution would be to ensure that no products are added to the cart in such scenarios and that the UI elements ("drawer" and "cart bubble") are updated appropriately.

Additional context/screenshots

I've observed this behavior not only in the Dawn theme but also in other themes on the Shopify theme store, pointing towards a more generalized issue with cart API.

https://github.com/Shopify/dawn/assets/70332672/f70a9880-d84d-431d-b08a-477e735563b5

EvgeniyMukhamedjanov commented 1 year ago

I can replicate as well! Left a question in the community. https://community.shopify.com/c/technical-q-a/cart-api-add-js-wrong-behavior/td-p/2227468

EvgeniyMukhamedjanov commented 1 year ago

The same thing is happening with the "change.js" endpoint! If you set the new quantity to be higher than in stock, it will return an error but it will actually add all available quantity to the cart!

bakura10 commented 10 months ago

We are impacted by this as well. The documentation confirms that the expected behavior should not add any product.

Actually, I realized that the behavior is even inconsistent across stores. We have tested some stores where it behaves as instructed in the doc (no product are added in case of error), while some add all the available quantity.

@ludoboludo is it possible to escalate this issue?

ludoboludo commented 10 months ago

Thanks for the flag. Ill track down where the progress on this is 👍 And/or at least make sure there is awareness of the fact that it's still an issue that is impacting negatively merchants and their customers.

EvgeniyMukhamedjanov commented 10 months ago

Hi @ludoboludo Is there any other repo or issue tracker where we can post API related issues? We've found another critical issue in the Shopify Cart API and I'm not where how to reach out Shopify devs. The /cart/update.js returns a wrong item_count value for shopify bundle products. Just described it in linkedin with a screenshot: https://www.linkedin.com/posts/evgeniy-mukhamedjanov_shopify-activity-7150400262665404416-qtsU

ludoboludo commented 10 months ago

There isn't at the moment 🤔 I've relayed the information to the team in question. I'm not sure what's on their current plate and where that will sit in terms of priority though. Anything cart related is pretty sensitive though.

NeevusPeevus commented 2 months ago

Hello! I've encountered this problem while working with a third-party theme, and I've also replicated it using the Dawn theme from the store. Given that this store offers very affordable items, it's not uncommon for customers to enter a quantity that exceeds the available stock, so this has become a significant pain point for the merchant.

Int: https://app.shopify.com/services/internal/shops/74639049002 ZD: https://shopify.zendesk.com/agent/tickets/50730481

zainalidst commented 1 month ago

Hi,

I am working on store development and using the dawn theme give me same behaviour.

Cart drawer section not load when /cart/add.js response status is 422. Theme developer not handle this bug and I am very strange that why dawn is not remove this bug in very release.

ludoboludo commented 1 month ago

So the documentation has been updated to reflect that the maximum quantity possible will be added to the cart while erroring. We would now need to tweak our handling of that error to clearly show the user what happened. Link to the docs

msev commented 1 month ago

Hi @ludoboludo,

It doesn't make sense that an add to cart can be done, but that the API return is an error. Adding to cart should not happen in this case.

If you think it makes more sense to add to cart, then the API return should be a success and not an error.