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

loadCart not merging correctly #192

Open
amirhemm opened this issue Apr 12, 2021 · 6 comments
Open

loadCart not merging correctly #192

amirhemm opened this issue Apr 12, 2021 · 6 comments

Comments

@amirhemm
Copy link

Hi,

I'm trying to use this method to sync my DB with local storage with the loadCart method and merging to true, but it seems that if you have the same product with the same ID added and you are trying to load it from DB and it already exists in the local storage, the current behavior is that the cartCount and totalPrice update accordingly but the cartItem quantity is not being updated.

Can you verify that this issue exists and if it dose I would suggest one of the these two approaches to fix it:

  1. Update the quantity of the cartItem.
  2. Merge the item with the same ID without updating the cartCount or totalPrice.

Thanks

@dayhaysoos
Copy link
Owner

hey @amirhemm, which version of USC are you using? The beta or the latest release?

@amirhemm
Copy link
Author

I'm using the latest release.

@dayhaysoos
Copy link
Owner

Hey @amirhemm, sorry for taking so long to get back to you. Did you end up finding a workaround by any chance? I am thinking of taking the merge approach you proposed, but there were some other issues/questions that came about regarding loadCart so I didn't get around to it.

@amirhemm
Copy link
Author

amirhemm commented Jul 4, 2021

Hi @dayhaysoos, no worries, I know you got a lot on your plate. Well I did manage to set something up for my use case. In a nutshell, if they user is logged in I merge (not by using the utility function, I made my own helper function) their DB cart with local storage cart. Everything works fine if user adds a new item to the cart. But once a user adds an item which is already added before to the DB cart, I set the quantity of the remote cart as the source of truth. I don't add the quantities. I just overwrite the whole remote item with the local item. I hope that help. Let me know know if you have a question. I also have a test site up. Let me know if you are interested to check it out.

@dayhaysoos
Copy link
Owner

@amirhemm I would love to see it! I would definitely like some direction on how to implement this with loadCart if you don't mind. I have yet to test USC with a backend so your perspective is very valuable

@amirhemm
Copy link
Author

amirhemm commented Jul 5, 2021

@dayhaysoos you can check out a sample implementation here. Let me know if come across any questions, I'll be more that happy to help if needed.

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

No branches or pull requests

2 participants