本文整理汇总了C#中System.Collections.Specialized.NameValueCollection.AddProductAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.AddProductAttribute方法的具体用法?C# NameValueCollection.AddProductAttribute怎么用?C# NameValueCollection.AddProductAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Specialized.NameValueCollection
的用法示例。
在下文中一共展示了NameValueCollection.AddProductAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPreselectedPrice
protected virtual decimal GetPreselectedPrice(Product product, PriceCalculationContext context, ProductBundleItemData bundleItem, IEnumerable<ProductBundleItemData> bundleItems)
{
var taxRate = decimal.Zero;
var attributesTotalPriceBase = decimal.Zero;
var preSelectedPriceAdjustmentBase = decimal.Zero;
var isBundle = (product.ProductType == ProductType.BundledProduct);
var isBundleItemPricing = (bundleItem != null && bundleItem.Item.BundleProduct.BundlePerItemPricing);
var isBundlePricing = (bundleItem != null && !bundleItem.Item.BundleProduct.BundlePerItemPricing);
var bundleItemId = (bundleItem == null ? 0 : bundleItem.Item.Id);
var selectedAttributes = new NameValueCollection();
var selectedAttributeValues = new List<ProductVariantAttributeValue>();
var attributes = context.Attributes.Load(product.Id);
// 1. fill selectedAttributes with initially selected attributes
foreach (var attribute in attributes.Where(x => x.ProductVariantAttributeValues.Count > 0 && x.ShouldHaveValues()))
{
int preSelectedValueId = 0;
ProductVariantAttributeValue defaultValue = null;
var selectedValueIds = new List<int>();
var pvaValues = attribute.ProductVariantAttributeValues;
foreach (var pvaValue in pvaValues)
{
ProductBundleItemAttributeFilter attributeFilter = null;
if (bundleItem.FilterOut(pvaValue, out attributeFilter))
continue;
if (preSelectedValueId == 0 && attributeFilter != null && attributeFilter.IsPreSelected)
preSelectedValueId = attributeFilter.AttributeValueId;
if (!isBundlePricing && pvaValue.IsPreSelected)
{
decimal attributeValuePriceAdjustment = GetProductVariantAttributeValuePriceAdjustment(pvaValue);
decimal priceAdjustmentBase = _taxService.GetProductPrice(product, attributeValuePriceAdjustment, out taxRate);
preSelectedPriceAdjustmentBase = decimal.Add(preSelectedPriceAdjustmentBase, priceAdjustmentBase);
}
}
// value pre-selected by a bundle item filter discards the default pre-selection
if (preSelectedValueId != 0 && (defaultValue = pvaValues.FirstOrDefault(x => x.Id == preSelectedValueId)) != null)
{
//defaultValue.IsPreSelected = true;
selectedAttributeValues.Add(defaultValue);
selectedAttributes.AddProductAttribute(attribute.ProductAttributeId, attribute.Id, defaultValue.Id, product.Id, bundleItemId);
}
else
{
foreach (var value in pvaValues.Where(x => x.IsPreSelected))
{
selectedAttributeValues.Add(value);
selectedAttributes.AddProductAttribute(attribute.ProductAttributeId, attribute.Id, value.Id, product.Id, bundleItemId);
}
}
}
// 2. find attribute combination for selected attributes and merge it
if (!isBundle && selectedAttributes.Count > 0)
{
string attributeXml = selectedAttributes.CreateSelectedAttributesXml(product.Id, attributes, _productAttributeParser, _services.Localization,
_downloadService, _catalogSettings, _httpRequestBase, new List<string>(), true, bundleItemId);
var combinations = context.AttributeCombinations.Load(product.Id);
var selectedCombination = combinations.FirstOrDefault(x => _productAttributeParser.AreProductAttributesEqual(x.AttributesXml, attributeXml, attributes));
if (selectedCombination != null && selectedCombination.IsActive && selectedCombination.Price.HasValue)
{
product.MergedDataValues = new Dictionary<string, object> { { "Price", selectedCombination.Price.Value } };
}
}
if (_catalogSettings.EnableDynamicPriceUpdate && !isBundlePricing)
{
if (selectedAttributeValues.Count > 0)
{
selectedAttributeValues.Each(x => attributesTotalPriceBase += GetProductVariantAttributeValuePriceAdjustment(x));
}
else
{
attributesTotalPriceBase = preSelectedPriceAdjustmentBase;
}
}
if (bundleItem != null)
{
bundleItem.AdditionalCharge = attributesTotalPriceBase;
}
var result = GetFinalPrice(product, bundleItems, _services.WorkContext.CurrentCustomer, attributesTotalPriceBase, true, 1, bundleItem, context);
return result;
}
示例2: GetPreselectedPrice
protected virtual decimal GetPreselectedPrice(Product product, ProductBundleItemData bundleItem, IList<ProductBundleItemData> bundleItems)
{
var taxRate = decimal.Zero;
var attributesTotalPriceBase = decimal.Zero;
var preSelectedPriceAdjustmentBase = decimal.Zero;
var isBundle = (product.ProductType == ProductType.BundledProduct);
var isBundleItemPricing = (bundleItem != null && bundleItem.Item.BundleProduct.BundlePerItemPricing);
var isBundlePricing = (bundleItem != null && !bundleItem.Item.BundleProduct.BundlePerItemPricing);
var bundleItemId = (bundleItem == null ? 0 : bundleItem.Item.Id);
var attributes = (isBundle ? new List<ProductVariantAttribute>() : _productAttributeService.GetProductVariantAttributesByProductId(product.Id));
var selectedAttributes = new NameValueCollection();
List<ProductVariantAttributeValue> selectedAttributeValues = null;
foreach (var attribute in attributes)
{
int preSelectedValueId = 0;
ProductVariantAttributeValue defaultValue = null;
if (attribute.ShouldHaveValues())
{
var pvaValues = _productAttributeService.GetProductVariantAttributeValues(attribute.Id);
if (pvaValues.Count == 0)
continue;
foreach (var pvaValue in pvaValues)
{
ProductBundleItemAttributeFilter attributeFilter = null;
if (bundleItem.FilterOut(pvaValue, out attributeFilter))
continue;
if (preSelectedValueId == 0 && attributeFilter != null && attributeFilter.IsPreSelected)
preSelectedValueId = attributeFilter.AttributeValueId;
if (!isBundlePricing && pvaValue.IsPreSelected)
{
decimal attributeValuePriceAdjustment = GetProductVariantAttributeValuePriceAdjustment(pvaValue);
decimal priceAdjustmentBase = _taxService.GetProductPrice(product, attributeValuePriceAdjustment, out taxRate);
preSelectedPriceAdjustmentBase = decimal.Add(preSelectedPriceAdjustmentBase, priceAdjustmentBase);
}
}
// value pre-selected by a bundle item filter discards the default pre-selection
if (preSelectedValueId != 0 && (defaultValue = pvaValues.FirstOrDefault(x => x.Id == preSelectedValueId)) != null)
defaultValue.IsPreSelected = true;
if (defaultValue == null)
defaultValue = pvaValues.FirstOrDefault(x => x.IsPreSelected);
if (defaultValue == null && attribute.IsRequired)
defaultValue = pvaValues.First();
if (defaultValue != null)
selectedAttributes.AddProductAttribute(attribute.ProductAttributeId, attribute.Id, defaultValue.Id, product.Id, bundleItemId);
}
}
if (!isBundle && selectedAttributes.Count > 0)
{
string attributeXml = selectedAttributes.CreateSelectedAttributesXml(product.Id, attributes, _productAttributeParser, _commonServices.Localization,
_downloadService, _catalogSettings, _httpRequestBase, new List<string>(), true, bundleItemId);
selectedAttributeValues = _productAttributeParser.ParseProductVariantAttributeValues(attributeXml).ToList();
var combinations = _productAttributeService.GetAllProductVariantAttributeCombinations(product.Id);
var selectedCombination = combinations.FirstOrDefault(x => _productAttributeParser.AreProductAttributesEqual(x.AttributesXml, attributeXml));
if (selectedCombination != null && selectedCombination.IsActive)
product.MergeWithCombination(selectedCombination);
}
if (_catalogSettings.EnableDynamicPriceUpdate && !isBundlePricing)
{
if (selectedAttributeValues != null)
{
selectedAttributeValues.Each(x => attributesTotalPriceBase += GetProductVariantAttributeValuePriceAdjustment(x));
}
else
{
attributesTotalPriceBase = preSelectedPriceAdjustmentBase;
}
}
if (bundleItem != null)
{
bundleItem.AdditionalCharge = attributesTotalPriceBase;
}
var result = GetFinalPrice(product, bundleItems, _commonServices.WorkContext.CurrentCustomer, attributesTotalPriceBase, true, 1, bundleItem);
return result;
}