cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Logged in user tries to register - Cart merge

rbespalovnc
Participant
0 Likes
504

Scenario: a user is logged in in hybris (soft or hard login, doesn't matter) and has some items in cart.

They go to the register page, register as a new user and are automatically logged in. At this moment cart merge happens and:

  • the new user gets all the cart items from the old user

  • old user (if you relogin with them) gets an empty cart

What I would like is the opposite: save the cart for the old user and have the new user get a new fresh cart.

I found that calling DefaultCartService::removeSessionCart() solves the problem with having a new empty cart but it also erases the cart for the old user.

How can I reliably save the cart for the old user and then erase it from session?

Or in other words - how can I force-logout the user in the middle of the registration process but without doing any redirects?

Accepted Solutions (0)

Answers (1)

Answers (1)

rbespalovnc
Participant
0 Likes

Just a short update: my current solution is use this line from de.hybris.platform.order.impl.DefaultCartService:

getSessionService().removeAttribute(SESSION_CART_PARAMETER_NAME);

Removing the attribute from the session forces creation of a new empty cnd the old one stays saved for the old user.

Pretty sure there is a better solution, but this one solves the problem at least.