Add temporary user cart to logged in user

Hello everyone!
So I’m working on shopping application where users will be able to add items to their cart even before logging in. I’m creating a New Cart when they add their first item and starting with the 2nd item, they will be added to the already created Cart’s items list. I have created a custom state of type “Cart” to store the cart temporarily. Right after creating the cart, I’m setting state “Temp-cart” = Step 1’s Create new cart. When user click on the cart button, they’ll be prompted to log in. I’m using reusable sign up/log in popup to do this. After they login/sign up, I’m setting Current user’s cart = “Repeating group’s Temp-cart” which is the custom state storing temporary cart. I see no mistake in this logic, but it’s not working.
Am I missing something?

Help!

Looks ok to me. Did you try doing this step-by-step in the debugger and seeing how the data progresses?

Try it and let me know where in the process the cart data is lost.

T
Learn no code → nocodify.com

What exactly do you mean when you say it’s “not working”. Do you mean the items are not adding to the cart upon logging in?

Yahh
When the user is not logged in, the items are getting added to the cart. After clicking on the cart to check out, login popup is being displayed and user logs in, then the cart is getting discarded. Instead it should be assigned to the logged in user. I’m storing the cart in a state and assigning it to the current logged in user in the Workflow after logging in through the login popup. But it’s not getting assigned.
Is there any better way to do this?

I personally haven’t used this plugin, but I think your specific use-case is going to need a plugin to handle cookies, like this one:

I thinkthe reason why the cart data disappears upon logging in is that it’s not stored in the cookie itself when the user isn’t logged in to your site. So you might want to give that a try.

But I’m storing it in the custom state right…

This topic was automatically closed after 70 days. New replies are no longer allowed.