public static void ToAddress(this Address amazonAddress, SmartStore.Core.Domain.Common.Address address, ICountryService countryService, IStateProvinceService stateProvinceService, out bool countryAllowsShipping, out bool countryAllowsBilling) { countryAllowsShipping = countryAllowsBilling = true; if (amazonAddress.IsSetName()) { address.ToFirstAndLastName(amazonAddress.Name); } if (amazonAddress.IsSetAddressLine1()) { address.Address1 = amazonAddress.AddressLine1.TrimSafe().Truncate(4000); } if (amazonAddress.IsSetAddressLine2()) { address.Address2 = amazonAddress.AddressLine2.TrimSafe().Truncate(4000); } if (amazonAddress.IsSetAddressLine3()) { address.Address2 = address.Address2.Grow(amazonAddress.AddressLine3.TrimSafe(), ", ").Truncate(4000); } // normalize if (address.Address1.IsEmpty() && address.Address2.HasValue()) { address.Address1 = address.Address2; address.Address2 = null; } else if (address.Address1.HasValue() && address.Address1 == address.Address2) { address.Address2 = null; } if (amazonAddress.IsSetCity()) { address.City = amazonAddress.City.TrimSafe().Truncate(4000); } if (amazonAddress.IsSetPostalCode()) { address.ZipPostalCode = amazonAddress.PostalCode.TrimSafe().Truncate(4000); } if (amazonAddress.IsSetPhone()) { address.PhoneNumber = amazonAddress.Phone.TrimSafe().Truncate(4000); } if (amazonAddress.IsSetCountryCode()) { var country = countryService.GetCountryByTwoOrThreeLetterIsoCode(amazonAddress.CountryCode); if (country != null) { address.CountryId = country.Id; countryAllowsShipping = country.AllowsShipping; countryAllowsBilling = country.AllowsBilling; } } if (amazonAddress.IsSetStateOrRegion()) { var stateProvince = stateProvinceService.GetStateProvinceByAbbreviation(amazonAddress.StateOrRegion); if (stateProvince != null) address.StateProvinceId = stateProvince.Id; } //amazonAddress.District, amazonAddress.County ?? if (address.CountryId == 0) address.CountryId = null; if (address.StateProvinceId == 0) address.StateProvinceId = null; }