Ejemplo n.º 1
0
        /// <summary> Updates the customer information in both Sitecore and in session </summary>
        /// <param name="formid"> The formid. </param>
        /// <param name="fields">The fields.</param>
        /// <param name="data">The data.</param>
        public void Execute(ID formid, AdaptedResultList fields, params object[] data)
        {
            if (StaticSettings.MasterDatabase == null)
            {
                Log.Warn("'Create Item' action : master database is unavailable", this);
            }

            NameValueCollection form = new NameValueCollection();

            ActionHelper.FillFormData(form, fields, this.ProcessField);

            ICustomerManager <CustomerInfo> customerManager = Context.Entity.Resolve <ICustomerManager <CustomerInfo> >();
            CustomerInfo customerInfo = customerManager.GetCustomerInfo(customerManager.CurrentUser.NickName);

            if (customerInfo == null)
            {
                return;
            }

            customerInfo.CustomerId = customerManager.CurrentUser.CustomerId;

            customerInfo.BillingAddress.Name    = form["Name"];
            customerInfo.BillingAddress.Address = form["Address"];
            customerInfo.BillingAddress.Zip     = form["Zip"];
            customerInfo.BillingAddress.City    = form["City"];
            customerInfo.BillingAddress.State   = form["State"];

            if (!string.IsNullOrEmpty(form["Country"]))
            {
                IEntityProvider <Country> countryProvider = Context.Entity.Resolve <IEntityProvider <Country> >();
                customerInfo.BillingAddress.Country = countryProvider.Get(form["Country"]);
            }

            foreach (string key in form.AllKeys)
            {
                customerInfo[key] = form[key];
            }

            EntityHelper entityHepler      = Context.Entity.Resolve <EntityHelper>();
            AddressInfo  targetAddressInfo = customerInfo.ShippingAddress;

            entityHepler.CopyPropertiesValues(customerInfo.BillingAddress, ref targetAddressInfo);

            customerManager.CurrentUser = customerInfo;
            customerManager.UpdateCustomerProfile(customerInfo);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Submits the specified formid.
        /// </summary>
        /// <param name="formid">The formid.</param>
        /// <param name="fields">The fields.</param>
        /// <param name="data">The data.</param>
        public void Execute(ID formid, AdaptedResultList fields, params object[] data)
        {
            if (StaticSettings.MasterDatabase == null)
            {
                Log.Warn("'Create Item' action : master database is unavailable", this);
            }

            NameValueCollection form = new NameValueCollection();

            ActionHelper.FillFormData(form, fields, this.ProcessField);

            // If username and password was given, create a user.
            if (string.IsNullOrEmpty(form["Email"]) || string.IsNullOrEmpty(form["Password"]))
            {
                return;
            }

            string name     = form["Email"].Trim();
            string password = form["Password"];
            string email    = form["Email"];

            string fullNickName = Sitecore.Context.Domain.GetFullName(name);

            ICustomerManager <CustomerInfo> customerManager = Context.Entity.Resolve <ICustomerManager <CustomerInfo> >();
            CustomerInfo customerInfo = customerManager.CreateCustomerAccount(fullNickName, password, email);

            if (customerInfo == null)
            {
                AnalyticsUtil.AuthentificationAccountCreationFailed();
                return;
            }

            foreach (string key in form.AllKeys)
            {
                customerInfo[key] = form[key];
            }

            customerInfo.BillingAddress.Name    = form["Name"];
            customerInfo.BillingAddress.Address = form["Address"];
            customerInfo.BillingAddress.Zip     = form["Zip"];
            customerInfo.BillingAddress.City    = form["City"];
            customerInfo.BillingAddress.State   = form["State"];

            if (!string.IsNullOrEmpty(form["Country"]))
            {
                IEntityProvider <Country> countryProvider = Context.Entity.Resolve <IEntityProvider <Country> >();
                customerInfo.BillingAddress.Country = countryProvider.Get(form["Country"]);
            }

            if (form["HideThisSection"] == "1")
            {
                customerInfo.ShippingAddress.Name    = form["Name"];
                customerInfo.ShippingAddress.Address = form["Address"];
                customerInfo.ShippingAddress.Zip     = form["Zip"];
                customerInfo.ShippingAddress.City    = form["City"];
                customerInfo.ShippingAddress.State   = form["State"];

                if (!string.IsNullOrEmpty(form["ShippingCountry"]))
                {
                    IEntityProvider <Country> countryProvider = Context.Entity.Resolve <IEntityProvider <Country> >();
                    customerInfo.ShippingAddress.Country = countryProvider.Get(form["ShippingCountry"]);
                }
            }
            else
            {
                EntityHelper entityHepler      = Context.Entity.Resolve <EntityHelper>();
                AddressInfo  targetAddressInfo = customerInfo.ShippingAddress;

                entityHepler.CopyPropertiesValues(customerInfo.BillingAddress, ref targetAddressInfo);
            }

            customerManager.UpdateCustomerProfile(customerInfo);
            customerManager.CurrentUser = customerInfo;

            AnalyticsUtil.AuthentificationAccountCreated();
        }