本文整理汇总了C#中ISpecificationAttributeService.GetSpecificationAttributeOptionById方法的典型用法代码示例。如果您正苦于以下问题:C# ISpecificationAttributeService.GetSpecificationAttributeOptionById方法的具体用法?C# ISpecificationAttributeService.GetSpecificationAttributeOptionById怎么用?C# ISpecificationAttributeService.GetSpecificationAttributeOptionById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISpecificationAttributeService
的用法示例。
在下文中一共展示了ISpecificationAttributeService.GetSpecificationAttributeOptionById方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareSpecsFilters
public virtual void PrepareSpecsFilters(IList<int> alreadyFilteredSpecOptionIds,
IList<int> filterableSpecificationAttributeOptionIds,
ISpecificationAttributeService specificationAttributeService,
IWebHelper webHelper,
IWorkContext workContext)
{
var allFilters = new List<SpecificationAttributeOptionFilter>();
if (filterableSpecificationAttributeOptionIds != null)
foreach (var saoId in filterableSpecificationAttributeOptionIds)
{
var sao = specificationAttributeService.GetSpecificationAttributeOptionById(saoId);
if (sao != null)
{
var sa = sao.SpecificationAttribute;
if (sa != null)
{
allFilters.Add(new SpecificationAttributeOptionFilter
{
SpecificationAttributeId = sa.Id,
SpecificationAttributeName = sa.GetLocalized(x => x.Name, workContext.WorkingLanguage.Id),
SpecificationAttributeDisplayOrder = sa.DisplayOrder,
SpecificationAttributeOptionId = sao.Id,
SpecificationAttributeOptionName = sao.GetLocalized(x => x.Name, workContext.WorkingLanguage.Id),
SpecificationAttributeOptionDisplayOrder = sao.DisplayOrder
});
}
}
}
//sort loaded options
allFilters = allFilters.OrderBy(saof => saof.SpecificationAttributeDisplayOrder)
.ThenBy(saof => saof.SpecificationAttributeName)
.ThenBy(saof => saof.SpecificationAttributeOptionDisplayOrder)
.ThenBy(saof => saof.SpecificationAttributeOptionName).ToList();
//get already filtered specification options
var alreadyFilteredOptions = allFilters
.Where(x => alreadyFilteredSpecOptionIds.Contains(x.SpecificationAttributeOptionId))
.Select(x => x)
.ToList();
//get not filtered specification options
var notFilteredOptions = new List<SpecificationAttributeOptionFilter>();
foreach (var saof in allFilters)
{
//do not add already filtered specification options
if (alreadyFilteredOptions.FirstOrDefault(x => x.SpecificationAttributeId == saof.SpecificationAttributeId) != null)
continue;
//else add it
notFilteredOptions.Add(saof);
}
//prepare the model properties
if (alreadyFilteredOptions.Count > 0 || notFilteredOptions.Count > 0)
{
this.Enabled = true;
this.AlreadyFilteredItems = alreadyFilteredOptions.ToList().Select(x =>
{
var item = new SpecificationFilterItem();
item.SpecificationAttributeName = x.SpecificationAttributeName;
item.SpecificationAttributeOptionName = x.SpecificationAttributeOptionName;
return item;
}).ToList();
this.NotFilteredItems = notFilteredOptions.ToList().Select(x =>
{
var item = new SpecificationFilterItem();
item.SpecificationAttributeName = x.SpecificationAttributeName;
item.SpecificationAttributeOptionName = x.SpecificationAttributeOptionName;
//filter URL
var alreadyFilteredOptionIds = GetAlreadyFilteredSpecOptionIds(webHelper);
if (!alreadyFilteredOptionIds.Contains(x.SpecificationAttributeOptionId))
alreadyFilteredOptionIds.Add(x.SpecificationAttributeOptionId);
string newQueryParam = GenerateFilteredSpecQueryParam(alreadyFilteredOptionIds);
string filterUrl = webHelper.ModifyQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM + "=" + newQueryParam, null);
filterUrl = ExcludeQueryStringParams(filterUrl, webHelper);
item.FilterUrl = filterUrl;
return item;
}).ToList();
//remove filter URL
string removeFilterUrl = webHelper.RemoveQueryString(webHelper.GetThisPageUrl(true), QUERYSTRINGPARAM);
removeFilterUrl = ExcludeQueryStringParams(removeFilterUrl, webHelper);
this.RemoveFilterUrl = removeFilterUrl;
}
else
{
this.Enabled = false;
}
}
示例2: GetAlreadyFilteredSpecs
protected virtual IList<SpecificationAttributeOptionFilter> GetAlreadyFilteredSpecs(ISpecificationAttributeService specificationAttributeService,
IWebHelper webHelper, IWorkContext workContext)
{
var result = new List<SpecificationAttributeOptionFilter>();
var optionIds = GetAlreadyFilteredSpecOptionIds(webHelper);
foreach (var id in optionIds)
{
var sao = specificationAttributeService.GetSpecificationAttributeOptionById(id);
if (sao != null)
{
var sa = sao.SpecificationAttribute;
if (sa != null)
{
result.Add(new SpecificationAttributeOptionFilter
{
SpecificationAttributeId = sa.Id,
SpecificationAttributeName = sa.GetLocalized(x => x.Name),
DisplayOrder = sa.DisplayOrder,
SpecificationAttributeOptionId = sao.Id,
SpecificationAttributeOptionName = sao.GetLocalized(x => x.Name)
});
}
}
}
return result;
}