当前位置: 首页>>代码示例>>C#>>正文


C# Product.MergeWithCombination方法代码示例

本文整理汇总了C#中SmartStore.Core.Domain.Catalog.Product.MergeWithCombination方法的典型用法代码示例。如果您正苦于以下问题:C# Product.MergeWithCombination方法的具体用法?C# Product.MergeWithCombination怎么用?C# Product.MergeWithCombination使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SmartStore.Core.Domain.Catalog.Product的用法示例。


在下文中一共展示了Product.MergeWithCombination方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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;
        }
开发者ID:ejimenezdelgado,项目名称:SmartStoreNET,代码行数:93,代码来源:PriceCalculationService.cs

示例2: PrepareProductDetailModel


//.........这里部分代码省略.........
                }
            }

            #endregion

            #region Attribute combinations

            if (!isBundle)
            {
                if (selectedAttributes.Count > 0)
                {
                    // merge with combination data if there's a match
                    var warnings = new List<string>();
                    string attributeXml = selectedAttributes.CreateSelectedAttributesXml(product.Id, variantAttributes, _productAttributeParser, _localizationService,
                        _downloadService, _catalogSettings, _httpRequest, warnings, true, bundleItemId);

                    selectedAttributeValues = _productAttributeParser.ParseProductVariantAttributeValues(attributeXml).ToList();
                    hasSelectedAttributesValues = (selectedAttributeValues.Count > 0);

                    if (isBundlePricing)
                    {
                        model.AttributeInfo = _productAttributeFormatter.FormatAttributes(product, attributeXml, customer,
                            renderPrices: false, renderGiftCardAttributes: false, allowHyperlinks: false);
                    }

                    model.SelectedCombination = _productAttributeParser.FindProductVariantAttributeCombination(product.Id, attributeXml);

                    if (model.SelectedCombination != null && model.SelectedCombination.IsActive == false)
                    {
                        model.IsAvailable = false;
                        model.StockAvailability = T("Products.Availability.IsNotActive");
                    }

                    product.MergeWithCombination(model.SelectedCombination);

                    // mark explicitly selected as pre-selected
                    foreach (var attribute in model.ProductVariantAttributes)
                    {
                        foreach (var value in attribute.Values)
                        {
                            if (selectedAttributeValues.FirstOrDefault(v => v.Id == value.Id) != null)
                                value.IsPreSelected = true;

                            if (!_catalogSettings.ShowVariantCombinationPriceAdjustment)
                                value.PriceAdjustment = "";
                        }
                    }
                }
            }

            #endregion

            #region Properties

            if ((productBundleItem != null && !productBundleItem.Item.BundleProduct.BundlePerItemShoppingCart) ||
                (product.ManageInventoryMethod == ManageInventoryMethod.ManageStockByAttributes && !hasSelectedAttributesValues))
            {
                // cases where stock inventory is not functional. determined by what ShoppingCartService.GetStandardWarnings and ProductService.AdjustInventory is not handling.
                model.IsAvailable = true;
                var hasAttributeCombinations = _services.DbContext.QueryForCollection(product, (Product p) => p.ProductVariantAttributeCombinations).Any();
                model.StockAvailability = !hasAttributeCombinations ? product.FormatStockMessage(_localizationService) : "";
            }
            else if (model.IsAvailable)
            {
                model.IsAvailable = product.IsAvailableByStock();
                model.StockAvailability = product.FormatStockMessage(_localizationService);
开发者ID:toannguyen241994,项目名称:SmartStoreNET,代码行数:67,代码来源:CatalogHelper.cs


注:本文中的SmartStore.Core.Domain.Catalog.Product.MergeWithCombination方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。