private void InitializePageState()
        {
            this.LoginView.Show();
            this.LoginView.BindView();
            this.LoginView.Disable();

            if (this.ShoppingCartModel.ShippingRequired)
            {
                this.PanelShippingMethod.Visible      = true;
                this.PanelShippingAddressWrap.Visible = true;

                this.ShipMethodView.Show();
                this.ShipMethodView.BindView();
                this.ShipMethodView.Disable();
            }
            else
            {
                this.PanelShippingMethod.Visible      = false;
                this.PanelShippingAddressWrap.Visible = false;

                this.ShipMethodView.Hide();
            }

            this.PaymentView.Show();
            this.PaymentView.BindView();
            this.PaymentView.Disable();

            this.ShippingAddressStaticView.Hide();
            this.ShippingAddressEditView.Hide();
            this.ShippingAddressEditUKView.Hide();
            this.ShippingAddressNoZipEditView.Hide();

            PanelTerms.Visible = ConfigurationProvider.DefaultProvider.RequireTermsAndConditions;
            PanelTerms.Enabled = false;

            PanelCheckboxOver13.Enabled = false;

            if (this.AccountModel.IsRegistered)
            {
                this.CreateAccountView.Hide();
                this.PanelCreateAccount.Visible = false;
                this.PanelEmailOptIn.Visible    = false;

                if (this.ShoppingCartModel.ShippingRequired)
                {
                    this.AddressBookView.Show();
                    this.AddressBookView.BindView();
                    this.AddressBookView.Disable();

                    this.HyperLinkShippingAddressBook.Enabled = true;
                    this.HyperLinkShippingAddressBook.Visible = true;

                    this.ShippingAddressStaticView.Show();
                    this.ShippingAddressStaticView.BindView();
                    this.ShippingAddressStaticView.Disable();
                }
            }
            else
            {
                this.EmailOptInYes.Enabled = this.AccountModel.AllowEmailSelected;

                litEmailPrefYes.Text = this.StringResourceProvider.GetString("smartcheckout.aspx.4");
                litEmailPrefNo.Text  = this.StringResourceProvider.GetString("smartcheckout.aspx.5");

                this.EmailOptInNo.Enabled    = this.AccountModel.AllowEmailSelected;
                this.PanelEmailOptIn.Visible = ConfigurationProvider.DefaultProvider.ShowEmailPreferencesOnCheckout;

                if (this.ShoppingCartModel.ShippingRequired)
                {
                    if (string.IsNullOrEmpty(this.AccountModel.ShippingAddress.Country))
                    {
                        if (ConfigurationProvider.DefaultProvider.AddressLocale.Equals("UK"))
                        {
                            this.ShippingAddressEditUKView.Initialize();
                            this.ShippingAddressEditUKView.Show();
                            this.ShippingAddressEditUKView.BindView();
                            this.ShippingAddressEditUKView.Disable();
                        }
                        else
                        {
                            if (ConfigurationProvider.DefaultProvider.UseZipcodeService)
                            {
                                this.ShippingAddressEditView.Initialize();
                                this.ShippingAddressEditView.Show();
                                this.ShippingAddressEditView.BindView();
                                this.ShippingAddressEditView.Disable();
                            }
                            else
                            {
                                this.ShippingAddressNoZipEditView.Initialize();
                                this.ShippingAddressNoZipEditView.Show();
                                this.ShippingAddressNoZipEditView.BindView();
                                this.ShippingAddressNoZipEditView.Disable();
                            }
                        }
                    }
                    else
                    {
                        this.ShippingAddressStaticView.Show();
                        this.ShippingAddressStaticView.BindView();
                        this.ShippingAddressStaticView.Disable();
                    }
                }

                if (!ConfigurationProvider.DefaultProvider.ShowCreateAccount &&
                    ConfigurationProvider.DefaultProvider.PasswordIsOptionalDuringCheckout)
                {
                    this.CreateAccountView.Hide();
                    this.PanelCreateAccount.Visible = false;
                }
                else
                {
                    this.CreateAccountView.Show();
                    this.CreateAccountView.BindView();
                    this.CreateAccountView.Disable();
                    this.PanelCreateAccount.Visible = true;
                }

                this.HyperLinkShippingAddressBook.Enabled = false;
                this.HyperLinkShippingAddressBook.Visible = false;

                this.AddressBookView.Hide();

                PanelCheckboxOver13.Visible = ConfigurationProvider.DefaultProvider.RequireOver13Checked;
            }

            // Show / Hide payment screen if zero dollar order
            PanelPaymentAndBilling.Visible = this.ShoppingCartModel.Total > 0;

            this.MiniCartCartSummary.BindView();

            // if amazon payments, show widgets, and disable shipping address editor
            GatewayCheckoutByAmazon.CheckoutByAmazon checkoutByAmazon = new GatewayCheckoutByAmazon.CheckoutByAmazon();

            var amazonPaymentModel = this.PaymentModel.PaymentMethods.FirstOrDefault(pm => pm.Key == PaymentType.CheckoutByAmazon).Value;

            if (amazonPaymentModel != null)
            {
                var paymentMethod = (CheckOutByAmazonPaymentModel)amazonPaymentModel;
                LitCheckOutByAmazoneShipping.Text = paymentMethod.RenderAddressWidget(new Guid(AspDotNetStorefrontCore.Customer.Current.CustomerGUID));
                LitAmazonPaymentWidget.Text       = paymentMethod.RenderWalletWidget();
            }

            if (IsCheckOutByAmazon())
            {
                PanelCheckOutByAmazonShipping.Visible = true;
                PanelShippingAddressWrap.Visible      = false;
                ShippingAddressEditView.Hide();
                ShippingAddressEditUKView.Hide();
                ShippingAddressStaticView.Hide();
                this.ShippingAddressEditView.Visible = false;

                if (checkoutByAmazon.GetDefaultShippingAddress() == null)
                {
                    SubmitOrder.OnClientClick = "alert('" + this.StringResourceProvider.GetString("gw.checkoutbyamazon.display.3") + "'); return false;";
                }
            }

            this.SubmitOrder.Visible = false;
            this.SubmitOrder.Enabled = false;
        }
Exemplo n.º 2
0
        private void CreateAccount()
        {
            ThisCustomer.RequireCustomerRecord();
            GatewayCheckoutByAmazon.CheckoutByAmazon checkoutByAmazon = new GatewayCheckoutByAmazon.CheckoutByAmazon();

            if (checkoutByAmazon.IsEnabled && checkoutByAmazon.IsCheckingOut && checkoutByAmazon.GetDefaultShippingAddress() == null)
            {
                lblErrorMessage.Text = "gw.checkoutbyamazon.display.3".StringResource();
                pnlErrorMsg.Visible  = true;
                return;
            }

            if (checkoutByAmazon.IsEnabled && checkoutByAmazon.IsCheckingOut && ThisCustomer.IsRegistered)
            {
                checkoutByAmazon.BeginCheckout(new Guid(ThisCustomer.CustomerGUID), false, false);
                Response.Redirect("checkoutshipping.aspx");
            }
            else if (checkoutByAmazon.IsEnabled && checkoutByAmazon.IsCheckingOut)
            {
                checkoutByAmazon.BeginCheckout(new Guid(ThisCustomer.CustomerGUID), false, false);
            }

            SetPasswordFields();

            string AccountName = (ctrlAccount.FirstName.Trim() + " " + ctrlAccount.LastName.Trim()).Trim();

            if (SkipRegistration)
            {
                AccountName = String.Format("{0} {1}", ctrlBillingAddress.FirstName.Trim(), ctrlBillingAddress.LastName.Trim()).Trim();

                if (checkoutByAmazon.IsEnabled && checkoutByAmazon.IsCheckingOut)
                {
                    AccountName = "Anonymous Amazon Customer";
                }
            }

            if (SkipRegistration)
            {
                Page.Validate("skipreg");
            }
            else
            {
                if (ctrlAccount.Password.Contains('\xFF') || ctrlAccount.Password.Length == 0)
                {
                    ctrlAccount.PasswordValidate = ViewState["custpwd"].ToString();
                }
                else
                {
                    ctrlAccount.PasswordValidate = ctrlAccount.Password;
                }

                if (ctrlAccount.PasswordConfirm.Contains('\xFF') || ctrlAccount.PasswordConfirm.Length == 0)
                {
                    ctrlAccount.PasswordConfirmValidate = ViewState["custpwd2"].ToString();
                }
                else
                {
                    ctrlAccount.PasswordConfirmValidate = ctrlAccount.PasswordConfirm;
                }

                ctrlAccount.Over13 = ctrlAccount.Over13;
                if ((!ThisCustomer.IsRegistered) && !checkoutByAmazon.IsCheckingOut && (ctrlAccount.Password.Length == 0 || ctrlAccount.PasswordConfirm.Length == 0))
                {
                    lblErrorMessage.Text = "createaccount.aspx.6".StringResource();
                    ResetScrollPosition();
                    pnlErrorMsg.Visible = true;
                    return;
                }

                ctrlBillingAddress.CountryIDToValidateZipCode  = AppLogic.GetCountryID(ctrlBillingAddress.Country);
                ctrlShippingAddress.CountryIDToValidateZipCode = AppLogic.GetCountryID(ctrlShippingAddress.Country);

                Page.Validate("registration");

                if (RequireSecurityCode)
                {
                    if (Session["SecurityCode"] != null)
                    {
                        String  sCode     = Session["SecurityCode"].ToString();
                        String  fCode     = ctrlAccount.txtSecurityCode.Text;
                        Boolean codeMatch = false;

                        if (AppLogic.AppConfigBool("Captcha.CaseSensitive"))
                        {
                            if (fCode.Equals(sCode))
                            {
                                codeMatch = true;
                            }
                        }
                        else
                        {
                            if (fCode.Equals(sCode, StringComparison.InvariantCultureIgnoreCase))
                            {
                                codeMatch = true;
                            }
                        }

                        if (!codeMatch)
                        {
                            lblErrorMessage.Text                         = string.Format(AppLogic.GetString("lat_signin_process.aspx.5", SkinID, ThisCustomer.LocaleSetting), sCode, fCode);
                            ctrlAccount.txtSecurityCode.Text             = String.Empty;
                            ctrlAccount.imgAccountSecurityImage.ImageUrl = "~/Captcha.ashx?id=1";
                            ResetScrollPosition();
                            pnlErrorMsg.Visible = true;
                            return;
                        }
                    }
                    else
                    {
                        lblErrorMessage.Text                         = string.Format(AppLogic.GetString("lat_signin_process.aspx.5", SkinID, ThisCustomer.LocaleSetting), "", ctrlAccount.txtSecurityCode.Text);
                        ctrlAccount.txtSecurityCode.Text             = String.Empty;
                        ctrlAccount.imgAccountSecurityImage.ImageUrl = "~/Captcha.ashx?id=1";
                        ResetScrollPosition();
                        pnlErrorMsg.Visible = true;
                        return;
                    }
                }

                if (!Page.IsValid && RequireSecurityCode)
                {
                    Session["SecurityCode"] = CommonLogic.GenerateRandomCode(6);
                }
            }



            Page.Validate("createacccount");


            if (Page.IsValid && AccountName.Length > 0)
            {
                String EMailField = CommonLogic.IIF(SkipRegistration, txtSkipRegEmail.Text.ToLowerInvariant().Trim(), ctrlAccount.Email.ToLowerInvariant().Trim());

                bool NewEmailAllowed = Customer.NewEmailPassesDuplicationRules(EMailField, ThisCustomer.CustomerID, SkipRegistration);

                String   PWD    = ViewState["custpwd"].ToString();
                Password p      = new Password(PWD);
                String   newpwd = p.SaltedPassword;
                System.Nullable <int> newsaltkey = p.Salt;

                Password blankpwd = new Password("", ThisCustomer.SaltKey);
                if (!(ThisCustomer.Password == "" || ThisCustomer.Password == blankpwd.SaltedPassword))
                {
                    // do NOT allow passwords to be changed on this page. this is only for creating an account.
                    // if they want to change their password, they must use their account page
                    newpwd     = null;
                    newsaltkey = null;
                }
                if (NewEmailAllowed)
                {
                    AppLogic.eventHandler("CreateAccount").CallEvent("&CreateAccount=true");

                    string strDOB = null;
                    if (AppLogic.AppConfigBool("Account.ShowBirthDateField"))
                    {
                        strDOB = ctrlAccount.DOBMonth + "/" + ctrlAccount.DOBDay + "/" + ctrlAccount.DOBYear;
                        //DOB defaults to 0/0/0 when doing anonymous checkout and blows up dbo.aspdnsf_updCustomer, preventing checkout
                        strDOB = (strDOB.Equals("0/0/0", StringComparison.Ordinal)) ? null : strDOB;
                    }

                    var defaultCustomerLevel_Public = (int)UserType.PUBLIC;

                    ThisCustomer.UpdateCustomer(
                        /*CustomerLevelID*/ defaultCustomerLevel_Public,
                        /*EMail*/ EMailField,
                        /*SaltedAndHashedPassword*/ newpwd,
                        /*SaltKey*/ newsaltkey,
                        /*DateOfBirth*/ strDOB,
                        /*Gender*/ null,
                        /*FirstName*/ ctrlAccount.FirstName,
                        /*LastName*/ ctrlAccount.LastName,
                        /*Notes*/ null,
                        /*SkinID*/ null,
                        /*Phone*/ ctrlAccount.Phone,
                        /*AffiliateID*/ null,
                        /*Referrer*/ null,
                        /*CouponCode*/ null,
                        /*OkToEmail*/ CommonLogic.IIF(ctrlAccount.OKToEmailYes, 1, 0),
                        /*IsAdmin*/ null,
                        /*BillingEqualsShipping*/ CommonLogic.IIF(AppLogic.AppConfigBool("AllowShipToDifferentThanBillTo"), 0, 1),
                        /*LastIPAddress*/ null,
                        /*OrderNotes*/ null,
                        /*SubscriptionExpiresOn*/ null,
                        /*RTShipRequest*/ null,
                        /*RTShipResponse*/ null,
                        /*OrderOptions*/ null,
                        /*LocaleSetting*/ null,
                        /*MicroPayBalance*/ null,
                        /*RecurringShippingMethodID*/ null,
                        /*RecurringShippingMethod*/ null,
                        /*BillingAddressID*/ null,
                        /*ShippingAddressID*/ null,
                        /*GiftRegistryGUID*/ null,
                        /*GiftRegistryIsAnonymous*/ null,
                        /*GiftRegistryAllowSearchByOthers*/ null,
                        /*GiftRegistryNickName*/ null,
                        /*GiftRegistryHideShippingAddresses*/ null,
                        /*CODCompanyCheckAllowed*/ null,
                        /*CODNet30Allowed*/ null,
                        /*ExtensionData*/ null,
                        /*FinalizationData*/ null,
                        /*Deleted*/ null,
                        /*Over13Checked*/ 1, //CommonLogic.IIF(ctrlAccount.Over13 || SkipRegOver13.Checked, 1, 0),
                        /*CurrencySetting*/ null,
                        /*VATSetting*/ null,
                        /*VATRegistrationID*/ null,
                        /*StoreCCInDB*/ CommonLogic.IIF(ctrlAccount.ShowSaveCC, ctrlAccount.SaveCC, true),
                        /*IsRegistered*/ CommonLogic.IIF(SkipRegistration, 0, 1),
                        /*LockedUntil*/ null,
                        /*AdminCanViewCC*/ null,
                        /*BadLogin*/ null,
                        /*Active*/ null,
                        /*PwdChangeRequired*/ null,
                        /*RegisterDate*/ null,
                        /*StoreId*/ AppLogic.StoreID()
                        );
                    if (ctrlAccount.OKToEmailYes)
                    {
                        AddToNewsletterList(ctrlAccount.FirstName, ctrlAccount.LastName, EMailField);
                    }
                    BillingAddress = ThisCustomer.PrimaryBillingAddress;
                    if (BillingAddress.AddressID == 0 && !checkoutByAmazon.IsCheckingOut)
                    {
                        if (pnlBillingInfo.Visible)
                        {
                            BillingAddress.NickName      = ctrlBillingAddress.NickName;
                            BillingAddress.LastName      = ctrlBillingAddress.LastName;
                            BillingAddress.FirstName     = ctrlBillingAddress.FirstName;
                            BillingAddress.Phone         = ctrlBillingAddress.PhoneNumber;
                            BillingAddress.Company       = ctrlBillingAddress.Company;
                            BillingAddress.ResidenceType = (ResidenceTypes)Enum.Parse(typeof(ResidenceTypes), ctrlBillingAddress.ResidenceType);
                            BillingAddress.Address1      = ctrlBillingAddress.Address1;
                            BillingAddress.Address2      = ctrlBillingAddress.Address2;
                            BillingAddress.Suite         = ctrlBillingAddress.Suite;
                            BillingAddress.City          = ctrlBillingAddress.City;
                            BillingAddress.State         = ctrlBillingAddress.State;
                            BillingAddress.Zip           = ctrlBillingAddress.ZipCode;
                            BillingAddress.Country       = ctrlBillingAddress.Country;

                            BillingAddress.InsertDB(ThisCustomer.CustomerID);
                            BillingAddress.MakeCustomersPrimaryAddress(AddressTypes.Billing);
                        }
                    }
                    else
                    {
                        BillingAddress.NickName  = String.Format("{0} {1}", ctrlAccount.FirstName, ctrlAccount.LastName);
                        BillingAddress.LastName  = ctrlAccount.FirstName;
                        BillingAddress.FirstName = ctrlAccount.LastName;
                        BillingAddress.Phone     = ctrlAccount.Phone;
                    }

                    ShippingAddress = ThisCustomer.PrimaryShippingAddress;
                    if (ShippingAddress.AddressID == 0 && !checkoutByAmazon.IsCheckingOut)
                    {
                        if (AllowShipToDifferentThanBillTo)
                        {
                            if (ctrlShippingAddress.Visible)
                            {
                                ShippingAddress.NickName      = ctrlBillingAddress.NickName;
                                ShippingAddress.LastName      = ctrlShippingAddress.LastName;
                                ShippingAddress.FirstName     = ctrlShippingAddress.FirstName;
                                ShippingAddress.Phone         = ctrlShippingAddress.PhoneNumber;
                                ShippingAddress.Company       = ctrlShippingAddress.Company;
                                ShippingAddress.ResidenceType = (ResidenceTypes)Enum.Parse(typeof(ResidenceTypes), ctrlShippingAddress.ResidenceType);
                                ShippingAddress.Address1      = ctrlShippingAddress.Address1;
                                ShippingAddress.Address2      = ctrlShippingAddress.Address2;
                                ShippingAddress.Suite         = ctrlShippingAddress.Suite;
                                ShippingAddress.City          = ctrlShippingAddress.City;
                                ShippingAddress.State         = ctrlShippingAddress.State;
                                ShippingAddress.Zip           = ctrlShippingAddress.ZipCode;
                                ShippingAddress.Country       = ctrlShippingAddress.Country;

                                ShippingAddress.InsertDB(ThisCustomer.CustomerID);
                                if (!String.IsNullOrEmpty(VerifyAddressesProvider))
                                {
                                    VerifyResult        = AddressValidation.RunValidate(ShippingAddress, out StandardizedAddress);
                                    VerifyAddressPrompt = (VerifyResult != AppLogic.ro_OK);
                                    if (VerifyAddressPrompt)
                                    {
                                        ShippingAddress = StandardizedAddress;
                                        ShippingAddress.UpdateDB();
                                    }
                                }
                                ShippingAddress.MakeCustomersPrimaryAddress(AddressTypes.Shipping);
                            }
                        }
                        else
                        {
                            if (!String.IsNullOrEmpty(VerifyAddressesProvider))
                            {
                                VerifyResult        = AddressValidation.RunValidate(BillingAddress, out StandardizedAddress);
                                VerifyAddressPrompt = (VerifyResult != AppLogic.ro_OK);
                                if (VerifyAddressPrompt)
                                {
                                    BillingAddress = StandardizedAddress;
                                    BillingAddress.UpdateDB();
                                }
                            }
                            BillingAddress.MakeCustomersPrimaryAddress(AddressTypes.Shipping);
                        }
                    }
                    else
                    {
                        ShippingAddress.NickName  = String.Format("{0} {1}", ctrlAccount.FirstName, ctrlAccount.LastName);
                        ShippingAddress.LastName  = ctrlAccount.FirstName;
                        ShippingAddress.FirstName = ctrlAccount.LastName;
                        ShippingAddress.Phone     = ctrlAccount.Phone;
                    }

                    if (AppLogic.AppConfigBool("Vat.Enabled") && ctrlAccount.VATRegistrationID.Length > 0)
                    {
                        String vtr = ctrlAccount.VATRegistrationID.Trim();

                        Exception vatServiceException = null;
                        if (AppLogic.VATRegistrationIDIsValid(ctrlBillingAddress.Country, vtr, out vatServiceException))
                        {
                            ThisCustomer.SetVATRegistrationID(vtr);
                        }
                        else
                        {
                            vtr = String.Empty;

                            if (vatServiceException != null && !String.IsNullOrEmpty(vatServiceException.Message))
                            {
                                if (vatServiceException.Message.Length > 255)
                                {
                                    lblErrorMessage.Text = Server.HtmlEncode(vatServiceException.Message.Substring(0, 255));
                                }
                                else
                                {
                                    lblErrorMessage.Text = Server.HtmlEncode(vatServiceException.Message);
                                }
                            }
                            else
                            {
                                lblErrorMessage.Text = "account.aspx.91".StringResource();
                            }
                            pnlErrorMsg.Visible = true;
                            return;
                        }
                    }
                    if (AppLogic.AppConfigBool("DynamicRelatedProducts.Enabled") ||
                        AppLogic.AppConfigBool("RecentlyViewedProducts.Enabled"))
                    {
                        ThisCustomer.ReplaceProductViewFromAnonymous();
                    }
                }
                if (Checkout)
                {
                    if (!NewEmailAllowed)
                    {
                        lblErrorMessage.Text = AppLogic.GetString("createaccount_process.aspx.1", 1, Localization.GetDefaultLocale());
                        InitializePageContent();
                    }
                    else
                    {
                        if (AppLogic.AppConfigBool("SendWelcomeEmail") && EMailField.IndexOf("@") != -1 && ThisCustomer.IsRegistered == true)
                        {
                            // don't let a simple welcome stop checkout!
                            try
                            {
                                string body = AppLogic.RunXmlPackage(AppLogic.AppConfig("XmlPackage.WelcomeEmail"),
                                                                     null,
                                                                     ThisCustomer,
                                                                     this.SkinID,
                                                                     "",
                                                                     "fullname=" + ctrlAccount.FirstName.Trim() + " " + ctrlAccount.LastName.Trim(),
                                                                     false,
                                                                     false,
                                                                     this.EntityHelpers);

                                AppLogic.SendMail(AppLogic.GetString("createaccount.aspx.79", ThisCustomer.SkinID, ThisCustomer.LocaleSetting),
                                                  body,
                                                  true,
                                                  AppLogic.AppConfig("MailMe_FromAddress"),
                                                  AppLogic.AppConfig("MailMe_FromName"),
                                                  EMailField,
                                                  ctrlAccount.FirstName.Trim() + " " + ctrlAccount.LastName.Trim(),
                                                  "",
                                                  AppLogic.MailServer());
                            }
                            catch { }
                        }
                        if (VerifyAddressPrompt)
                        {
                            if (AllowShipToDifferentThanBillTo)
                            {
                                Response.Redirect("address.aspx?Checkout=True&AddressType=Shipping&AddressID=" + Customer.GetCustomerPrimaryShippingAddressID(ThisCustomer.CustomerID).ToString() + "&NewAccount=true&prompt=" + VerifyResult + "&skipreg=" + SkipRegistration + "&returnURL=checkoutshipping.aspx?checkout=true");
                            }
                            else
                            {
                                Response.Redirect("address.aspx?Checkout=True&AddressType=Billing&AddressID=" + Customer.GetCustomerPrimaryShippingAddressID(ThisCustomer.CustomerID).ToString() + "&NewAccount=true&prompt=" + VerifyResult + "&skipreg=" + SkipRegistration + "&returnURL=checkoutshipping.aspx?checkout=true");
                            }
                        }
                        else
                        {
                            if (checkouttype == "ppec" || checkouttype == "ppbml" || checkouttype == "gc")
                            {
                                Response.Redirect("shoppingcart.aspx");
                            }
                            else
                            {
                                Response.Redirect("account.aspx?checkout=true");//checkoutshipping
                            }
                        }
                    }
                }
                else
                {
                    if (!NewEmailAllowed)
                    {
                        DB.ExecuteSQL("update customer set EMail='', IsRegistered = 0 where CustomerID=" + ThisCustomer.CustomerID);
                        lblErrorMessage.Text = AppLogic.GetString("createaccount_process.aspx.1", 1, Localization.GetDefaultLocale());
                        InitializePageContent();
                    }
                    else
                    {
                        if (AppLogic.AppConfigBool("SendWelcomeEmail") && EMailField.IndexOf("@") != -1 && ThisCustomer.IsRegistered == true)
                        {
                            // don't let a simple welcome stop checkout!
                            try
                            {
                                string body = AppLogic.RunXmlPackage(AppLogic.AppConfig("XmlPackage.WelcomeEmail"),
                                                                     null,
                                                                     ThisCustomer,
                                                                     this.SkinID,
                                                                     "",
                                                                     "",
                                                                     false,
                                                                     false,
                                                                     this.EntityHelpers);

                                AppLogic.SendMail(AppLogic.GetString("createaccount.aspx.79", ThisCustomer.SkinID, ThisCustomer.LocaleSetting),
                                                  body,
                                                  true,
                                                  AppLogic.AppConfig("MailMe_FromAddress"),
                                                  AppLogic.AppConfig("MailMe_FromName"),
                                                  EMailField,
                                                  ctrlAccount.FirstName.Trim() + " " + ctrlAccount.LastName.Trim(), "",
                                                  AppLogic.MailServer());
                            }
                            catch { }
                        }
                        if (VerifyAddressPrompt)
                        {
                            if (AllowShipToDifferentThanBillTo)
                            {
                                Response.Redirect("address.aspx?Checkout=False&AddressType=Shipping&AddressID=" + Customer.GetCustomerPrimaryShippingAddressID(ThisCustomer.CustomerID).ToString() + "&NewAccount=true&prompt=" + VerifyResult + "&skipreg=" + SkipRegistration);
                            }
                            else
                            {
                                Response.Redirect("address.aspx?Checkout=False&AddressType=Billing&AddressID=" + Customer.GetCustomerPrimaryShippingAddressID(ThisCustomer.CustomerID).ToString() + "&NewAccount=true&prompt=" + VerifyResult + "&skipreg=" + SkipRegistration);
                            }
                        }
                        else
                        {
                            Response.Redirect("JWMyAccount.aspx");
                        }
                    }
                }
            }
            else
            {
                foreach (IValidator aValidator in this.Validators)
                {
                    if (!aValidator.IsValid)
                    {
                        lblErrorMessage.Text = aValidator.ErrorMessage;
                        break;
                    }
                }
                ResetScrollPosition();
            }

            pnlErrorMsg.Visible = lblErrorMessage.Text.Length > 0;
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            Response.CacheControl = "private";
            Response.Expires      = -1;
            Response.AddHeader("pragma", "no-cache");

            ErrorMessage err;

            if (AppLogic.AppConfigBool("RequireOver13Checked") && !ThisCustomer.IsOver13)
            {
                err = new ErrorMessage(Server.HtmlEncode(AppLogic.GetString("checkout.over13required", ThisCustomer.SkinID, ThisCustomer.LocaleSetting)));
                Response.Redirect("shoppingcart.aspx?errormsg=" + err.MessageId);
            }

            bool phoneCustomer = ((HttpContext.Current.Items["IsBeingImpersonated"] != null) &&
                                  ((string)HttpContext.Current.Items["IsBeingImpersonated"] == "true"));

            bool paypalExpressCheckout = (ThisCustomer.ThisCustomerSession["paypalexpresspayerid"].ToString().Length == 0 &&
                                          ThisCustomer.ThisCustomerSession["paypalexpresstoken"].ToString().Length == 0);

            var checkoutController = CheckOutPageControllerFactory.CreateCheckOutPageController(ThisCustomer, cart);

            if (checkoutController.GetCheckoutType() == CheckOutType.SmartOPC)
            {
                if (!phoneCustomer && checkoutController.CanUseOnePageCheckout())
                {
                    Response.Redirect(checkoutController.GetSmartOnePageCheckoutPage());
                }
            }
            else if (checkoutController.GetCheckoutType() == CheckOutType.BasicOPC)
            {
                if (!paypalExpressCheckout && checkoutController.CanUseOnePageCheckout())
                {
                    Response.Redirect(checkoutController.GetBasicOnePageCheckoutPage());
                }
            }

            RequireSecurePage();

            // -----------------------------------------------------------------------------------------------
            // NOTE ON PAGE LOAD LOGIC:
            // We are checking here for required elements to allowing the customer to stay on this page.
            // Many of these checks may be redundant, and they DO add a bit of overhead in terms of db calls, but ANYTHING really
            // could have changed since the customer was on the last page. Remember, the web is completely stateless. Assume this
            // page was executed by ANYONE at ANYTIME (even someone trying to break the cart).
            // It could have been yesterday, or 1 second ago, and other customers could have purchased limitied inventory products,
            // coupons may no longer be valid, etc, etc, etc...
            // -----------------------------------------------------------------------------------------------
            ThisCustomer.RequireCustomerRecord();

            if (!ThisCustomer.IsRegistered)
            {
                bool boolAllowAnon = AppLogic.ProductIsMLExpress() == false && AppLogic.AppConfigBool("PasswordIsOptionalDuringCheckout");
                if (!boolAllowAnon && ThisCustomer.PrimaryBillingAddressID > 0)
                {
                    Address BillingAddress = new Address();
                    BillingAddress.LoadByCustomer(ThisCustomer.CustomerID, ThisCustomer.PrimaryBillingAddressID, AddressTypes.Billing);
                    if (BillingAddress.PaymentMethodLastUsed == AppLogic.ro_PMPayPalExpress || BillingAddress.PaymentMethodLastUsed == AppLogic.ro_PMPayPalExpressMark)
                    {
                        boolAllowAnon = AppLogic.ProductIsMLExpress() == false && AppLogic.AppConfigBool("PayPal.Express.AllowAnonCheckout");
                    }
                }

                if (!boolAllowAnon)
                {
                    Response.Redirect("createaccount.aspx?checkout=true");
                }
            }
            if (ThisCustomer.PrimaryBillingAddressID == 0 || ThisCustomer.PrimaryShippingAddressID == 0)
            {
                err = new ErrorMessage(Server.HtmlEncode(AppLogic.GetString("checkoutpayment.aspx.2", ThisCustomer.SkinID, ThisCustomer.LocaleSetting)));
                Response.Redirect("shoppingcart.aspx?resetlinkback=1&errormsg=" + err.MessageId);
            }

            SectionTitle = AppLogic.GetString("checkoutshipping.aspx.1", SkinID, ThisCustomer.LocaleSetting);
            cart         = new ShoppingCart(SkinID, ThisCustomer, CartTypeEnum.ShoppingCart, 0, false);

            cart.ValidProceedCheckout(); // will not come back from this if any issue. they are sent back to the cart page!

            GatewayCheckoutByAmazon.CheckoutByAmazon checkoutByAmazon = new GatewayCheckoutByAmazon.CheckoutByAmazon();
            if (checkoutByAmazon.IsCheckingOut)
            {
                if (checkoutByAmazon.GetDefaultShippingAddress() == null)
                {
                    btnContinueCheckout.OnClientClick = "alert('" + "gw.checkoutbyamazon.display.3".StringResource() + "'); return false;";
                }
            }

            if (!cart.IsAllDownloadComponents() && !cart.IsAllFreeShippingComponents() && !cart.IsAllSystemComponents() && (cart.HasMultipleShippingAddresses() || cart.HasGiftRegistryComponents()) && cart.TotalQuantity() <= AppLogic.MultiShipMaxNumItemsAllowed() && cart.CartAllowsShippingMethodSelection && cart.TotalQuantity() > 1 && !checkoutByAmazon.IsCheckingOut)
            {
                Response.Redirect("checkoutshippingmult.aspx");
            }

            //MOD GS - If entire cart is email gift cards...redirect to checkoutgiftcard.aspx
            if (cart.IsAllEmailGiftCards())
            {
                Response.Redirect("checkoutgiftcard.aspx");
            }

            if (AppLogic.AppConfigBool("SkipShippingOnCheckout") ||
                cart.IsAllSystemComponents() ||
                cart.IsAllDownloadComponents() ||
                cart.NoShippingRequiredComponents())
            {
                if (cart.ContainsGiftCard())
                {
                    Response.Redirect("checkoutgiftcard.aspx");
                }
                else
                {
                    if (ThisCustomer.ThisCustomerSession["PayPalExpressToken"] == "")
                    {
                        Response.Redirect("checkoutpayment.aspx");
                    }
                    else
                    {
                        Response.Redirect("checkoutreview.aspx?PaymentMethod=PAYPALEXPRESS");
                    }
                }
            }

            pnlSelectShipping.Visible = AppLogic.AppConfigBool("AllowAddressChangeOnCheckoutShipping") && AppLogic.AppConfigBool("AllowShipToDifferentThanBillTo") && !checkoutByAmazon.IsCheckingOut;

            ctrlShippingMethods.ErrorMessage = string.Empty;
            pnlErrorMsg.Visible = false;

            CartItem FirstCartItem            = (CartItem)cart.CartItems[0];
            Address  FirstItemShippingAddress = new Address();

            FirstItemShippingAddress.LoadByCustomer(ThisCustomer.CustomerID, FirstCartItem.ShippingAddressID, AddressTypes.Shipping);
            if (FirstItemShippingAddress.AddressID == 0)
            {
                err = new ErrorMessage(Server.HtmlEncode(AppLogic.GetString("checkoutshipping.aspx.10", ThisCustomer.SkinID, ThisCustomer.LocaleSetting)));
                Response.Redirect("shoppingcart.aspx?errormsg=" + err.MessageId);
            }

            if (!this.IsPostBack)
            {
                if (!AppLogic.AppConfigBool("AllowMultipleShippingAddressPerOrder") && CommonLogic.QueryStringCanBeDangerousContent("dontupdateid").Length == 0)
                {
                    // force primary shipping address id to be active on all cart items (safety check):
                    DB.ExecuteSQL("update ShoppingCart set ShippingAddressID=(select ShippingAddressID from customer where CustomerID=" + ThisCustomer.CustomerID.ToString() + ") where CustomerID=" + ThisCustomer.CustomerID.ToString() + " and CartType=" + ((int)CartTypeEnum.ShoppingCart).ToString());
                    Response.Redirect("checkoutshipping.aspx?dontupdateid=true");
                }
                InitializePageContent();
            }
            else
            {
                pnlErrorMsg.Visible = false;
                if (CommonLogic.FormCanBeDangerousContent("btnContinueCheckout") != "")
                {
                    ProcessCheckOut();
                }
            }

            ctrlShoppingCart.HeaderTabImageURL     = AppLogic.SkinImage("OrderInfo.gif");
            ctrlShoppingCart.HeaderTabEditOderLink = string.Format(" {0}<a href=\"ShoppingCart.aspx\"> {1}</a>", AppLogic.GetString("checkoutcard.aspx.9", SkinID, ThisCustomer.LocaleSetting), AppLogic.GetString("checkoutcard.aspx.10", SkinID, ThisCustomer.LocaleSetting));

            AppLogic.eventHandler("CheckoutShipping").CallEvent("&CheckoutShipping=true");
        }