vuestorefront / vue-storefront-1

The open-source frontend for any eCommerce. Built with a PWA and headless approach, using a modern JS stack. We have custom integrations with Magento, commercetools, Shopware and Shopify and total coverage is just a matter of time. The API approach also allows you to merge VSF with any third-party tool like CMS, payment gateways or analytics. Newest updates: https://blog.vuestorefront.io. Always Open Source, MIT license.
https://www.vuestorefront.io
MIT License
19 stars 13 forks source link

[Bug]: Cart quantity update fails even though updated quantity is available #502

Open tobyj opened 3 years ago

tobyj commented 3 years ago

Describe the Bug

Cart quantity update appears to try and add the product quantity again as opposed to updating quantity of existing product. This means if there are scenarios where you cannot update the item quantity even though the desired quantity is valid.

This has been reproduced on vsf demo site.

Current behavior

Can ONLY increase/decrease currentQuantity of a product to requestedQuantity if the sum of currentQuantity and requestedQuantity is less than or equal to totalAvailableQty.

If (currentQuantity + requestedQuantity) <= totalAvailableQty - Quantity update will work. ✔️ If (currentQuantity + requestedQuantity) > totalAvailableQty - Quantity update will fail. ❌

e.g. for item X: totalAvailableQty = 50 (the max that can be purchased) currentQuantity = 40 (the quantity of item X I currently have in the cart) requestedQuantity = 45 (the quantity of item X that I actually want)

(40 + 45) > 50 - the quantity update will fail ❌

... the only way to get to qty 45 would be to first reduce qty to 5 or less (45+5 <= 50), then change quantity back to 45

This bug also means you can't decrease the quantity of a product in some situations. e.g. for item X above again - If I had 40 in cart, and wanted to decrease to 39 it will fail (because 40+39 > 50).

Expected behavior

Cart quantity updates from, for example, 40 to 45 items (where there are 50 in stock) should work but fails.

Steps to reproduce

Visit https://demo.vuestorefront.io/arcadio-gym-short.html?childSku=MSH11-32-Black

image

Note: At time of writing I could add a maximum quantity of 74. Assuming the max available items is 74:

  1. Add quantity 74 to cart. This works, but you won't be able to adjust quantity up or down again. image image

  2. Try adjusting quantity down to 73. It fails. and reverts to 74. image

  3. Clear the cart so we can continue testing.

  4. Add quantity of 50 to cart. image

  5. Open cart and try adjusting quantity to 51. It will fail with error The requested qty is not available. (50+51 <= 74) and revert to 50. You should be able to update to 51 as we know there are 74 in stock image

  6. Try adjusting quantity to 25 - this too fails (50+25 > 74) You should be able to decrease quantity from 50 to 25

  7. Try adjusting quantity to 24 - this works because its under the total available quantity: (50+24 <= 74). Quantity is updated to 24. image

  8. Try adjusting quantity to 74 - this fails (24+74 > 74). Quantity is not updated

What version of Vue Storefront are you using?

1.12.2

What version of Node.js are you using?

14.17.6

What browser (and version) are you using?

Chrome

What operating system (and version) are you using?

MacOS

Relevant log output

No response

Able to fix / change the documentation?

Code of Conduct