// Carry over profile property values from an anonymous to an authenticated state
protected void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs e)
{
Profile anonymousProfile = PB.ProfileManager.Instance.GetAnonymousUser();
Profile profile = PB.ProfileManager.Instance.GetCurrentUser(e.Context.User.Identity.Name);
//Merge anonymous shopping cart items to the authenticated shopping cart items
foreach (Cart item in anonymousProfile.CartCollection)
{
profile.CartCollection.Add(new Cart()
{
ItemId = item.ItemId, UniqueId = profile.UniqueId, IsShoppingCart = true, Quantity = item.Quantity
});
}
//Merge anonymous wishlist items to the authenticated wishlist items
foreach (Cart item in anonymousProfile.WishList)
{
profile.WishList.Add(new Cart()
{
ItemId = item.ItemId, UniqueId = profile.UniqueId, IsShoppingCart = false, Quantity = item.Quantity
});
}
var profileService = new ProfileService();
profileService.DeepSave(profile);
// Clean up anonymous profile
ProfileManager.DeleteProfile(e.AnonymousID);
AnonymousIdentificationModule.ClearAnonymousIdentifier();
//Clear the cart.
anonymousProfile.CartCollection.Clear();
anonymousProfile.WishList.Clear();
profileService.DeepSave(anonymousProfile);
}