Ejemplo n.º 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    this.SettingManager.SetParam("Shipping.EstimateShipping.Enabled", cbEstimateShippingEnabled.Checked.ToString());
                    this.SettingManager.SetParam("Shipping.FreeShippingOverX.Enabled", cbFreeShippingOverX.Checked.ToString());
                    this.SettingManager.SetParamNative("Shipping.FreeShippingOverX.Value", txtFreeShippingOverX.Value);

                    Address shippingOriginAddress = new Address();
                    shippingOriginAddress.CountryId = int.Parse(this.ddlShippingOriginCountry.SelectedItem.Value);
                    shippingOriginAddress.StateProvinceId = int.Parse(this.ddlShippingOriginStateProvince.SelectedItem.Value);
                    shippingOriginAddress.ZipPostalCode = txtShippingOriginZipPostalCode.Text;
                    this.ShippingService.ShippingOrigin = shippingOriginAddress;

                    this.CustomerActivityService.InsertActivity(
                        "EditShippingSettings",
                        GetLocaleResourceString("ActivityLog.EditShippingSettings"));

                    Response.Redirect("ShippingSettings.aspx");
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    //standard settings
                    this.TaxService.PricesIncludeTax = cbPricesIncludeTax.Checked;
                    this.TaxService.AllowCustomersToSelectTaxDisplayType = cbAllowCustomersToSelectTaxDisplayType.Checked;
                    this.TaxService.TaxDisplayType = (TaxDisplayTypeEnum)Enum.ToObject(typeof(TaxDisplayTypeEnum), int.Parse(this.ddlTaxDisplayType.SelectedItem.Value));
                    this.TaxService.DisplayTaxSuffix = cbDisplayTaxSuffix.Checked;
                    this.TaxService.DisplayTaxRates = cbDisplayTaxRates.Checked;
                    this.TaxService.HideZeroTax= cbHideZeroTax.Checked;
                    this.TaxService.HideTaxInOrderSummary = cbHideTaxInOrderSummary.Checked;
                    this.TaxService.TaxBasedOn = (TaxBasedOnEnum)Enum.ToObject(typeof(TaxBasedOnEnum), int.Parse(this.ddlTaxBasedOn.SelectedItem.Value));

                    //tax address
                    Address defaultTaxAddress = new Address();
                    defaultTaxAddress.CountryId = int.Parse(this.ddlTaxDefaultCountry.SelectedItem.Value);
                    defaultTaxAddress.StateProvinceId = int.Parse(this.ddlTaxDefaultStateProvince.SelectedItem.Value);
                    defaultTaxAddress.ZipPostalCode = txtTaxDefaultZipPostalCode.Text;
                    this.TaxService.DefaultTaxAddress = defaultTaxAddress;

                    //shipping
                    this.TaxService.ShippingIsTaxable = cbShippingIsTaxable.Checked;
                    this.TaxService.ShippingPriceIncludesTax = cbShippingPriceIncludesTax.Checked;
                    this.TaxService.ShippingTaxClassId = int.Parse(this.ddlShippingTaxClass.SelectedItem.Value);

                    //additional payment fee
                    this.TaxService.PaymentMethodAdditionalFeeIsTaxable = cbPaymentMethodAdditionalFeeIsTaxable.Checked;
                    this.TaxService.PaymentMethodAdditionalFeeIncludesTax = cbPaymentMethodAdditionalFeeIncludesTax.Checked;
                    this.TaxService.PaymentMethodAdditionalFeeTaxClassId = int.Parse(this.ddlPaymentMethodAdditionalFeeTaxClass.SelectedItem.Value);

                    //EU VAT support
                    this.TaxService.EUVatEnabled = cbEUVatEnabled.Checked;
                    this.TaxService.EUVatShopCountryId = int.Parse(this.ddlEUVatShopCountry.SelectedItem.Value);
                    this.TaxService.EUVatAllowVATExemption = cbEUVatAllowVATExemption.Checked;
                    this.TaxService.EUVatUseWebService = cbEUVatUseWebService.Checked;
                    this.TaxService.EUVatEmailAdminWhenNewVATSubmitted = cbEUVatEmailAdminWhenNewVATSubmitted.Checked;

                    //logging
                    this.CustomerActivityService.InsertActivity(
                        "EditTaxSettings",
                        GetLocaleResourceString("ActivityLog.EditTaxSettings"));

                    Response.Redirect("TaxSettings.aspx");
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
        }
Ejemplo n.º 3
0
 protected void FillCountryDropDowns(Address address)
 {
     this.ddlCountry.Items.Clear();
     List<Country> countryCollection = null;
     if (address.IsBillingAddress)
         countryCollection = CountryManager.GetAllCountriesForBilling();
     else
         countryCollection = CountryManager.GetAllCountriesForShipping();
     foreach (Country country in countryCollection)
     {
         ListItem ddlCountryItem2 = new ListItem(country.Name, country.CountryId.ToString());
         this.ddlCountry.Items.Add(ddlCountryItem2);
     }
 }
Ejemplo n.º 4
0
        public static Address ConvertFromDTO(AddressDTO input)
        {
            Address result = new Address();

            result.AddressId = Convert.ToInt32(input.addressId);
            result.FirstName = input.firstName;
            result.LastName = input.lastName;
            result.Address1 = input.address1;
            result.Address2 = input.address2;
            result.City = input.city;
            result.CountryId = 1;
            result.StateProvinceId = Convert.ToInt32(input.stateId);
            result.ZipPostalCode = input.zip;
            result.Email = input.email;

            return result;
        }
Ejemplo n.º 5
0
        public static AddressDTO ConvertToDTO(Address input)
        {
            AddressDTO result = new AddressDTO();

            result.addressId = input.AddressId.ToString();
            result.firstName = input.FirstName;
            result.lastName = input.LastName;
            result.address1 = input.Address1;
            result.address2 = input.Address2;
            result.city = input.City;
            result.stateId = input.StateProvinceId;
            result.stateText = input.StateProvinceId == 0 || input.StateProvince == null ? String.Empty : input.StateProvince.Abbreviation;
            result.zip = input.ZipPostalCode;
            result.email = input.Email;

            return result;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets a tax rate
        /// </summary>
        /// <param name="address">Address</param>
        /// <param name="TaxCategoryID">The tax category identifier</param>
        /// <returns>Tax rate</returns>
        protected decimal GetTaxRate(Address address, int TaxCategoryID)
        {
            int CountryID = 0;
            int StateProvinceID = 0;

            if (address.Country != null)
            {
                CountryID = address.Country.CountryID;
            }
            if (address.StateProvince != null)
            {
                StateProvinceID = address.StateProvince.StateProvinceID;
            }
            decimal tr = decimal.Zero;
            TaxRateCollection taxRates = TaxRateManager.GetAllTaxRates(TaxCategoryID, CountryID, StateProvinceID, address.ZipPostalCode);
            if (taxRates.Count > 0)
                tr += taxRates[0].Percentage;
            return tr;
        }
        protected void SelectAddress(Address shippingAddress)
        {
            if (shippingAddress == null)
            {
                NopContext.Current.User = CustomerManager.SetDefaultShippingAddress(NopContext.Current.User.CustomerId, 0);
                var args1 = new CheckoutStepEventArgs() { ShippingAddressSelected = true };
                OnCheckoutStepChanged(args1);
                if (!this.OnePageCheckout)
                    Response.Redirect("~/checkoutbillingaddress.aspx");
                return;
            }

            if (shippingAddress.AddressId == 0)
            {
                //check if address already exists
                var shippingAddress2 = NopContext.Current.User.ShippingAddresses.FindAddress(shippingAddress.FirstName,
                    shippingAddress.LastName, shippingAddress.PhoneNumber, shippingAddress.Email,
                    shippingAddress.FaxNumber, shippingAddress.Company,
                    shippingAddress.Address1, shippingAddress.Address2,
                    shippingAddress.City, shippingAddress.StateProvinceId, shippingAddress.ZipPostalCode,
                    shippingAddress.CountryId);

                if (shippingAddress2 != null)
                {
                    shippingAddress = shippingAddress2;
                }
                else
                {
                    shippingAddress = CustomerManager.InsertAddress(NopContext.Current.User.CustomerId, false, shippingAddress.FirstName,
                              shippingAddress.LastName, shippingAddress.PhoneNumber, shippingAddress.Email,
                              shippingAddress.FaxNumber, shippingAddress.Company, shippingAddress.Address1, shippingAddress.Address2,
                              shippingAddress.City, shippingAddress.StateProvinceId, shippingAddress.ZipPostalCode,
                              shippingAddress.CountryId, DateTime.UtcNow, DateTime.UtcNow);
                }
            }

            NopContext.Current.User = CustomerManager.SetDefaultShippingAddress(NopContext.Current.User.CustomerId, shippingAddress.AddressId);
            var args2 = new CheckoutStepEventArgs() { ShippingAddressSelected = true };
            OnCheckoutStepChanged(args2);
            if (!this.OnePageCheckout)
                Response.Redirect("~/checkoutbillingaddress.aspx");
        }
        private void SelectAddress(Address shippingAddress)
        {
            if (shippingAddress == null)
            {
                NopContext.Current.User =CustomerManager.SetDefaultShippingAddress(NopContext.Current.User.CustomerID, 0);
                return;
            }

            if (shippingAddress.AddressID == 0)
            { 
                //check if address already exists
                Address shippingAddress2 = NopContext.Current.User.ShippingAddresses.FindAddress(shippingAddress.FirstName,
                    shippingAddress.LastName, shippingAddress.PhoneNumber, shippingAddress.Email,
                    shippingAddress.FaxNumber, shippingAddress.Company, 
                    shippingAddress.Address1, shippingAddress.Address2,
                    shippingAddress.City, shippingAddress.StateProvinceID, shippingAddress.ZipPostalCode,
                    shippingAddress.CountryID);

                if (shippingAddress2 != null)
                {
                    shippingAddress = shippingAddress2;
                }
                else
                {
                    shippingAddress = CustomerManager.InsertAddress(NopContext.Current.User.CustomerID, false, shippingAddress.FirstName,
                              shippingAddress.LastName, shippingAddress.PhoneNumber, shippingAddress.Email,
                              shippingAddress.FaxNumber, shippingAddress.Company, shippingAddress.Address1, shippingAddress.Address2,
                              shippingAddress.City, shippingAddress.StateProvinceID, shippingAddress.ZipPostalCode,
                              shippingAddress.CountryID, DateTime.Now, DateTime.Now);
                }
            }

            NopContext.Current.User = CustomerManager.SetDefaultShippingAddress(NopContext.Current.User.CustomerID, shippingAddress.AddressID);

            Response.Redirect("~/CheckoutBillingAddress.aspx");
        }
        protected void btnTheSameAsShippingAddress_Click(object sender, EventArgs e)
        {
            var shippingAddress = NopContext.Current.User.ShippingAddress;
            if (shippingAddress != null && this.CustomerService.CanUseAddressAsBillingAddress(shippingAddress))
            {
                var billingAddress = new Address();
                billingAddress.AddressId = 0;
                billingAddress.CustomerId = shippingAddress.CustomerId;
                billingAddress.IsBillingAddress = true;
                billingAddress.FirstName = shippingAddress.FirstName;
                billingAddress.LastName = shippingAddress.LastName;
                billingAddress.PhoneNumber = shippingAddress.PhoneNumber;
                billingAddress.Email = shippingAddress.Email;
                billingAddress.FaxNumber = shippingAddress.FaxNumber;
                billingAddress.Company = shippingAddress.Company;
                billingAddress.Address1 = shippingAddress.Address1;
                billingAddress.Address2 = shippingAddress.Address2;
                billingAddress.City = shippingAddress.City;
                billingAddress.StateProvinceId = shippingAddress.StateProvinceId;
                billingAddress.ZipPostalCode = shippingAddress.ZipPostalCode;
                billingAddress.CountryId = shippingAddress.CountryId;
                billingAddress.CreatedOn = shippingAddress.CreatedOn;

                ctrlBillingAddress.Address = billingAddress;

                //automatically select the address for the user and move to next step. Rather than copying values then having to click next.
                //comment the line below to force a customer to click 'Next'
                SelectAddress(this.BillingAddress);
            }
            else
            {
                pnlTheSameAsShippingAddress.Visible = false;
            }
        }
 public string getCountryIfnull(Address address)
 {
     var Country = address.Country;
     if (Country != null)
         return Server.HtmlEncode(Country.Name).ToString();
     else
         return "";
 }
Ejemplo n.º 11
0
        /// <summary>
        ///  Gets available shipping options
        /// </summary>
        /// <param name="cart">Shopping cart</param>
        /// <param name="customer">Customer</param>
        /// <param name="shippingAddress">Shipping address</param>
        /// <param name="allowedShippingRateComputationMethodId">Filter by shipping rate computation method identifier; null to load shipping options of all shipping rate computation methods</param>
        /// <param name="error">Error</param>
        /// <returns>Shipping options</returns>
        public static List<ShippingOption> GetShippingOptions(ShoppingCart cart,
            Customer customer, Address shippingAddress, 
            int? allowedShippingRateComputationMethodId, ref string error)
        {
            if (cart == null)
                throw new ArgumentNullException("cart");

            var shippingOptions = new List<ShippingOption>();

            bool isFreeShipping = IsFreeShipping(cart, customer);

            //create a package
            var shipmentPackage = CreateShipmentPackage(cart, customer, shippingAddress);
            var shippingRateComputationMethods = ShippingRateComputationMethodManager.GetAllShippingRateComputationMethods(false);
            if (shippingRateComputationMethods.Count == 0)
                throw new NopException("Shipping rate computation method could not be loaded");

            //get shipping options
            foreach (var srcm in shippingRateComputationMethods)
            {
                if (allowedShippingRateComputationMethodId.HasValue &&
                    allowedShippingRateComputationMethodId.Value > 0 &&
                    allowedShippingRateComputationMethodId.Value != srcm.ShippingRateComputationMethodId)
                    continue;

                var iShippingRateComputationMethod = Activator.CreateInstance(Type.GetType(srcm.ClassName)) as IShippingRateComputationMethod;

                var shippingOptions2 = iShippingRateComputationMethod.GetShippingOptions(shipmentPackage, ref error);
                if (shippingOptions2 != null)
                {
                    foreach (var so2 in shippingOptions2)
                    {
                        so2.ShippingRateComputationMethodId = srcm.ShippingRateComputationMethodId;
                        shippingOptions.Add(so2);
                    }
                }
            }

            //no shipping options loaded
            if (shippingOptions.Count == 0 && String.IsNullOrEmpty(error))
            {
                error = "Shipping options could not be loaded";
            }

            //additional shipping charges
            decimal additionalShippingCharge = GetShoppingCartAdditionalShippingCharge(cart, customer);
            shippingOptions.ForEach(so => so.Rate += additionalShippingCharge);

            //free shipping
            if (isFreeShipping)
            {
                shippingOptions.ForEach(so => so.Rate = decimal.Zero);
            }

            return shippingOptions;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Create shipment package from shopping cart
 /// </summary>
 /// <param name="cart">Shopping cart</param>
 /// <param name="customer">Customer</param>
 /// <param name="shippingAddress">Shipping address</param>
 /// <returns>Shipment package</returns>
 protected static ShipmentPackage CreateShipmentPackage(ShoppingCart cart, 
     Customer customer, Address shippingAddress)
 {
     var shipmentPackage = new ShipmentPackage();
     shipmentPackage.Customer = customer;
     shipmentPackage.Items = new ShoppingCart();
     foreach (var sc in cart)
         if (sc.IsShipEnabled)
             shipmentPackage.Items.Add(sc);
     shipmentPackage.ShippingAddress = shippingAddress;
     //TODO set values from warehouses or shipping origin
     shipmentPackage.CountryFrom = null;
     shipmentPackage.StateProvinceFrom = null;
     shipmentPackage.ZipPostalCodeFrom = string.Empty;
     return shipmentPackage;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Resets cached values for an instance
 /// </summary>
 public void ResetCachedValues()
 {
     _customerAttributesCache = null;
     _customerRolesCache = null;
     _billingAddressCache = null;
     _shippingAddressCache = null;
     _rewardPointsHistoryCache = null;
 }
Ejemplo n.º 14
0
 /// <summary>
 ///  Gets available shipping options
 /// </summary>
 /// <param name="cart">Shopping cart</param>
 /// <param name="customer">Customer</param>
 /// <param name="shippingAddress">Shipping address</param>
 /// <param name="error">Error</param>
 /// <returns>Shipping options</returns>
 public static List<ShippingOption> GetShippingOptions(ShoppingCart cart, 
     Customer customer, Address shippingAddress, ref string error)
 {
     return GetShippingOptions(cart, customer, shippingAddress, null, ref error);
 }
        /// <summary>
        /// Updates the address
        /// </summary>
        /// <param name="address">Address</param>
        public void UpdateAddress(Address address)
        {
            if (address == null)
                throw new ArgumentNullException("address");

            address.FirstName = CommonHelper.EnsureNotNull(address.FirstName);
            address.LastName = CommonHelper.EnsureNotNull(address.LastName);
            address.PhoneNumber = CommonHelper.EnsureNotNull(address.PhoneNumber);
            address.Email = CommonHelper.EnsureNotNull(address.Email);
            address.FaxNumber = CommonHelper.EnsureNotNull(address.FaxNumber);
            address.Company = CommonHelper.EnsureNotNull(address.Company);
            address.Address1 = CommonHelper.EnsureNotNull(address.Address1);
            address.Address2 = CommonHelper.EnsureNotNull(address.Address2);
            address.City = CommonHelper.EnsureNotNull(address.City);
            address.ZipPostalCode = CommonHelper.EnsureNotNull(address.ZipPostalCode);

            address.FirstName = address.FirstName.Trim();
            address.LastName = address.LastName.Trim();
            address.PhoneNumber = address.PhoneNumber.Trim();
            address.Email = address.Email.Trim();
            address.FaxNumber = address.FaxNumber.Trim();
            address.Company = address.Company.Trim();
            address.Address1 = address.Address1.Trim();
            address.Address2 = address.Address2.Trim();
            address.City = address.City.Trim();
            address.ZipPostalCode = address.ZipPostalCode.Trim();

            address.FirstName = CommonHelper.EnsureMaximumLength(address.FirstName, 100);
            address.LastName = CommonHelper.EnsureMaximumLength(address.LastName, 100);
            address.PhoneNumber = CommonHelper.EnsureMaximumLength(address.PhoneNumber, 50);
            address.Email = CommonHelper.EnsureMaximumLength(address.Email, 255);
            address.FaxNumber = CommonHelper.EnsureMaximumLength(address.FaxNumber, 50);
            address.Company = CommonHelper.EnsureMaximumLength(address.Company, 100);
            address.Address1 = CommonHelper.EnsureMaximumLength(address.Address1, 100);
            address.Address2 = CommonHelper.EnsureMaximumLength(address.Address2, 100);
            address.City = CommonHelper.EnsureMaximumLength(address.City, 100);
            address.ZipPostalCode = CommonHelper.EnsureMaximumLength(address.ZipPostalCode, 30);

            if (!_context.IsAttached(address))
                _context.Addresses.Attach(address);

            _context.SaveChanges();
        }
        protected void SelectAddress(Address shippingAddress)
        {
            if (shippingAddress == null)
            {
                //set default shipping address
                NopContext.Current.User.ShippingAddressId = 0;
                this.CustomerService.UpdateCustomer(NopContext.Current.User);

                var args1 = new CheckoutStepEventArgs() { ShippingAddressSelected = true };
                OnCheckoutStepChanged(args1);

                return;
            }

            if (shippingAddress.AddressId == 0)
            {
                //check if address already exists
                var shippingAddress2 = NopContext.Current.User.ShippingAddresses.FindAddress(shippingAddress.FirstName,
                    shippingAddress.LastName, shippingAddress.PhoneNumber, shippingAddress.Email,
                    shippingAddress.FaxNumber, shippingAddress.Company,
                    shippingAddress.Address1, shippingAddress.Address2,
                    shippingAddress.City, shippingAddress.StateProvinceId, shippingAddress.ZipPostalCode,
                    shippingAddress.CountryId);

                if (shippingAddress2 != null)
                {
                    shippingAddress = shippingAddress2;
                }
                else
                {
                    shippingAddress.CustomerId = NopContext.Current.User.CustomerId;
                    shippingAddress.IsBillingAddress = false;
                    shippingAddress.CreatedOn = DateTime.UtcNow;
                    shippingAddress.UpdatedOn = DateTime.UtcNow;

                    this.CustomerService.InsertAddress(shippingAddress);
                }
            }

            //set default shipping address
            NopContext.Current.User.ShippingAddressId = shippingAddress.AddressId;
            this.CustomerService.UpdateCustomer(NopContext.Current.User);

            var args2 = new CheckoutStepEventArgs() { ShippingAddressSelected = true };
            OnCheckoutStepChanged(args2);
        }
Ejemplo n.º 17
0
        public void CreatedUser(object sender, EventArgs e)
        {
            var rbGenderM = (RadioButton)CreateUserWizardStep1.ContentTemplateContainer.FindControl("rbGenderM");
            var rbGenderF = (RadioButton)CreateUserWizardStep1.ContentTemplateContainer.FindControl("rbGenderF");
            var txtFirstName = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtFirstName");
            var txtLastName = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtLastName");
            var txtDateOfBirth = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtDateOfBirth");
            var UserName = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");
            var txtCompany = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtCompany");
            var txtVatNumber = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtVatNumber");
            var txtStreetAddress = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtStreetAddress");
            var txtStreetAddress2 = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtStreetAddress2");
            var txtZipPostalCode = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtZipPostalCode");
            var txtCity = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtCity");
            var txtPhoneNumber = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtPhoneNumber");
            var txtFaxNumber = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtFaxNumber");
            var ddlCountry = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlCountry");
            var ddlStateProvince = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlStateProvince");
            var cbNewsletter = (CheckBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("cbNewsletter");
            var dtDateOfBirth = (NopDatePicker)CreateUserWizardStep1.ContentTemplateContainer.FindControl("dtDateOfBirth");
            var ddlTimeZone = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlTimeZone");

            Customer customer = null;
            if (this.CustomerService.UsernamesEnabled)
            {
                customer = this.CustomerService.GetCustomerByUsername(UserName.Text.Trim());
            }
            else
            {
                customer = this.CustomerService.GetCustomerByEmail(UserName.Text.Trim());
            }
            if (this.CustomerService.FormFieldGenderEnabled)
            {
                if (rbGenderM.Checked)
                    customer.Gender = "M";
                else
                    customer.Gender = "F";
            }
            customer.FirstName = txtFirstName.Text;
            customer.LastName = txtLastName.Text;
            if (this.CustomerService.FormFieldDateOfBirthEnabled)
            {
                customer.DateOfBirth = dtDateOfBirth.SelectedDate;
                this.CustomerService.UpdateCustomer(customer);
            }
            if (this.CustomerService.FormFieldCompanyEnabled)
            {
                customer.Company = txtCompany.Text;
            }
            if (this.CustomerService.FormFieldStreetAddressEnabled)
            {
                customer.StreetAddress = txtStreetAddress.Text;
            }
            if (this.CustomerService.FormFieldStreetAddress2Enabled)
            {
                customer.StreetAddress2 = txtStreetAddress2.Text;
            }
            if (this.CustomerService.FormFieldPostCodeEnabled)
            {
                customer.ZipPostalCode = txtZipPostalCode.Text;
            }
            if (this.CustomerService.FormFieldCityEnabled)
            {
                customer.City = txtCity.Text;
            }
            if (this.CustomerService.FormFieldCountryEnabled)
            {
                customer.CountryId = int.Parse(ddlCountry.SelectedItem.Value);
            }
            if (this.CustomerService.FormFieldCountryEnabled &&
                        this.CustomerService.FormFieldStateEnabled)
            {
                customer.StateProvinceId = int.Parse(ddlStateProvince.SelectedItem.Value);
            }
            if (this.CustomerService.FormFieldPhoneEnabled)
            {
                customer.PhoneNumber = txtPhoneNumber.Text;
            }
            if (this.CustomerService.FormFieldFaxEnabled)
            {
                customer.FaxNumber = txtFaxNumber.Text;
            }
            if (this.CustomerService.FormFieldNewsletterEnabled)
            {
                customer.ReceiveNewsletter = cbNewsletter.Checked;
            }
            if (DateTimeHelper.AllowCustomersToSetTimeZone && this.CustomerService.FormFieldTimeZoneEnabled)
            {
                if (ddlTimeZone.SelectedItem != null && !String.IsNullOrEmpty(ddlTimeZone.SelectedItem.Value))
                {
                    string timeZoneId = ddlTimeZone.SelectedItem.Value;
                    customer.TimeZoneId = DateTimeHelper.FindTimeZoneById(timeZoneId).Id;
                    this.CustomerService.UpdateCustomer(customer);
                }
            }

            //set VAT number after country is saved
            if (this.TaxService.EUVatEnabled)
            {
                string vatName = string.Empty;
                string vatAddress = string.Empty;

                customer.VatNumber = txtVatNumber.Text;
                customer.VatNumberStatus = this.TaxService.GetVatNumberStatus(this.CountryService.GetCountryById(customer.CountryId),
                    customer.VatNumber, out vatName, out vatAddress);
                //admin notification
                if (!String.IsNullOrEmpty(customer.VatNumber) && this.TaxService.EUVatEmailAdminWhenNewVATSubmitted)
                {
                    this.MessageService.SendNewVATSubmittedStoreOwnerNotification(customer,
                        vatName, vatAddress, this.LocalizationManager.DefaultAdminLanguage.LanguageId);
                }
            }

            //billing address
            var billingAddress = new Address()
            {
                CustomerId = customer.CustomerId,
                IsBillingAddress = true,
                FirstName = customer.FirstName,
                LastName = customer.LastName,
                PhoneNumber = customer.PhoneNumber,
                Email = customer.Email,
                FaxNumber = customer.FaxNumber,
                Company = customer.Company,
                Address1 = customer.StreetAddress,
                Address2 = customer.StreetAddress2,
                City = customer.City,
                StateProvinceId = customer.StateProvinceId,
                ZipPostalCode = customer.ZipPostalCode,
                CountryId = customer.CountryId,
                CreatedOn = customer.RegistrationDate,
                UpdatedOn = customer.RegistrationDate
            };
            if (this.CustomerService.CanUseAddressAsBillingAddress(billingAddress))
            {
                this.CustomerService.InsertAddress(billingAddress);

                //set default billing address
                customer.BillingAddressId = billingAddress.AddressId;
                this.CustomerService.UpdateCustomer(customer);
            }

            //shipping address
            var shippingAddress = new Address()
            {
                CustomerId = customer.CustomerId,
                IsBillingAddress = false,
                FirstName = customer.FirstName,
                LastName = customer.LastName,
                PhoneNumber = customer.PhoneNumber,
                Email = customer.Email,
                FaxNumber = customer.FaxNumber,
                Company = customer.Company,
                Address1 = customer.StreetAddress,
                Address2 = customer.StreetAddress2,
                City = customer.City,
                StateProvinceId = customer.StateProvinceId,
                ZipPostalCode = customer.ZipPostalCode,
                CountryId = customer.CountryId,
                CreatedOn = customer.RegistrationDate,
                UpdatedOn = customer.RegistrationDate
            };
            if (this.CustomerService.CanUseAddressAsShippingAddress(shippingAddress))
            {
                this.CustomerService.InsertAddress(shippingAddress);

                //set default shipping address
                customer.ShippingAddressId = shippingAddress.AddressId;
                this.CustomerService.UpdateCustomer(customer);
            }

            //notification
            if (this.CustomerService.NotifyNewCustomerRegistration)
            {
                this.MessageService.SendNewCustomerNotificationMessage(customer, this.LocalizationManager.DefaultAdminLanguage.LanguageId);
            }
        }
        protected Address Save()
        {
            Address address = new Address()
            {
                CustomerId = this.CustomerId,
                IsBillingAddress = this.IsBillingAddress,
                FirstName = txtFirstName.Text,
                LastName = txtLastName.Text,
                PhoneNumber = txtPhoneNumber.Text,
                Email = txtEmail.Text,
                FaxNumber = txtFaxNumber.Text,
                Company = txtCompany.Text,
                Address1 = txtAddress1.Text,
                Address2 = txtAddress2.Text,
                City = txtCity.Text,
                StateProvinceId = int.Parse(this.ddlStateProvince.SelectedItem.Value),
                ZipPostalCode = txtZipPostalCode.Text,
                CountryId = int.Parse(this.ddlCountry.SelectedItem.Value),
                CreatedOn = DateTime.UtcNow,
                UpdatedOn = DateTime.UtcNow
            };
            this.CustomerService.InsertAddress(address);

            return address;
        }
Ejemplo n.º 19
0
        protected Address GetEnteredAddress()
        {
            Address address = new Address();
            if (this.ddlCountry.SelectedItem == null)
                throw new NopException("Countries are not populated");
            address.CountryId = int.Parse(this.ddlCountry.SelectedItem.Value);

            if (this.ddlStateProvince.SelectedItem == null)
                throw new NopException("State/Provinces are not populated");
            var stateProvince = this.StateProvinceService.GetStateProvinceById(int.Parse(this.ddlStateProvince.SelectedItem.Value));
            if (stateProvince != null && stateProvince.CountryId == address.CountryId)
                address.StateProvinceId = stateProvince.StateProvinceId;

            address.ZipPostalCode = txtZipPostalCode.Text.Trim();

            return address;
        }
Ejemplo n.º 20
0
        protected void btnTheSameAsShippingAddress_Click(object sender, EventArgs e)
        {
            var shippingAddress = NopContext.Current.User.ShippingAddress;
            if (shippingAddress != null && CustomerManager.CanUseAddressAsBillingAddress(shippingAddress))
            {
                var billingAddress = new Address();
                billingAddress.AddressId = 0;
                billingAddress.CustomerId = shippingAddress.CustomerId;
                billingAddress.IsBillingAddress = true;
                billingAddress.FirstName = shippingAddress.FirstName;
                billingAddress.LastName = shippingAddress.LastName;
                billingAddress.PhoneNumber = shippingAddress.PhoneNumber;
                billingAddress.Email = shippingAddress.Email;
                billingAddress.FaxNumber = shippingAddress.FaxNumber;
                billingAddress.Company = shippingAddress.Company;
                billingAddress.Address1 = shippingAddress.Address1;
                billingAddress.Address2 = shippingAddress.Address2;
                billingAddress.City = shippingAddress.City;
                billingAddress.StateProvinceId = shippingAddress.StateProvinceId;
                billingAddress.ZipPostalCode = shippingAddress.ZipPostalCode;
                billingAddress.CountryId = shippingAddress.CountryId;
                billingAddress.CreatedOn = shippingAddress.CreatedOn;

                ctrlBillingAddress.Address = billingAddress;
            }
            else
            {
                pnlTheSameAsShippingAddress.Visible = false;
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Gets a value indicating whether EU VAT exempt (the European Union Value Added Tax)
        /// </summary>
        /// <param name="address">Address</param>
        /// <param name="customer">Customer</param>
        /// <returns>Result</returns>
        protected static bool IsVatExempt(Address address, Customer customer)
        {
            if (!TaxManager.EUVatEnabled)
            {
                return false;
            }

            if (address == null || address.Country == null || customer == null)
            {
                return false;
            }

            if (!address.Country.SubjectToVAT)
            {
                // VAT not chargeable if shipping outside VAT zone:
                return true;
            }
            else
            {
                // VAT not chargeable if address, customer and config meet our VAT exemption requirements:
                // returns true if this customer is VAT exempt because they are shipping within the EU but outside our shop country, they have supplied a validated VAT number, and the shop is configured to allow VAT exemption
                return address.CountryId != TaxManager.EUVatShopCountryId &&
                    customer.VatNumberStatus == VatNumberStatusEnum.Valid &&
                    TaxManager.EUVatAllowVATExemption;
            }
        }
 public string getFullname(Address address)
 {
     return address.FirstName + " " + address.LastName;
 }
 public string getStateProvinceIfnull(Address address)
 {
     var stateProvince = address.StateProvince;
     if (stateProvince != null)
         return Server.HtmlEncode(stateProvince.Name).ToString();
     else
         return "";
 }
        /// <summary>
        /// Gets a value indicating whether address can be used as shipping address
        /// </summary>
        /// <param name="address">Address to validate</param>
        /// <returns>Result</returns>
        public bool CanUseAddressAsShippingAddress(Address address)
        {
            if (address == null)
                return false;

            if (address.FirstName == null)
                return false;
            if (String.IsNullOrEmpty(address.FirstName.Trim()))
                return false;

            if (address.LastName == null)
                return false;
            if (String.IsNullOrEmpty(address.LastName.Trim()))
                return false;

            if (address.PhoneNumber == null)
                return false;
            if (String.IsNullOrEmpty(address.PhoneNumber.Trim()))
                return false;

            if (address.Email == null)
                return false;
            if (String.IsNullOrEmpty(address.Email.Trim()))
                return false;

            if (address.Address1 == null)
                return false;
            if (String.IsNullOrEmpty(address.Address1.Trim()))
                return false;

            if (address.City == null)
                return false;
            if (String.IsNullOrEmpty(address.City.Trim()))
                return false;

            if (address.ZipPostalCode == null)
                return false;
            if (String.IsNullOrEmpty(address.ZipPostalCode.Trim()))
                return false;

            if (address.Country == null)
                return false;

            if (!address.Country.AllowsShipping)
                return false;

            if (address.Country.StateProvinces.Count > 0 &&
                address.StateProvince == null)
                return false;

            return true;
        }
        protected void btnTheSameAsShippingAddress_Click(object sender, EventArgs e)
        {
            var shippingAddress = NopContext.Current.User.ShippingAddress;
            if (shippingAddress != null && this.CustomerService.CanUseAddressAsBillingAddress(shippingAddress))
            {
                var billingAddress = new Address();
                billingAddress.AddressId = 0;
                billingAddress.CustomerId = shippingAddress.CustomerId;
                billingAddress.IsBillingAddress = true;
                billingAddress.FirstName = shippingAddress.FirstName;
                billingAddress.LastName = shippingAddress.LastName;
                billingAddress.PhoneNumber = shippingAddress.PhoneNumber;
                billingAddress.Email = shippingAddress.Email;
                billingAddress.FaxNumber = shippingAddress.FaxNumber;
                billingAddress.Company = shippingAddress.Company;
                billingAddress.Address1 = shippingAddress.Address1;
                billingAddress.Address2 = shippingAddress.Address2;
                billingAddress.City = shippingAddress.City;
                billingAddress.StateProvinceId = shippingAddress.StateProvinceId;
                billingAddress.ZipPostalCode = shippingAddress.ZipPostalCode;
                billingAddress.CountryId = shippingAddress.CountryId;
                billingAddress.CreatedOn = shippingAddress.CreatedOn;

                ctrlBillingAddress.Address = billingAddress;

                //automatically select the address for the user and move to next step. Rather than copying values then having to click next.
                //comment the line below to force a customer to click 'Next'
                SelectAddress(this.BillingAddress);

                //payment methods
                //don't bother searching for a payment method.
                //we know which one we're going to use Paypal Peer to Peer.

                var paymentMethod = this.PaymentService.GetPaymentMethodBySystemKeyword("PAYPALPEER");
                if (paymentMethod != null && paymentMethod.IsActive)
                {
                    //save selected payment methods
                    NopContext.Current.User.LastPaymentMethodId = paymentMethod.PaymentMethodId;
                    this.CustomerService.UpdateCustomer(NopContext.Current.User);
                    var args2 = new CheckoutStepEventArgs() { PaymentMethodSelected = true };
                    OnCheckoutStepChanged(args2);
                    if (!this.OnePageCheckout)
                        Response.Redirect("~/checkoutpaymentinfo.aspx");
                }

                //paymentinfo stuff.
                this.PaymentInfo = this.GetPaymentInfo();
                var args1 = new CheckoutStepEventArgs() { PaymentInfoEntered = true };
                OnCheckoutStepChanged(args1);
                if (!this.OnePageCheckout)
                    Response.Redirect("~/checkoutconfirm.aspx");

            }
            else
            {
                pnlTheSameAsShippingAddress.Visible = false;
            }
        }
        //将当前用户信息 显示为 收货人地址栏目里
        public void showUserShipping()
        {
            var shippingAddress = NopContext.Current.User;
            if (shippingAddress != null)
            {
                var billingAddress = new Address();
                billingAddress.AddressId = 0;
                billingAddress.CustomerId = shippingAddress.CustomerId;
                billingAddress.IsBillingAddress = true;
                billingAddress.FirstName = shippingAddress.FirstName;
                billingAddress.LastName = shippingAddress.LastName;
                billingAddress.PhoneNumber = shippingAddress.PhoneNumber;
                billingAddress.Email = shippingAddress.Email;
                billingAddress.FaxNumber = shippingAddress.FaxNumber;
                billingAddress.Company = shippingAddress.Company;
                billingAddress.Address1 = shippingAddress.StreetAddress;
                billingAddress.Address2 = shippingAddress.StreetAddress2;
                billingAddress.City = shippingAddress.City;
                billingAddress.StateProvinceId = shippingAddress.StateProvinceId;
                billingAddress.ZipPostalCode = shippingAddress.ZipPostalCode;
                billingAddress.CountryId = shippingAddress.CountryId;
                billingAddress.CreatedOn = DateTime.Now;

                ctrlShippingAddress.Address = billingAddress;
            }
        }
        public AddressResponse SaveAddress(AddressRequest request)
        {
            AddressResponse response = new AddressResponse();
            CustomerService cs = IoC.Resolve<NopSolutions.NopCommerce.BusinessLogic.CustomerManagement.CustomerService>();
            Address addy = Mapper.ConvertFromDTO(request.address);
            response.billing = request.Billing.ToLower() == "billing" ? 1 : 0;

            if (request == null){
                // no request object is probably an error.
                return response;
            }
            if (request.address == null){
                // no address object is probably an error.
                return response;
            }

            Customer cust = cs.GetCustomerById(request.CustomerId);

            //if address already has an id, be sure to update instead of insert.
            if (request.address.addressId == string.Empty || request.address.addressId == "0" || request.address.addressId == null)
            {
                //No ID found.  It must be an insert.

                //assign values for insert.

                addy.CustomerId = request.CustomerId;
                addy.CreatedOn = System.DateTime.Now;
                addy.UpdatedOn = System.DateTime.Now;
                addy.Email = cust.Email;

                addy.IsBillingAddress = request.Billing.ToLower() == "billing" ? true : false;

                //perform insert.
                cs.InsertAddress(addy);
            }
            else
            {
                //addressid was found. So we need to retreive it in order to get it.
                addy = cs.GetAddressById(Convert.ToInt32(request.address.addressId));
                if (addy.Email == "*****@*****.**")
                {
                    addy.Email = cust.Email;
                    cs.UpdateAddress(addy);
                }
            }

            //then update the user.
            if (cust != null)
            {
                if (request.Billing.ToLower() == "billing")
                {
                    //billing
                    if (request.UseShippingAsBilling == "1")
                    {
                        //yes, then save the addy as a new address.

                        Address ad = new Address();
                        ad.FirstName = addy.FirstName;
                        ad.LastName = addy.LastName;

                        ad.Address1 = addy.Address1;
                        ad.Address2 = addy.Address2;
                        ad.City = addy.City;
                        ad.StateProvinceId = addy.StateProvinceId;
                        ad.ZipPostalCode = addy.ZipPostalCode;
                        ad.CountryId = addy.CountryId;
                        ad.Email = addy.Email;

                        ad.CustomerId = request.CustomerId;
                        ad.CreatedOn = System.DateTime.Now;
                        ad.UpdatedOn = System.DateTime.Now;
                        ad.IsBillingAddress = true;

                        cs.InsertAddress(ad);

                        cust.BillingAddressId = ad.AddressId;
                        // do this because down below we'll add it to the
                        // return collection for update on the client.
                        addy = ad;
                    }
                    else
                    {
                        //no do not do shipping as billing.
                        //so do regular billing address update.
                        addy.IsBillingAddress = true;
                        cust.BillingAddressId = addy.AddressId;
                    }

                }
                else
                {
                    //shipping
                    cust.ShippingAddressId = addy.AddressId;
                }

                cs.UpdateCustomer(cust);
                response.success = 1;
                if (response.addresses == null)
                {
                    response.addresses = new List<AddressDTO>();
                }
                response.addresses.Add(Mapper.ConvertToDTO(addy));
            }
            else
            {
                //customer's address was not updated for the user.
                response.success = 0;
            }
            return response;
        }
        protected void SelectAddress(Address billingAddress)
        {
            if (billingAddress == null)
            {
                //set default billing address
                NopContext.Current.User.BillingAddressId = 0;
                this.CustomerService.UpdateCustomer(NopContext.Current.User);
                var args1 = new CheckoutStepEventArgs() { BillingAddressSelected = true };
                OnCheckoutStepChanged(args1);
                if (!this.OnePageCheckout)
                    Response.Redirect("~/checkoutshippingmethod.aspx");
                return;
            }

            if (billingAddress.AddressId == 0)
            {
                //check if address already exists
                var billingAddress2 = NopContext.Current.User.BillingAddresses.FindAddress(billingAddress.FirstName,
                     billingAddress.LastName, billingAddress.PhoneNumber, billingAddress.Email,
                     billingAddress.FaxNumber, billingAddress.Company,
                     billingAddress.Address1, billingAddress.Address2,
                     billingAddress.City, billingAddress.StateProvinceId, billingAddress.ZipPostalCode,
                     billingAddress.CountryId);

                if (billingAddress2 != null)
                {
                    billingAddress = billingAddress2;
                }
                else
                {
                    billingAddress.CustomerId = NopContext.Current.User.CustomerId;
                    billingAddress.IsBillingAddress = true;
                    billingAddress.CreatedOn = DateTime.UtcNow;
                    billingAddress.UpdatedOn = DateTime.UtcNow;

                    this.CustomerService.InsertAddress(billingAddress);
                }
            }
            //set default billing address
            NopContext.Current.User.BillingAddressId = billingAddress.AddressId;
            this.CustomerService.UpdateCustomer(NopContext.Current.User);
            var args2 = new CheckoutStepEventArgs() { BillingAddressSelected = true };
            OnCheckoutStepChanged(args2);
            if (!this.OnePageCheckout)
                Response.Redirect("~/checkoutshippingmethod.aspx");
        }
Ejemplo n.º 29
0
        public void CreatedUser(object sender, EventArgs e)
        {
            var rbGenderM = (RadioButton)CreateUserWizardStep1.ContentTemplateContainer.FindControl("rbGenderM");
            var rbGenderF = (RadioButton)CreateUserWizardStep1.ContentTemplateContainer.FindControl("rbGenderF");
            var txtFirstName = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtFirstName");
            var txtLastName = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtLastName");
            var txtDateOfBirth = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtDateOfBirth");
            var UserName = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");
            var txtCompany = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtCompany");
            var txtVatNumber = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtVatNumber");
            var txtStreetAddress = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtStreetAddress");
            var txtStreetAddress2 = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtStreetAddress2");
            var txtZipPostalCode = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtZipPostalCode");
            var txtCity = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtCity");
            var txtPhoneNumber = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtPhoneNumber");
            var txtFaxNumber = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("txtFaxNumber");
            var ddlCountry = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlCountry");
            var ddlStateProvince = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlStateProvince");
            var cbNewsletter = (CheckBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("cbNewsletter");
            var dtDateOfBirth = (NopDatePicker)CreateUserWizardStep1.ContentTemplateContainer.FindControl("dtDateOfBirth");
            
            Customer customer = null;
            if (CustomerManager.UsernamesEnabled)
            {
                customer = CustomerManager.GetCustomerByUsername(UserName.Text.Trim());
            }
            else
            {
                customer = CustomerManager.GetCustomerByEmail(UserName.Text.Trim());
            }
            if (CustomerManager.FormFieldGenderEnabled)
            {
                if (rbGenderM.Checked)
                    customer.Gender = "M";
                else
                    customer.Gender = "F";
            }
            customer.FirstName = txtFirstName.Text;
            customer.LastName = txtLastName.Text;
            if (CustomerManager.FormFieldDateOfBirthEnabled)
            {
                customer = CustomerManager.SetCustomerDateOfBirth(customer.CustomerId, dtDateOfBirth.SelectedDate);
            }
            if (CustomerManager.FormFieldCompanyEnabled)
            {
                customer.Company = txtCompany.Text;
            }
            if (CustomerManager.FormFieldStreetAddressEnabled)
            {
                customer.StreetAddress = txtStreetAddress.Text;
            }
            if (CustomerManager.FormFieldStreetAddress2Enabled)
            {
                customer.StreetAddress2 = txtStreetAddress2.Text;
            }
            if (CustomerManager.FormFieldPostCodeEnabled)
            {
                customer.ZipPostalCode = txtZipPostalCode.Text;
            }
            if (CustomerManager.FormFieldCityEnabled)
            {
                customer.City = txtCity.Text;
            }
            if (CustomerManager.FormFieldCountryEnabled)
            {
                customer.CountryId = int.Parse(ddlCountry.SelectedItem.Value);
            }
            if (CustomerManager.FormFieldCountryEnabled &&
                        CustomerManager.FormFieldStateEnabled)
            {
                customer.StateProvinceId = int.Parse(ddlStateProvince.SelectedItem.Value);
            }
            if (CustomerManager.FormFieldPhoneEnabled)
            {
                customer.PhoneNumber = txtPhoneNumber.Text;
            }
            if (CustomerManager.FormFieldFaxEnabled)
            {
                customer.FaxNumber = txtFaxNumber.Text;
            }
            if (CustomerManager.FormFieldNewsletterEnabled)
            {
                customer.ReceiveNewsletter = cbNewsletter.Checked;
            }

            //set VAT number after country is saved
            if (TaxManager.EUVatEnabled)
            {
                customer.VatNumber = txtVatNumber.Text;
                customer.VatNumberStatus = TaxManager.GetVatNumberStatus(CountryManager.GetCountryById(customer.CountryId), customer.VatNumber);
                //admin notification
                if (!String.IsNullOrEmpty(customer.VatNumber) && TaxManager.EUVatEmailAdminWhenNewVATSubmitted)
                {
                    MessageManager.SendNewVATSubmittedStoreOwnerNotification(customer, LocalizationManager.DefaultAdminLanguage.LanguageId);
                }
            }

            //billing address
            var billingAddress = new Address()
            {
                CustomerId = customer.CustomerId,
                IsBillingAddress = true,
                FirstName = customer.FirstName,
                LastName = customer.LastName,
                PhoneNumber = customer.PhoneNumber,
                Email = customer.Email,
                FaxNumber = customer.FaxNumber,
                Company = customer.Company,
                Address1 = customer.StreetAddress,
                Address2 = customer.StreetAddress2,
                City = customer.City,
                StateProvinceId = customer.StateProvinceId,
                ZipPostalCode = customer.ZipPostalCode,
                CountryId = customer.CountryId,
                CreatedOn = customer.RegistrationDate
            };
            if (CustomerManager.CanUseAddressAsBillingAddress(billingAddress))
            {
                billingAddress = CustomerManager.InsertAddress(billingAddress.CustomerId, billingAddress.IsBillingAddress,
                    billingAddress.FirstName, billingAddress.LastName, billingAddress.PhoneNumber,
                    billingAddress.Email, billingAddress.FaxNumber, billingAddress.Company,
                    billingAddress.Address1, billingAddress.Address2,
                    billingAddress.City, billingAddress.StateProvinceId,
                    billingAddress.ZipPostalCode, billingAddress.CountryId, DateTime.UtcNow, DateTime.UtcNow);
                customer = CustomerManager.SetDefaultBillingAddress(customer.CustomerId, billingAddress.AddressId);
            }

            //shipping address
            var shippingAddress = new Address()
            {
                CustomerId = customer.CustomerId,
                IsBillingAddress = false,
                FirstName = customer.FirstName,
                LastName = customer.LastName,
                PhoneNumber = customer.PhoneNumber,
                Email = customer.Email,
                FaxNumber = customer.FaxNumber,
                Company = customer.Company,
                Address1 = customer.StreetAddress,
                Address2 = customer.StreetAddress2,
                City = customer.City,
                StateProvinceId = customer.StateProvinceId,
                ZipPostalCode = customer.ZipPostalCode,
                CountryId = customer.CountryId,
                CreatedOn = customer.RegistrationDate
            };
            if (CustomerManager.CanUseAddressAsShippingAddress(shippingAddress))
            {
                shippingAddress = CustomerManager.InsertAddress(shippingAddress.CustomerId, shippingAddress.IsBillingAddress,
                    shippingAddress.FirstName, shippingAddress.LastName, shippingAddress.PhoneNumber,
                    shippingAddress.Email, shippingAddress.FaxNumber, shippingAddress.Company,
                    shippingAddress.Address1, shippingAddress.Address2,
                    shippingAddress.City, shippingAddress.StateProvinceId,
                    shippingAddress.ZipPostalCode, shippingAddress.CountryId, DateTime.UtcNow, DateTime.UtcNow);
                customer = CustomerManager.SetDefaultShippingAddress(customer.CustomerId, shippingAddress.AddressId);
            }
        }
        private void processNewOrderNotification(string xmlData)
        {
            try
            {
                NewOrderNotification newOrderNotification = (NewOrderNotification)EncodeHelper.Deserialize(xmlData, typeof(NewOrderNotification));
                string googleOrderNumber = newOrderNotification.googleordernumber;

                XmlNode  CustomerInfo       = newOrderNotification.shoppingcart.merchantprivatedata.Any[0];
                int      CustomerID         = Convert.ToInt32(CustomerInfo.Attributes["CustomerID"].Value);
                int      CustomerLanguageID = Convert.ToInt32(CustomerInfo.Attributes["CustomerLanguageID"].Value);
                int      CustomerCurrencyID = Convert.ToInt32(CustomerInfo.Attributes["CustomerCurrencyID"].Value);
                Customer customer           = CustomerManager.GetCustomerById(CustomerID);

                NopSolutions.NopCommerce.BusinessLogic.Orders.ShoppingCart Cart = ShoppingCartManager.GetCustomerShoppingCart(customer.CustomerId, ShoppingCartTypeEnum.ShoppingCart);

                if (customer == null)
                {
                    logMessage("Could not load a customer");
                    return;
                }

                NopContext.Current.User = customer;

                if (Cart.Count == 0)
                {
                    logMessage("Cart is empty");
                    return;
                }

                //validate cart
                foreach (NopSolutions.NopCommerce.BusinessLogic.Orders.ShoppingCartItem sci in Cart)
                {
                    bool ok = false;
                    foreach (Item item in newOrderNotification.shoppingcart.items)
                    {
                        if (!String.IsNullOrEmpty(item.merchantitemid))
                        {
                            if ((Convert.ToInt32(item.merchantitemid) == sci.ShoppingCartItemId) && (item.quantity == sci.Quantity))
                            {
                                ok = true;
                                break;
                            }
                        }
                    }

                    if (!ok)
                    {
                        logMessage(string.Format("Shopping Cart item has been changed. {0}. {1}", sci.ShoppingCartItemId, sci.Quantity));
                        return;
                    }
                }


                string[] billingFullname  = newOrderNotification.buyerbillingaddress.contactname.Trim().Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
                string   billingFirstName = billingFullname[0];
                string   billingLastName  = string.Empty;
                if (billingFullname.Length > 1)
                {
                    billingLastName = billingFullname[1];
                }
                string        billingEmail           = newOrderNotification.buyerbillingaddress.email.Trim();
                string        billingAddress1        = newOrderNotification.buyerbillingaddress.address1.Trim();
                string        billingAddress2        = newOrderNotification.buyerbillingaddress.address2.Trim();
                string        billingPhoneNumber     = newOrderNotification.buyerbillingaddress.phone.Trim();
                string        billingCity            = newOrderNotification.buyerbillingaddress.city.Trim();
                int           billingStateProvinceID = 0;
                StateProvince billingStateProvince   = StateProvinceManager.GetStateProvinceByAbbreviation(newOrderNotification.buyerbillingaddress.region.Trim());
                if (billingStateProvince != null)
                {
                    billingStateProvinceID = billingStateProvince.StateProvinceId;
                }
                string  billingZipPostalCode = newOrderNotification.buyerbillingaddress.postalcode.Trim();
                int     billingCountryID     = 0;
                Country billingCountry       = CountryManager.GetCountryByTwoLetterIsoCode(newOrderNotification.buyerbillingaddress.countrycode.Trim());
                if (billingCountry != null)
                {
                    billingCountryID = billingCountry.CountryId;
                }

                NopSolutions.NopCommerce.BusinessLogic.CustomerManagement.Address BillingAddress = customer.BillingAddresses.FindAddress(
                    billingFirstName, billingLastName, billingPhoneNumber,
                    billingEmail, string.Empty, string.Empty, billingAddress1, billingAddress2, billingCity,
                    billingStateProvinceID, billingZipPostalCode, billingCountryID);

                if (BillingAddress == null)
                {
                    BillingAddress = CustomerManager.InsertAddress(CustomerID, true,
                                                                   billingFirstName, billingLastName, billingPhoneNumber, billingEmail,
                                                                   string.Empty, string.Empty, billingAddress1,
                                                                   billingAddress2, billingCity,
                                                                   billingStateProvinceID, billingZipPostalCode,
                                                                   billingCountryID, DateTime.Now, DateTime.Now);
                }
                customer = CustomerManager.SetDefaultBillingAddress(customer.CustomerId, BillingAddress.AddressId);

                NopSolutions.NopCommerce.BusinessLogic.CustomerManagement.Address ShippingAddress = null;
                customer.LastShippingOption = null;
                bool shoppingCartRequiresShipping = ShippingManager.ShoppingCartRequiresShipping(Cart);
                if (shoppingCartRequiresShipping)
                {
                    string[] shippingFullname  = newOrderNotification.buyershippingaddress.contactname.Trim().Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
                    string   shippingFirstName = shippingFullname[0];
                    string   shippingLastName  = string.Empty;
                    if (shippingFullname.Length > 1)
                    {
                        shippingLastName = shippingFullname[1];
                    }
                    string        shippingEmail           = newOrderNotification.buyershippingaddress.email.Trim();
                    string        shippingAddress1        = newOrderNotification.buyershippingaddress.address1.Trim();
                    string        shippingAddress2        = newOrderNotification.buyershippingaddress.address2.Trim();
                    string        shippingPhoneNumber     = newOrderNotification.buyershippingaddress.phone.Trim();
                    string        shippingCity            = newOrderNotification.buyershippingaddress.city.Trim();
                    int           shippingStateProvinceID = 0;
                    StateProvince shippingStateProvince   = StateProvinceManager.GetStateProvinceByAbbreviation(newOrderNotification.buyershippingaddress.region.Trim());
                    if (shippingStateProvince != null)
                    {
                        shippingStateProvinceID = shippingStateProvince.StateProvinceId;
                    }
                    int     shippingCountryID     = 0;
                    string  shippingZipPostalCode = newOrderNotification.buyershippingaddress.postalcode.Trim();
                    Country shippingCountry       = CountryManager.GetCountryByTwoLetterIsoCode(newOrderNotification.buyershippingaddress.countrycode.Trim());
                    if (shippingCountry != null)
                    {
                        shippingCountryID = shippingCountry.CountryId;
                    }

                    ShippingAddress = customer.ShippingAddresses.FindAddress(
                        shippingFirstName, shippingLastName, shippingPhoneNumber,
                        shippingEmail, string.Empty, string.Empty,
                        shippingAddress1, shippingAddress2, shippingCity,
                        shippingStateProvinceID, shippingZipPostalCode, shippingCountryID);
                    if (ShippingAddress == null)
                    {
                        ShippingAddress = CustomerManager.InsertAddress(CustomerID, false,
                                                                        shippingFirstName, shippingLastName, shippingPhoneNumber, shippingEmail,
                                                                        string.Empty, string.Empty, shippingAddress1,
                                                                        shippingAddress2, shippingCity, shippingStateProvinceID,
                                                                        shippingZipPostalCode, shippingCountryID,
                                                                        DateTime.Now, DateTime.Now);
                    }

                    customer = CustomerManager.SetDefaultShippingAddress(customer.CustomerId, ShippingAddress.AddressId);

                    string  shippingMethod = string.Empty;
                    decimal shippingCost   = decimal.Zero;
                    if (newOrderNotification.orderadjustment != null &&
                        newOrderNotification.orderadjustment.shipping != null &&
                        newOrderNotification.orderadjustment.shipping.Item != null)
                    {
                        FlatRateShippingAdjustment ShippingMethod = (FlatRateShippingAdjustment)newOrderNotification.orderadjustment.shipping.Item;
                        shippingMethod = ShippingMethod.shippingname;
                        shippingCost   = ShippingMethod.shippingcost.Value;


                        ShippingOption shippingOption = new ShippingOption();
                        shippingOption.Name         = shippingMethod;
                        shippingOption.Rate         = shippingCost;
                        customer.LastShippingOption = shippingOption;
                    }
                }

                //customer.LastCalculatedTax = decimal.Zero;

                PaymentMethod googleCheckoutPaymentMethod = PaymentMethodManager.GetPaymentMethodBySystemKeyword("GoogleCheckout");

                PaymentInfo paymentInfo = new PaymentInfo();
                paymentInfo.PaymentMethodId   = googleCheckoutPaymentMethod.PaymentMethodId;
                paymentInfo.BillingAddress    = BillingAddress;
                paymentInfo.ShippingAddress   = ShippingAddress;
                paymentInfo.CustomerLanguage  = LanguageManager.GetLanguageById(CustomerLanguageID);
                paymentInfo.CustomerCurrency  = CurrencyManager.GetCurrencyById(CustomerCurrencyID);
                paymentInfo.GoogleOrderNumber = googleOrderNumber;
                int    orderID = 0;
                string result  = OrderManager.PlaceOrder(paymentInfo, customer, out orderID);
                if (!String.IsNullOrEmpty(result))
                {
                    logMessage("new-order-notification received. CreateOrder() error: Order Number " + orderID + ". " + result);
                    return;
                }

                Order order = OrderManager.GetOrderById(orderID);
                logMessage("new-order-notification received and saved: Order Number " + orderID);
            }
            catch (Exception exc)
            {
                logMessage("processNewOrderNotification Exception: " + exc.Message + ": " + exc.StackTrace);
            }
        }
        protected void btnSaveShippingAddress_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    var inputedAddress = this.Address;
                    inputedAddress.CustomerId = NopContext.Current.User.CustomerId;
                    inputedAddress.IsBillingAddress = false;
                    inputedAddress.CreatedOn = DateTime.UtcNow;
                    inputedAddress.UpdatedOn = DateTime.UtcNow;
                    this.CustomerService.InsertAddress(inputedAddress);
                    ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + "Saved Successfully" + "');", true);

                    pnlEditShippingAddress.Visible = false;
                    BindData();
                    BindBillingData();
                    BindShippingInfoData();
                    SummaryBindData();
                    OrderTotalCalculation();

                    if (inputedAddress != null && NopContext.Current.User != null)
                    {
                        var prevAddress = this.CustomerService.GetAddressById(inputedAddress.AddressId);
                        if (prevAddress.CustomerId != NopContext.Current.User.CustomerId)
                            return;
                    }

                    SelectAddress(inputedAddress);
                }
                catch (Exception exc)
                {
                }
                try
                {

                    var shippingAddress = NopContext.Current.User.ShippingAddress;
                    if (shippingAddress != null && this.CustomerService.CanUseAddressAsBillingAddress(shippingAddress))
                    {
                        var billingAddress = new Address();
                        billingAddress.AddressId = 0;
                        billingAddress.CustomerId = shippingAddress.CustomerId;
                        billingAddress.IsBillingAddress = true;
                        billingAddress.FirstName = shippingAddress.FirstName;
                        billingAddress.LastName = shippingAddress.LastName;
                        billingAddress.PhoneNumber = shippingAddress.PhoneNumber;
                        billingAddress.Email = shippingAddress.Email;
                        billingAddress.FaxNumber = shippingAddress.FaxNumber;
                        billingAddress.Company = shippingAddress.Company;
                        billingAddress.Address1 = shippingAddress.Address1;
                        billingAddress.Address2 = shippingAddress.Address2;
                        billingAddress.City = shippingAddress.City;
                        billingAddress.StateProvinceId = shippingAddress.StateProvinceId;
                        billingAddress.ZipPostalCode = shippingAddress.ZipPostalCode;
                        billingAddress.CountryId = shippingAddress.CountryId;
                        billingAddress.CreatedOn = shippingAddress.CreatedOn;

                        this.BillAddress = billingAddress;

                        //automatically select the address for the user and move to next step. Rather than copying values then having to click next.
                        //comment the line below to force a customer to click 'Next'
                        SelectBillingAddress(this.BillingAddress);
                    }
                    else
                    {
                        pnlTheSameAsShippingAddress.Visible = false;
                    }
                }
                catch (Exception ex)
                {

                }
                Response.Redirect("~/SinglePageGuestCheckOut.aspx");
            }
        }