/// <summary> /// Adds CustomerInfo, Shippingdetails and Billingdetails into the ShoppingCart instance /// Also updates the CustomerInfo session /// </summary> /// <param name="formid">The formid.</param> /// <param name="fields">The fields.</param> /// <param name="data">The data.</param> /// <exception cref="ValidatorException">Throws <c>ValidatorException</c> in a customer is already exists.</exception> public void Execute(ID formid, AdaptedResultList fields, params object[] data) { AnalyticsUtil.CheckoutNext(); NameValueCollection orderInfo = new NameValueCollection(); ActionHelper.FillFormData(orderInfo, fields, this.FillOrderInfo); bool isNewUser = false; ICustomerManager <CustomerInfo> customerManager = Context.Entity.Resolve <ICustomerManager <CustomerInfo> >(); CustomerInfo customerInfo; if (orderInfo["HideCreateUserSection"] == "1" && !string.IsNullOrEmpty(orderInfo["Password"]) && !Sitecore.Context.User.IsAuthenticated) { try { string fullNickName = Sitecore.Context.Domain.GetFullName(orderInfo["Email"]); customerInfo = customerManager.CreateCustomerAccount(fullNickName, orderInfo["Password"], orderInfo["Email"]); } catch (MembershipCreateUserException ex) { Log.Error("Unable to create a customer account.", ex, this); throw new ValidatorException(ex.Message, ex); } isNewUser = true; } else { customerInfo = customerManager.CurrentUser; } Assert.IsNotNull(customerInfo, "Cannot create user"); foreach (string key in orderInfo.AllKeys) { customerInfo[key] = orderInfo[key]; } customerInfo.BillingAddress.Name = orderInfo["Name"]; customerInfo.BillingAddress.Address = orderInfo["Address"]; customerInfo.BillingAddress.Zip = orderInfo["Zip"]; customerInfo.BillingAddress.City = orderInfo["City"]; customerInfo.BillingAddress.State = orderInfo["State"]; customerInfo.Email = orderInfo["Email"]; // Find country. if (!string.IsNullOrEmpty(orderInfo["Country"])) { IEntityProvider <Country> countryProvider = Context.Entity.Resolve <IEntityProvider <Country> >(); customerInfo.BillingAddress.Country = countryProvider.Get(orderInfo["Country"]); } // If shipping checkbox is checked if (orderInfo["HideThisSection"] == "1") { customerInfo.ShippingAddress.Name = orderInfo["ShippingName"]; customerInfo.ShippingAddress.Address = orderInfo["ShippingAddress"]; customerInfo.ShippingAddress.Zip = orderInfo["ShippingZip"]; customerInfo.ShippingAddress.City = orderInfo["ShippingCity"]; customerInfo.ShippingAddress.State = orderInfo["ShippingState"]; if (!string.IsNullOrEmpty(orderInfo["ShippingCountry"])) { IEntityProvider <Country> countryProvider = Context.Entity.Resolve <IEntityProvider <Country> >(); customerInfo.ShippingAddress.Country = countryProvider.Get(orderInfo["ShippingCountry"]); } } else { EntityHelper entityHepler = Context.Entity.Resolve <EntityHelper>(); AddressInfo targetAddressInfo = customerInfo.ShippingAddress; entityHepler.CopyPropertiesValues(customerInfo.BillingAddress, ref targetAddressInfo); } ShoppingCart shoppingCart = Context.Entity.GetInstance <ShoppingCart>(); shoppingCart.CustomerInfo = customerInfo; IEntityProvider <NotificationOption> notificationProvider = Context.Entity.Resolve <IEntityProvider <NotificationOption> >(); Assert.IsNotNull(notificationProvider, "Notification options provider is null"); shoppingCart.NotificationOption = notificationProvider.Get("Email"); shoppingCart.NotificationOptionValue = orderInfo["Email"]; if (isNewUser) { customerManager.UpdateCustomerProfile(customerInfo); } customerManager.CurrentUser = customerInfo; Context.Entity.SetInstance(shoppingCart); // Indicates that the form has been filled out and that it should be initialized if the user returnes to this page. ICheckOut checkOut = Context.Entity.GetInstance <ICheckOut>(); if (checkOut is CheckOut) { ((CheckOut)checkOut).HasOtherShippingAddressBeenChecked = orderInfo["HideThisSection"] == "1"; } Context.Entity.SetInstance(checkOut); ItemUtil.RedirectToNavigationLink(NavigationLinkNext, false); }