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


C# ProductVariant.ParseRequiredProductVariantIds方法代码示例

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


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

示例1: Can_parse_required_productvariant_ids

        public void Can_parse_required_productvariant_ids()
        {
            var productVariant = new ProductVariant
            {
                RequiredProductVariantIds = "1, 4,7 ,a,"
            };

            var ids = productVariant.ParseRequiredProductVariantIds();
            ids.Length.ShouldEqual(3);
            ids[0].ShouldEqual(1);
            ids[1].ShouldEqual(4);
            ids[2].ShouldEqual(7);
        }
开发者ID:cmcginn,项目名称:StoreFront,代码行数:13,代码来源:ProductVariantTests.cs

示例2: GetRequiredProductVariantWarnings

        /// <summary>
        /// Validates required product variants (product variants which require other variant to be added to the cart)
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <param name="shoppingCartType">Shopping cart type</param>
        /// <param name="productVariant">Product variant</param>
        /// <param name="automaticallyAddRequiredProductVariantsIfEnabled">Automatically add required product variants if enabled</param>
        /// <returns>Warnings</returns>
        public virtual IList<string> GetRequiredProductVariantWarnings(Customer customer, ShoppingCartType shoppingCartType,
            ProductVariant productVariant, bool automaticallyAddRequiredProductVariantsIfEnabled)
        {
            if (customer == null)
                throw new ArgumentNullException("customer");

            if (productVariant == null)
                throw new ArgumentNullException("productVariant");

            var cart = customer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == shoppingCartType).ToList();

            var warnings = new List<string>();

            if (productVariant.RequireOtherProducts)
            {
                var requiredProductVariants = new List<ProductVariant>();
                foreach (var id in productVariant.ParseRequiredProductVariantIds())
                {
                    var rpv = _productService.GetProductVariantById(id);
                    if (rpv != null)
                        requiredProductVariants.Add(rpv);
                }

                foreach (var rpv in requiredProductVariants)
                {
                    //ensure that product is in the cart
                    bool alreadyInTheCart = false;
                    foreach (var sci in cart)
                    {
                        if (sci.ProductVariantId == rpv.Id)
                        {
                            alreadyInTheCart = true;
                            break;
                        }
                    }
                    //not in the cart
                    if (!alreadyInTheCart)
                    {

                        string fullProductName = "";
                        if (!String.IsNullOrEmpty(rpv.GetLocalized(x => x.Name)))
                            fullProductName = string.Format("{0} ({1})", rpv.Product.GetLocalized(x => x.Name), rpv.GetLocalized(x => x.Name));
                        else
                            fullProductName = rpv.Product.GetLocalized(x => x.Name);

                        if (productVariant.AutomaticallyAddRequiredProductVariants)
                        {
                            //add to cart (if possible)
                            if (automaticallyAddRequiredProductVariantsIfEnabled)
                            {
                                //pass 'false' for 'automaticallyAddRequiredProductVariantsIfEnabled' to prevent circular references
                                var addToCartWarnings = AddToCart(customer, rpv, shoppingCartType, "", decimal.Zero, 1, false);
                                if (addToCartWarnings.Count > 0)
                                {
                                    //a product wasn't atomatically added for some reasons

                                    //don't display specific errors from 'addToCartWarnings' variable
                                    //display only generic error
                                    warnings.Add(string.Format(_localizationService.GetResource("ShoppingCart.RequiredProductWarning"), fullProductName));
                                }
                            }
                            else
                            {
                                warnings.Add(string.Format(_localizationService.GetResource("ShoppingCart.RequiredProductWarning"), fullProductName));
                            }
                        }
                        else
                        {
                            warnings.Add(string.Format(_localizationService.GetResource("ShoppingCart.RequiredProductWarning"), fullProductName));
                        }
                    }
                }
            }

            return warnings;
        }
开发者ID:nopmcs,项目名称:hcc_dev,代码行数:84,代码来源:ShoppingCartService.cs

示例3: GetRequiredProductVariants

        /// <summary>
        /// Get a list of required product variants
        /// </summary>
        /// <param name="productVariant">Product variant</param>
        /// <returns>Required product variants</returns>
        protected virtual IList<ProductVariant> GetRequiredProductVariants(ProductVariant productVariant)
        {
            if (productVariant == null)
                throw new ArgumentNullException("productVariant");

            var requiredProductVariants = new List<ProductVariant>();

            var ids = productVariant.ParseRequiredProductVariantIds();
            foreach (var id in ids)
            {
                var pv = _productService.GetProductVariantById(id);
                var nowUtc = DateTime.UtcNow;
                //ensure that product and product variant are published, not deleted, etc
                if (pv != null &&
                    !pv.Deleted &&
                    pv.Published &&
                    !pv.Product.Deleted &&
                    pv.Product.Published &&
                    (!pv.AvailableStartDateTimeUtc.HasValue || pv.AvailableStartDateTimeUtc.Value < nowUtc) &&
                    (!pv.AvailableEndDateTimeUtc.HasValue || pv.AvailableEndDateTimeUtc.Value > nowUtc))
                {
                    requiredProductVariants.Add(pv);
                }
            }

            return requiredProductVariants;
        }
开发者ID:pquic,项目名称:qCommerce,代码行数:32,代码来源:ShoppingCartService.cs


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