Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the quantity error in the cart only if variant didn't change #3476

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mironov
Copy link

@mironov mironov commented May 15, 2024

PR Summary:

Show the quantity error in the cart only if variant didn't change

Why are these changes introduced?

Fixes #2935
Fixes #3340

What approach did you take?

When changing the item quantity in the cart, the code should not assume that the item will stay in the same position or stay at all. With cart transform functions, the cart content may change significantly.

To solve this issue, the updateQuantity code is changed to find the line by variant ID instead of line position.

Other considerations

n/a

Decision log

n/a

Visual impact on existing themes

Merchants won't see the incorrect message on the cart page.

Testing steps/scenarios

  • Test that quantity message is shown when variant doesn't change
  • Test that quantity message is not shown when variant does change, e.g., with a cart transform function

Demo links

Before fix

before_fix.mp4

After fix

after_fix.mp4

Checklist

@aviita
Copy link

aviita commented Jun 6, 2024

Did you test if you have multiple instances of the same variant in the cart (e.g. multiple bundles with same variant id) or multiple bundled item cart lines that the correct item is always updated with your logic?

I see that at least in our case, when we are sharing same bundle container product as the variant to bundle on, we might have multiple instances with same variant id on different cart lines and in that case you might or might not find the correct line with variant based search (if the whole cart is being processed by that cart update function).

@mironov
Copy link
Author

mironov commented Jun 8, 2024

@aviita Thank you for raising this issue. I hadn't considered this scenario.

I've made a change that should resolve the issue. However, there may still be some edge cases that still need to be accounted for.

The PR tackles the common issue when a line in the cart changes. The cart shouldn't show quantity errors if the variant has changed on a line.

@aviita
Copy link

aviita commented Jun 10, 2024

@aviita Thank you for raising this issue. I hadn't considered this scenario.

I've made a change that should resolve the issue. However, there may still be some edge cases that still need to be accounted for.

The PR tackles the common issue when a line in the cart changes. The cart shouldn't show quantity errors if the variant has changed on a line.

Thanks, that was fast!

I did check the updated fix. It seems good now on this regard.

I saw in your video regarding the fixed state that you now need to click "+" button twice to get the count updated?

Could not figure out what could be the issue just by reading the code though. Is the line not being re-rendered or something like that?

@aviita
Copy link

aviita commented Jun 10, 2024

@aviita Thank you for raising this issue. I hadn't considered this scenario.
I've made a change that should resolve the issue. However, there may still be some edge cases that still need to be accounted for.
The PR tackles the common issue when a line in the cart changes. The cart shouldn't show quantity errors if the variant has changed on a line.

Thanks, that was fast!

I did check the updated fix. It seems good now on this regard.

I saw in your video regarding the fixed state that you now need to click "+" button twice to get the count updated?

Could not figure out what could be the issue just by reading the code though. Is the line not being re-rendered or something like that?

What I would also like verified still is that the count of Bundle and the line items under it do not fall out of sync if you need to press the "+" button twice (if not fixing that in this PR already). Otherwise this definitely should improve the situation as the count can be updated although it does not fully work.

@aviita
Copy link

aviita commented Jun 10, 2024

And I must add that I do not have rights to approve your PR so, we will still need to get hold of someone to do that, but hope my comments and your (@mironov) additional commits help to get this prioritized as it is a nasty bug as the bundle item and the nested items counts get out of sync currently and there is this unnecessary error message shown.

@aviita
Copy link

aviita commented Jun 10, 2024

@mironov, Based on Contributing guide, you should add @Shopify/themes-front-end-developers as reviewer.

@mironov
Copy link
Author

mironov commented Jun 10, 2024

@aviita Thank you for checking the updated version!

Regarding your observations regarding the "+" button, I want to clarify that it is not necessary to click it twice. In the second demo video, the situation you noticed occurs when a product is converted to a BOGO bundle as its quantity is increased, followed by an increase in the quantity of the bundle itself.

Unfortunately, it seems I am unable to add anyone as reviewer for this PR because there is no link available for that action.

@jayportimo
Copy link

I tested this in our environment and the warning does indeed go away. When clicking '+', total price and bundle content change, but the quantity number does not go up. The cart also showcases an error message under checkout-button.

bundling_video.mp4

@mironov
Copy link
Author

mironov commented Jun 11, 2024

@jayportimo Thank you for testing this out.

Could you please provide more details on how to reproduce the issue you’re experiencing? Specifically, do you have sufficient inventory for the components of the bundle?

In my tests, this PR consistently works as expected. When there is enough inventory, the quantity increases without any errors. Conversely, if the inventory is insufficient, the quantity does not increase, and an error message is displayed.

@jayportimo
Copy link

@mironov

The components within the bundle have sufficient inventory.
Now this got me thinking probably the issue is with the bundle container product/variant then.
Thank you for answering my comment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants