/// <summary> /// Migrates data such as profile settings and basket contents from one user to another. /// </summary> /// <param name="oldUser">The user that provides the source data.</param> /// <param name="newUser">The user to receive the data.</param> /// <param name="includeOrderData">If true, order history and address book are migrated.</param> /// <param name="isNewUserAccount">If true, newUser represents an account just created.</param> public static void Migrate(User oldUser, User newUser, bool includeOrderData, bool isNewUserAccount) { //FAIL MIGRATION IF REQUIRED PARAMETERS MISSING if (oldUser == null) { throw new ArgumentNullException("oldUser"); } if (newUser == null) { throw new ArgumentNullException("newUser"); } //ONLY MIGRATE IF USERID DOES NOT MATCH if (oldUser.UserId != newUser.UserId) { //MIGRATE AFFILIATE SETTINGS if (oldUser.Affiliate != null && oldUser.AffiliateId != newUser.AffiliateId) { // A VALID AFFILIATE WAS SET ON THE OLD USER AND IS NOT THE ONE ASSOCIATED WITH NEW USER // SHOULD WE UPDATE THE USER? StoreSettingCollection settings = Store.GetCachedSettings(); if (isNewUserAccount || settings.AffiliateReferralRule == ReferralRule.NewSignupsOrExistingUsersOverrideAffiliate || (settings.AffiliateReferralRule == ReferralRule.NewSignupsOrExistingUsersNoOverride && newUser.AffiliateId == 0)) { // EITHER A NEW SIGNUP // OR THE RULE IS TO ALWAYS OVERRIDE // OR AN EXISTING USER WITH NO AFFILIATE SET WITH EXISTING USERS NO OVERRIDE OPTION // AFFILIATE SHOULD BE UPDATED FOR THE TARGET USER newUser.AffiliateId = oldUser.AffiliateId; newUser.AffiliateReferralDate = oldUser.AffiliateReferralDate; } // UPDATE USERS WITH NEW AFFILIATE ASSOCIATIONS newUser.Save(); oldUser.AffiliateId = 0; oldUser.AffiliateReferralDate = DateTime.MinValue; oldUser.Save(); } //TRANSFER BASKET IF NEEDED Basket.Transfer(oldUser.UserId, newUser.UserId); Wishlist.Transfer(oldUser.UserId, newUser.UserId); // TRANSFER PAGE VIEW HISTORY PageViewDataSource.UpdateUser(oldUser.UserId, newUser.UserId); //SHOULD WE TRANSFER ORDER DATA? if (includeOrderData) { //REASSIGN ORDERS AND ADDRESSES TO NEW USER OrderDataSource.UpdateUser(oldUser.UserId, newUser.UserId); AddressDataSource.UpdateUser(oldUser.UserId, newUser.UserId); } else if (oldUser.IsAnonymous) { //BUG 7740, ERASE ANY ADDRESS INFO ASSOCIATED WITH ANON ACCOUNT oldUser.Addresses.DeleteAll(); oldUser.PrimaryAddressId = 0; oldUser.Save(); } } }
public static Address Load(Int32 addressId) { return(AddressDataSource.Load(addressId, true)); }