本文整理汇总了C#中IProduct.ProductOptionsForAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# IProduct.ProductOptionsForAttributes方法的具体用法?C# IProduct.ProductOptionsForAttributes怎么用?C# IProduct.ProductOptionsForAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IProduct
的用法示例。
在下文中一共展示了IProduct.ProductOptionsForAttributes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateProductVariant
/// <summary>
/// Creates a <see cref="IProductVariant"/> of the <see cref="IProduct"/> passed defined by the collection of <see cref="IProductAttribute"/>
/// without saving it to the database
/// </summary>
/// <param name="product">The <see cref="IProduct"/></param>
/// <param name="attributes">The <see cref="IProductVariant"/></param>
/// <returns>Either a new <see cref="IProductVariant"/> or, if one already exists with associated attributes, the existing <see cref="IProductVariant"/></returns>
internal IProductVariant CreateProductVariant(IProduct product, ProductAttributeCollection attributes)
{
var skuSeparator = MerchelloConfiguration.Current.DefaultSkuSeparator;
// verify the order of the attributes so that a sku can be constructed in the same order as the UI
var optionIds = product.ProductOptionsForAttributes(attributes).OrderBy(x => x.SortOrder).Select(x => x.Key).Distinct();
// the base sku
var sku = product.Sku;
var name = string.Format("{0} - ", product.Name);
foreach (var att in optionIds.Select(key => attributes.FirstOrDefault(x => x.OptionKey == key)).Where(att => att != null))
{
name += att.Name + " ";
sku += skuSeparator + (string.IsNullOrEmpty(att.Sku) ? Regex.Replace(att.Name, "[^0-9a-zA-Z]+", string.Empty) : att.Sku);
}
return CreateProductVariant(product, name, sku, product.Price, attributes);
}