-
Notifications
You must be signed in to change notification settings - Fork 29
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
Deduplication in Cart is still very buggy #73
Comments
Can you post a quick script that illustrates the problem? |
Thanks. Not really, b/c we now went back to dedupe client side as a backup, b/c using the library seemed to fail dedupe sometimes and we couldn't figure out why. There is some edge case, but we find out hard to isolate it. I'll do some more debugging and report back. |
OK, was able to replicate. I can send you video if you want. Send me an email. Now I'm certain there is a bug. It seems like the cart dedupes on a get request, but on an initial addItem request, it won't dedupe, unless there are 2 items already in cart of the same id. I guess on the client side you can get the cart before putting it back to solve this issue but then you might as well just dedupe on client side. BTW, we are using NextJsCommerce repo. Also, "updateItem" does dedupe fine. So maybe the problem is just isolated to how the API is handing " addItem". What I would recommend (as I've seen this before with other APIs that had to solve deduping issues), is to add an endpoint, like "addItemDedup" - this will execute the dedupe on the API when it is called for adding an item. So you have 2 endpoints, one which doesn't dedupe and which does. |
Thanks for the details. The API should be de-duping items in all cases regardless of how it's added to the cart. I'll see if we can reproduce this or if it's already been reported. |
You can just go to: https://swell.vercel.store/ - and add the same product to the cart and you will see the API does not dedupe. Granted this repo is running on an old version of the API, but even after we upgraded the API, it still didn't work and was unreliable for dedupe, depending on the situation. |
👀 |
Found the issue! Actually was caused by an edge case around variant options. Will get this fixed shortly. |
Thanks. Can you please update the issue when a fix is pushed? |
@osseonews fix is live now - let me know if you still see any problem with it |
which version? |
The issue and fix was on the backend API side |
@osseonews Following up on this to confirm if you are still experiencing the issue after the fix was deployed. |
No sorry. Our code still dedupes clients side and we haven't updated it yet to check the backend API. Just working on other fixes now. |
First of, what I mean by deduplication is that if you add an item to the cart, where the exact same item is already in the cart, the cart should increment the quantity of that item, instead of adding it a new item to the cart. So let's say you have 5 of product ABC in the cart. If you add 2 more of ABC to the cart, the cart should simply add quantity of 2 to ABC for 7 ABC in cart, instead of adding another item of 2 of ABC, and then ABC is in the cart twice.
Unfortunately, deduplication of a cart in Swell with the API is still very buggy and can't be trusted. I posted about this bug a long time ago and I am dismayed that the API still doesn't have this fixed, and we need to still dedupe at the client level, which slows everything down. Deduplication is a simple concept and should happen at the API level.
I have tested extensively and the API still doesn't dedupe, though I think the claim is that it does. From my testing the dedupe will only occur after there are 2 of the same item in the cart, and/or if there is already something else in the cart. So what happens is that if you have an empty cart and Add 1 of ABC to the cart and then Add another 1 of ABC to the cart, it will not dedupe. Thereafter, if you add 1 of ABC, it will dedupe, though, which item in the cart it adds it to, seems to be totally random. I am not sure what the source of this issue is in the code, but I can state that the above definitely happens (dedupe only occurs after 2 of the same item are in the cart).
Of course, if you just dedupe at the client level, you can eliminate the errors from the API, but this is far from ideal. Please add proper deduplication to the API.
The text was updated successfully, but these errors were encountered: