Guest user cart lost after register

Hace 8 meses
Hi

When a guest user put items into the cart, on checkout they are navigated to the register/login page. If they choose to register as a new user I need to navigate them to checkout page (done), but in the process the card loose their items, and the navigation fails, because the cart is empty. How can I fix this, or whet to override.

thnx
Hace 8 meses
What version of nopCommerce ?
Hace 8 meses
4.60.1
Hace 8 meses
atila.vastag wrote:
Hi

When a guest user put items into the cart, on checkout they are navigated to the register/login page. If they choose to register as a new user I need to navigate them to checkout page (done), but in the process the card loose their items, and the navigation fails, because the cart is empty. How can I fix this, or whet to override.

thnx


Yes many people facing this is problem.. solution is after register user should be auto login and have to move cart item to that user account.
Hace 8 meses
In my own controller I have the following code:

var result = await base.RegisterAsync(model, returnUrl, captchaValid, form);

if (cart.Any())
  ((RedirectResult)result).Url = "/registerresult/1?returnUrl=/onepagecheckout#opc-billing";

//send email
var email = new ShopRegisterEmailRequest(model.FirstName, model.Email, "NopShopRegistrationTemplate.cshtml");
await myService.SendRegistrationEmailAsync<bool>(email);

return result;


In the line
await base.RegisterAsync(model, returnUrl, captchaValid, form);
,

inspecting the code there is a line that does the login (what is suggested), and it runs every time.
return await _customerRegistrationService.SignInCustomerAsync(customer, returnUrl, true);


So does I need to do something more, or something different?
thnx
Hace 8 meses
Preserving/transferring the cart should work out of the box.  However, I see that it is also broken in the online demo, so it must be a bug introduced in 4.60
Hace 8 meses
Works fine in v4.6.4

The Routine that does it is MigrateShoppingCartAsync(...) in
nopCommerce_4.60.4_Source\src\Libraries\Nop.Services\Orders\ShoppingCartService.cs
called from SignInCustomerAsync in
nopCommerce_4.60.4_Source\src\Libraries\Nop.Services\Customers\CustomerRegistrationService.cs

Are you still using these routines or maybe your code is bypassing
or the code is being overriden or by a plugin ?
Hace 8 meses
As you can see from my code example, I am not bypassing it, I run all the build in register function.
Hace 8 meses
Yidna wrote:
SignInCustomerAsync in
nopCommerce_4.60.4_Source\src\Libraries\Nop.Services\Customers\CustomerRegistrationService.cs

Checking the code in this routine - are you somehow preserving the Customer.Id - if so then the migrate code does not run - the Id before login and after login must be different


var currentCustomer = await _workContext.GetCurrentCustomerAsync();
if (currentCustomer?.Id != customer.Id)
{
    //migrate shopping cart
    await _shoppingCartService.MigrateShoppingCartAsync(currentCustomer, customer, true);
    await _workContext.SetCurrentCustomerAsync(customer);
}
Hace 7 meses
As I can see, the main problem is that after logout the cookie not got cleared, the GIUD of the previous user is still there. So when the  _workContext.GetCurrentCustomerAsync() runs, it always founds the latest logged in user. Because of this any logic I tried was a dead end, because either the logout process fails or the cart retrieve  fail.