コード例 #1
0
        public static Address ToEntity(this VendorAddressModel model, Address destination, bool trimFields = true)
        {
            if (model == null)
            {
                return(destination);
            }

            if (trimFields)
            {
                if (model.Company != null)
                {
                    model.Company = model.Company.Trim();
                }
                if (model.City != null)
                {
                    model.City = model.City.Trim();
                }
                if (model.Address1 != null)
                {
                    model.Address1 = model.Address1.Trim();
                }
                if (model.Address2 != null)
                {
                    model.Address2 = model.Address2.Trim();
                }
                if (model.ZipPostalCode != null)
                {
                    model.ZipPostalCode = model.ZipPostalCode.Trim();
                }
                if (model.PhoneNumber != null)
                {
                    model.PhoneNumber = model.PhoneNumber.Trim();
                }
                if (model.FaxNumber != null)
                {
                    model.FaxNumber = model.FaxNumber.Trim();
                }
            }
            destination.Company         = model.Company;
            destination.CountryId       = !String.IsNullOrEmpty(model.CountryId) ? model.CountryId : "";
            destination.StateProvinceId = !String.IsNullOrEmpty(model.StateProvinceId) ? model.StateProvinceId : "";
            destination.City            = model.City;
            destination.Address1        = model.Address1;
            destination.Address2        = model.Address2;
            destination.ZipPostalCode   = model.ZipPostalCode;
            destination.PhoneNumber     = model.PhoneNumber;
            destination.FaxNumber       = model.FaxNumber;

            return(destination);
        }
コード例 #2
0
        public virtual void PrepareVendorAddressModel(VendorAddressModel model,
                                                      Address address, bool excludeProperties,
                                                      Func <IList <Country> > loadCountries = null,
                                                      bool prePopulateWithCustomerFields    = false,
                                                      Customer customer             = null,
                                                      VendorSettings vendorSettings = null)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            if (!excludeProperties && address != null)
            {
                model.Company   = address.Company;
                model.CountryId = address.CountryId;
                Country country = null;
                if (!String.IsNullOrEmpty(address.CountryId))
                {
                    country = _countryService.GetCountryById(address.CountryId);
                }
                model.CountryName = country != null?country.GetLocalized(x => x.Name) : null;

                model.StateProvinceId = address.StateProvinceId;
                StateProvince state = null;
                if (!String.IsNullOrEmpty(address.StateProvinceId))
                {
                    state = _stateProvinceService.GetStateProvinceById(address.StateProvinceId);
                }
                model.StateProvinceName = state != null?state.GetLocalized(x => x.Name) : null;

                model.City          = address.City;
                model.Address1      = address.Address1;
                model.Address2      = address.Address2;
                model.ZipPostalCode = address.ZipPostalCode;
                model.PhoneNumber   = address.PhoneNumber;
                model.FaxNumber     = address.FaxNumber;
            }

            if (address == null && prePopulateWithCustomerFields)
            {
                if (customer == null)
                {
                    throw new Exception("Customer cannot be null when prepopulating an address");
                }
                model.Company       = customer.GetAttribute <string>(SystemCustomerAttributeNames.Company);
                model.Address1      = customer.GetAttribute <string>(SystemCustomerAttributeNames.StreetAddress);
                model.Address2      = customer.GetAttribute <string>(SystemCustomerAttributeNames.StreetAddress2);
                model.ZipPostalCode = customer.GetAttribute <string>(SystemCustomerAttributeNames.ZipPostalCode);
                model.City          = customer.GetAttribute <string>(SystemCustomerAttributeNames.City);
                model.PhoneNumber   = customer.GetAttribute <string>(SystemCustomerAttributeNames.Phone);
                model.FaxNumber     = customer.GetAttribute <string>(SystemCustomerAttributeNames.Fax);

                if (vendorSettings.CountryEnabled)
                {
                    model.CountryId = customer.GetAttribute <string>(SystemCustomerAttributeNames.CountryId);
                }

                if (vendorSettings.StateProvinceEnabled)
                {
                    model.StateProvinceId = customer.GetAttribute <string>(SystemCustomerAttributeNames.StateProvinceId);
                }
            }

            //countries and states
            if (vendorSettings.CountryEnabled && loadCountries != null)
            {
                model.AvailableCountries.Add(new SelectListItem {
                    Text = _localizationService.GetResource("Address.SelectCountry"), Value = ""
                });
                foreach (var c in loadCountries())
                {
                    model.AvailableCountries.Add(new SelectListItem
                    {
                        Text     = c.GetLocalized(x => x.Name),
                        Value    = c.Id.ToString(),
                        Selected = c.Id == model.CountryId
                    });
                }

                if (vendorSettings.StateProvinceEnabled)
                {
                    var languageId = _workContext.WorkingLanguage.Id;
                    var states     = _stateProvinceService
                                     .GetStateProvincesByCountryId(!String.IsNullOrEmpty(model.CountryId) ? model.CountryId : "", languageId)
                                     .ToList();
                    if (states.Any())
                    {
                        model.AvailableStates.Add(new SelectListItem {
                            Text = _localizationService.GetResource("Address.SelectState"), Value = ""
                        });

                        foreach (var s in states)
                        {
                            model.AvailableStates.Add(new SelectListItem
                            {
                                Text     = s.GetLocalized(x => x.Name),
                                Value    = s.Id.ToString(),
                                Selected = (s.Id == model.StateProvinceId)
                            });
                        }
                    }
                    else
                    {
                        bool anyCountrySelected = model.AvailableCountries.Any(x => x.Selected);
                        model.AvailableStates.Add(new SelectListItem
                        {
                            Text  = _localizationService.GetResource(anyCountrySelected ? "Address.OtherNonUS" : "Address.SelectState"),
                            Value = ""
                        });
                    }
                }
            }

            //form fields
            model.CompanyEnabled         = vendorSettings.CompanyEnabled;
            model.CompanyRequired        = vendorSettings.CompanyRequired;
            model.StreetAddressEnabled   = vendorSettings.StreetAddressEnabled;
            model.StreetAddressRequired  = vendorSettings.StreetAddressRequired;
            model.StreetAddress2Enabled  = vendorSettings.StreetAddress2Enabled;
            model.StreetAddress2Required = vendorSettings.StreetAddress2Required;
            model.ZipPostalCodeEnabled   = vendorSettings.ZipPostalCodeEnabled;
            model.ZipPostalCodeRequired  = vendorSettings.ZipPostalCodeRequired;
            model.CityEnabled            = vendorSettings.CityEnabled;
            model.CityRequired           = vendorSettings.CityRequired;
            model.CountryEnabled         = vendorSettings.CountryEnabled;
            model.StateProvinceEnabled   = vendorSettings.StateProvinceEnabled;
            model.PhoneEnabled           = vendorSettings.PhoneEnabled;
            model.PhoneRequired          = vendorSettings.PhoneRequired;
            model.FaxEnabled             = vendorSettings.FaxEnabled;
            model.FaxRequired            = vendorSettings.FaxRequired;
        }
コード例 #3
0
 public VendorModel()
 {
     Products = new List <ProductOverviewModel>();
     PagingFilteringContext = new CatalogPagingFilteringModel();
     Address = new VendorAddressModel();
 }