Hi,
When adding login capabilities to the one page checkout I discovered that somewhere an address with all nulls is being created. During the login when the anonymous user is migrated over to the authenticated user it seems to take this new address with it and store the new (all null) address as the primary address. I've tried manually setting the primaryaddress:
Token.Instance.User.PrimaryAddressId = loginUser.PrimaryAddressId;
That didn't work. I also tried clearing out the anon user's address before migration:
User thisuser = Token.Instance.User;
thisuser.Addresses.DeleteAll();
thisuser.PrimaryAddressId = 0;
thisuser.Save();
Obviously that didn't work either or I wouldn't be posting here. I can't find another forum post about this issue.
-Tim
primaryaddress issue adding login to onepagecheckout
-
- Ensign (ENS)
- Posts: 3
- Joined: Fri Aug 13, 2010 10:03 am
Re: primaryaddress issue adding login to onepagecheckout
See the code we used in ConLib/LoginDialog control. You need to make use of User.Migrate method to migrate information of user.
-
- Ensign (ENS)
- Posts: 3
- Joined: Fri Aug 13, 2010 10:03 am
Re: primaryaddress issue adding login to onepagecheckout
Thanks for the reply mazhar.
I did indeed use that method. After the following code is executed, I end up with the logged in user having a new primaryaddressid that refers to an address record full of null values. This is saved to the database.
User loginUser = UserDataSource.LoadForUserName(username);
if (loginUser != null)
{
if (User.Login(username, password))
{
//LOGIN SUCCEEDED, MIGRATE USER
int newUserId = loginUser.UserId;
User.Migrate(Token.Instance.User, UserDataSource.Load(newUserId));
Token.Instance.UserId = newUserId;
Response.Cookies.Add(new HttpCookie("UserName", ""));
.
.
.
}
}
It seems like the migrate method is acting screwy but I hope you can tell me that I'm just doing something stupid. Thanks!
I did indeed use that method. After the following code is executed, I end up with the logged in user having a new primaryaddressid that refers to an address record full of null values. This is saved to the database.
User loginUser = UserDataSource.LoadForUserName(username);
if (loginUser != null)
{
if (User.Login(username, password))
{
//LOGIN SUCCEEDED, MIGRATE USER
int newUserId = loginUser.UserId;
User.Migrate(Token.Instance.User, UserDataSource.Load(newUserId));
Token.Instance.UserId = newUserId;
Response.Cookies.Add(new HttpCookie("UserName", ""));
.
.
.
}
}
It seems like the migrate method is acting screwy but I hope you can tell me that I'm just doing something stupid. Thanks!
-
- Ensign (ENS)
- Posts: 3
- Joined: Fri Aug 13, 2010 10:03 am
Re: primaryaddress issue adding login to onepagecheckout
Ok, it seems to be working now. I was doing some other stuff after the migrate, trying to assign some values to fields in Token.Instance.User. I have no idea why removing that would work but it seems to have solved it.