[DisplayName("ProductPage")]
[DisplayColumn("Title")] public class ProductPage_Metadata : MetadataBase<IProductEnrichment> { .............. [Display(Name = "CustomerSegments", Order = 121)] [UIHint("Country")] // [UIHint("CustomerSegments")] public object CustomerSegmentsIds { get; set; } }
public List<string>CustomerSegmentsIds { get; set; }
View > default > Shared > EditorTemplate > Country.
check Providertype also
@using Sana.Commerce @using Sana.Commerce.Shop @{ var fieldTitle = Html.DisplayName(string.Empty).ToString(); var name = string.Empty; var value = ViewData.Model as string; var selectedId = ViewData.Model as string; var entityField = ViewData.Model as EntityTemplateFieldModel; var customerSegments = CommerceFrameworkBase.CustomerSegments.Provider.GetCustomerSegments().ToList(); if (entityField != null) { fieldTitle = entityField.FieldTitle; name = entityField.Name; value = (string)entityField.Value; selectedId = (string)entityField.Value; } var modelState = ViewData.ModelState[name]; if (modelState != null && modelState.Value != null) { selectedId = modelState.Value.AttemptedValue; } var htmlAttributes = Html.GetTextBoxAttributes(fieldTitle, required: false); if (ViewData.ContainsKey("tabindex")) { htmlAttributes["tabindex"] = ViewData["tabindex"]; } <div class="ddlb"> <select name="@Html.Name(name)" id="@Html.Id(name)" @Html.RenderAttributes(htmlAttributes)> <option disabled @When(!customerSegments.Any(cs => cs.Id.iEquals(value)), "selected")> @Sana.SimpleText("SelectCustomerSegmentPlaceholder", "Select customer segment") </option> @{ var isSelected = false; foreach (var item in customerSegments) { isSelected = false; if (value == item.Id) { isSelected = true; } <option selected="@isSelected" value="@item.Id">@item.Title.Or(item.Id).AsHtml() </option> } } </select> </div> }
@using Sana.Commerce @using ICountry = Sana.Commerce.Common.ICountry @{ var fieldTitle = Html.DisplayName(string.Empty).ToString(); var name = string.Empty; var value = ViewData.Model as string; var countries = ViewBag.Countries as IList<ICountry>; var selectedId = ViewData.Model as string; var entityField = ViewData.Model as EntityTemplateFieldModel; var cStatment = CommerceFrameworkBase.CustomerSegments.Provider.GetCustomerSegments().ToList(); if (entityField != null) { fieldTitle = entityField.FieldTitle; name = entityField.Name; value = (string)entityField.Value; if (entityField.Settings.Countries != null) { countries = entityField.Settings.Countries; } selectedId = (string)entityField.Value; } if (countries == null) { countries = CommerceFrameworkBase.Common.GetCountries(userCountriesOnly: true, visibleOnly: true); } var modelState = ViewData.ModelState[name]; if (modelState != null && modelState.Value != null) { selectedId = modelState.Value.AttemptedValue; } var htmlAttributes = Html.GetTextBoxAttributes(fieldTitle, required: true); if (ViewData.ContainsKey("tabindex")) { htmlAttributes["tabindex"] = ViewData["tabindex"]; } @*<div class="ddlb"> <select name="@Html.Name(name)" id="@Html.Id(name)" @Html.RenderAttributes(htmlAttributes)> <option disabled @When(!countries.Any(country => country.Id.iEquals(value)), "selected")>@Sana.SimpleText("SelectCountryPlaceholder")</option> @foreach (var item in countries) { <option value="@item.Id" @Html.RenderAttributes(GetOptionHtmlAttributes(item, selectedId))>@item.Name.Or(item.Id).AsHtml()</option> } </select> </div>*@ <div class="ddlb"> <select name="@Html.Name(name)" id="@Html.Id(name)" @Html.RenderAttributes(htmlAttributes)> <option disabled @When(!countries.Any(country => country.Id.iEquals(value)), "selected")>@Sana.SimpleText("SelectCountryPlaceholder")</option> @foreach (var item in cStatment) { <option value="@item.Id">@item.Title.Or(item.Id).AsHtml()</option> } </select> </div> } @functions { IDictionary<string, object> GetOptionHtmlAttributes(ICountry country, string selectedId) { var attributes = new Dictionary<string, object>(); if (country.Id.iEquals(selectedId)) { attributes["selected"] = "selected"; } if (country.AddressUseZipPlus4) { attributes["data-zipPlus4"] = "true"; } return attributes; } }