Page 1 of 1
Write a Remember Me cookie after Customer Checks out
Posted: Tue May 18, 2010 12:26 pm
by Mike718NY
After a customer (who created an account) checks out, . . and they placed their order, . .
I want to write a "remember me" cookie.
So the next time they return, their Email address will be in the
"E-Mail Address : " field of the Login Page.
I tried making this "true" but it didn't work (from OnePageCheckout):
User.Migrate(oldUser, newUser, true);
Token.Instance.InitUserContext(newUser);
FormsAuthentication.SetAuthCookie(newUser.UserName, false); // true didn't work
Anyone know how I can do this?
Re: Write a Remember Me cookie after Customer Checks out
Posted: Wed May 19, 2010 3:36 am
by s_ismail
I am not sure where do you want to write your cookie.Already on log in Page a cookie is working to remember User Name usually email address.
This is the code to write a cookie
Place this on login/register Button click event
Code: Select all
HttpCookie EmailCookie = new HttpCookie("Email", EmailTextBox.Text);
EmailCookie.Expires = DateTime.MaxValue;
Response.Cookies.Add(EmailCookie);
On Page Load place this code
Code: Select all
HttpCookie EmailCookie = Request.Cookies["Email"];
if (EmailCookie != null && !string.IsNullOrEmpty(EmailCookie.Value))
EmailTextBox.Text.Text = EmailCookie.Value;
Re: Write a Remember Me cookie after Customer Checks out
Posted: Wed May 19, 2010 5:49 am
by mazhar
AbleCommerce login page already have a remember me option. Did you tried that?
Re: Write a Remember Me cookie after Customer Checks out
Posted: Wed May 19, 2010 9:39 am
by Mike718NY
mazhar wrote:AbleCommerce login page already have a remember me option.
That works only after the customer puts in their Email address
the first time they return to the site, after placing their first order.
From then on, the Email address will appear
The problem is when they return to the site after they placed their first order :
the Email address doesn't show in the box.
Re: Write a Remember Me cookie after Customer Checks out
Posted: Wed May 19, 2010 10:16 am
by Mike718NY
I tried this and I think it works, . . added code at end (OnePageCheckout):
Code: Select all
void CheckedOut(object sender, CheckedOutEventArgs e)
{
...............
//MIGRATE THE USER
User oldUser = Token.Instance.User;
string newUserName = oldUser.PrimaryAddress.Email;
string newEmail = oldUser.PrimaryAddress.Email;
string newPassword = NewUserPassword.Text;
if (!CreateAccountPanel.Visible)
{
anonCheckout = true;
newUserName = "zz_anonymous_" + Guid.NewGuid().ToString("N") + "@domain.xyz";
newPassword = Guid.NewGuid().ToString("N");
}
MembershipCreateStatus createStatus;
User newUser = UserDataSource.CreateUser(newUserName, newEmail, newPassword, string.Empty, string.Empty, true, Token.Instance.User.AffiliateId, out createStatus);
//IF THE CREATE FAILS, IGNORE AND CONTINUE CREATING THE ORDER
if (createStatus == MembershipCreateStatus.Success)
{
if (anonCheckout)
{
// CHANGE THE NAME AND EMAIL TO SOMETHING MORE FRIENDLY THAN GUID
newUser.UserName = "zz_anonymous_" + newUser.UserId.ToString() + "@domain.xyz";
newUser.Save();
}
User.Migrate(oldUser, newUser, true);
Token.Instance.InitUserContext(newUser);
FormsAuthentication.SetAuthCookie(newUser.UserName, false);
// ********* I ADDED THIS TO WRITE THE COOKIE ********************
if (!anonCheckout)
{
HttpCookie cookie = new HttpCookie("UserName", newUser.UserName);
cookie.Expires = DateTime.MaxValue;
Response.Cookies.Add(cookie);
}
}
}
......................
Now when the customer return, the Email Address appears in Log In email text box.
This will avoid a lot of confusion, and make it easier for returning customers.
Re: Write a Remember Me cookie after Customer Checks out
Posted: Wed May 19, 2010 12:06 pm
by Mike718NY
This worked, . . but change
if (!anonCheckout)
{....
to:
if (CreateAccountPanel.Visible)
{....