/// <summary> /// Profile migrate from anonymous. /// </summary> /// <param name="sender">The sender.</param> /// <param name="pe">The <see cref="ProfileMigrateEventArgs"/> instance containing the event data.</param> private void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs pe) { var client = ServiceLocator.Current.GetInstance<OrderClient>(); var orders = client.GetAllCustomerOrders(pe.AnonymousID, UserHelper.CustomerSession.StoreId); if (orders != null) { foreach (var order in orders) { order.CustomerId = UserHelper.CustomerSession.CustomerId; order.CustomerName = UserHelper.CustomerSession.CustomerName; } client.SaveChanges(); } // Migrate shopping cart var cart = new CartHelper(CartHelper.CartName); var anonymousCart = new CartHelper(CartHelper.CartName, pe.AnonymousID); // Only perform merge if cart is not empty if (!anonymousCart.IsEmpty) { // Merge cart cart.Add(anonymousCart.Cart, true); cart.SaveChanges(); // Delete anonymous cart anonymousCart.Delete(); anonymousCart.SaveChanges(); } var wishList = new CartHelper(CartHelper.WishListName); var anonymousWishList = new CartHelper(CartHelper.WishListName, pe.AnonymousID); // Only perform merge if cart is not empty if (!anonymousWishList.IsEmpty) { // Merge wish list wishList.Add(anonymousWishList.Cart, true); if (String.IsNullOrEmpty(wishList.Cart.BillingCurrency)) { wishList.Cart.BillingCurrency = UserHelper.CustomerSession.Currency; } wishList.SaveChanges(); // Delete anonymous wish list anonymousWishList.Delete(); anonymousWishList.SaveChanges(); } //Delete the anonymous data from the database //ProfileManager.DeleteProfile(pe.AnonymousID); //Remove the anonymous identifier from the request so //this event will no longer fire for a logged-in user AnonymousIdentificationModule.ClearAnonymousIdentifier(); }
/// <summary> /// Reorders the specified order. /// </summary> /// <param name="orderId">The order identifier.</param> /// <returns>ActionResult.</returns> /// <exception cref="System.UnauthorizedAccessException"></exception> public ActionResult Reorder(string orderId) { var order = _orderClient.GetCustomerOrder(UserHelper.CustomerSession.CustomerId, orderId); if (order == null || String.IsNullOrEmpty(order.CustomerId)) { throw new UnauthorizedAccessException(); } //Convert order forms to shopping cart order.OrderForms.ForEach(f=>f.Name = CartHelper.CartName); var ch = new CartHelper(CartHelper.CartName); ch.Add(order); if (String.IsNullOrEmpty(ch.Cart.BillingCurrency)) { ch.Cart.BillingCurrency = UserHelper.CustomerSession.Currency; } // run workflows ch.RunWorkflow("ShoppingCartPrepareWorkflow"); ch.SaveChanges(); return RedirectToAction("Index", "Checkout"); }