Persistent Cart Across Browsers/Devices #4311
pevey
started this conversation in
Feature Requests
Replies: 2 comments 4 replies
-
Hey @pevey i didn't quite follow how adding the proposed API improves the current cart functionality. The new API requires a logged in customer but if the customer is already logged in then the functionality already exists? Or you are describing how it currently works on your custom setup? Thanks |
Beta Was this translation helpful? Give feedback.
4 replies
-
Just a suggestion |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
On many store web sites, a user's cart persists if they log into their account from a new device. I have implemented this feature for my own use, and I think it would be a useful addition to the core.
This discussion is to get feedback on this idea and the planned approach.
Currently, when I fetch a cart in my storefront application (using the sveltekit-medusa-client), the app first checks if a cart cookie is set on that device/browser and tries to use that. If it is not set or if the cart cookie is not valid, it looks to see if there is a logged in user. If so, it checks to see if that user has a valid cart session. The checking is very simple. It just returns the first valid cart session found for that user.
This requires two small customizations of the medusa backend that I am proposing adding to the core. I think adding these to the core is more appropriate than making a plugin for them since these changes are quite small and are not really about integration with a third-party service or application. These are customizations that I think would be widely applicable for many medusa users.
NOTE: The function in part 2 was edited after some testing to address situations where a customer may create a new cart on a new device, log in, complete that cart, and then not want to see old carts from before the time of the last completed cart.
If anyone has any suggested changes or additions, please let me know. I will wait a week or so and then create a PR if there is general agreement.
Beta Was this translation helpful? Give feedback.
All reactions