本文整理汇总了C#中IAddressAttributeFormatter.FormatAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# IAddressAttributeFormatter.FormatAttributes方法的具体用法?C# IAddressAttributeFormatter.FormatAttributes怎么用?C# IAddressAttributeFormatter.FormatAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAddressAttributeFormatter
的用法示例。
在下文中一共展示了IAddressAttributeFormatter.FormatAttributes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareModel
//.........这里部分代码省略.........
if (address == null && prePopulateWithCustomerFields)
{
if (customer == null)
throw new Exception("Customer cannot be null when prepopulating an address");
model.Email = customer.Email;
model.FirstName = customer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName);
model.LastName = customer.GetAttribute<string>(SystemCustomerAttributeNames.LastName);
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);
//ignore country and state for prepopulation. it can cause some issues when posting pack with errors, etc
//model.CountryId = customer.GetAttribute<int>(SystemCustomerAttributeNames.CountryId);
//model.StateProvinceId = customer.GetAttribute<int>(SystemCustomerAttributeNames.StateProvinceId);
model.PhoneNumber = customer.GetAttribute<string>(SystemCustomerAttributeNames.Phone);
model.FaxNumber = customer.GetAttribute<string>(SystemCustomerAttributeNames.Fax);
}
//countries and states
if (addressSettings.CountryEnabled && loadCountries != null)
{
if (localizationService == null)
throw new ArgumentNullException("localizationService");
model.AvailableCountries.Add(new SelectListItem { Text = localizationService.GetResource("Address.SelectCountry"), Value = "0" });
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 (addressSettings.StateProvinceEnabled)
{
//states
if (stateProvinceService == null)
throw new ArgumentNullException("stateProvinceService");
var languageId = EngineContext.Current.Resolve<IWorkContext>().WorkingLanguage.Id;
var states = stateProvinceService
.GetStateProvincesByCountryId(model.CountryId.HasValue ? model.CountryId.Value : 0, languageId)
.ToList();
if (states.Count > 0)
{
model.AvailableStates.Add(new SelectListItem { Text = localizationService.GetResource("Address.SelectState"), Value = "0" });
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 = "0"
});
}
}
}
//form fields
model.CompanyEnabled = addressSettings.CompanyEnabled;
model.CompanyRequired = addressSettings.CompanyRequired;
model.StreetAddressEnabled = addressSettings.StreetAddressEnabled;
model.StreetAddressRequired = addressSettings.StreetAddressRequired;
model.StreetAddress2Enabled = addressSettings.StreetAddress2Enabled;
model.StreetAddress2Required = addressSettings.StreetAddress2Required;
model.ZipPostalCodeEnabled = addressSettings.ZipPostalCodeEnabled;
model.ZipPostalCodeRequired = addressSettings.ZipPostalCodeRequired;
model.CityEnabled = addressSettings.CityEnabled;
model.CityRequired = addressSettings.CityRequired;
model.CountryEnabled = addressSettings.CountryEnabled;
model.StateProvinceEnabled = addressSettings.StateProvinceEnabled;
model.PhoneEnabled = addressSettings.PhoneEnabled;
model.PhoneRequired = addressSettings.PhoneRequired;
model.FaxEnabled = addressSettings.FaxEnabled;
model.FaxRequired = addressSettings.FaxRequired;
//customer attribute services
if (addressAttributeService != null && addressAttributeParser != null)
{
PrepareCustomAddressAttributes(model, address, addressAttributeService, addressAttributeParser, overrideAttributesXml);
}
if (addressAttributeFormatter != null && address != null)
{
model.FormattedCustomAddressAttributes = addressAttributeFormatter.FormatAttributes(address.CustomAttributes);
}
}