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


C# Product.ParseRequiredProductIds方法代码示例

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


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

示例1: Can_parse_required_product_ids

		public void Can_parse_required_product_ids()
		{
			var product = new Product
			{
				RequiredProductIds = "1, 4,7 ,a,"
			};

			var ids = product.ParseRequiredProductIds();
			ids.Length.ShouldEqual(3);
			ids[0].ShouldEqual(1);
			ids[1].ShouldEqual(4);
			ids[2].ShouldEqual(7);
		}
开发者ID:JeffersonNascimento,项目名称:SmartStoreNET,代码行数:13,代码来源:ProductExtensionTests.cs

示例2: GetRequiredProductWarnings

        /// <summary>
		/// Validates required products (products 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="product">Product</param>
		/// <param name="storeId">Store identifier</param>
		/// <param name="automaticallyAddRequiredProductsIfEnabled">Automatically add required products if enabled</param>
        /// <returns>Warnings</returns>
        public virtual IList<string> GetRequiredProductWarnings(Customer customer,
			ShoppingCartType shoppingCartType, Product product,
			int storeId, bool automaticallyAddRequiredProductsIfEnabled)
        {
            if (customer == null)
                throw new ArgumentNullException("customer");

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

            var cart = customer.GetCartItems(shoppingCartType, storeId);
            var warnings = new List<string>();

            if (product.RequireOtherProducts)
            {
                var requiredProducts = new List<Product>();
                foreach (var id in product.ParseRequiredProductIds())
                {
					var rp = _productService.GetProductById(id);
                    if (rp != null)
                        requiredProducts.Add(rp);
                }
                
                foreach (var rp in requiredProducts)
                {
                    //ensure that product is in the cart
                    bool alreadyInTheCart = false;
                    foreach (var sci in cart)
                    {
                        if (sci.Item.ProductId == rp.Id)
                        {
                            alreadyInTheCart = true;
                            break;
                        }
                    }
                    //not in the cart
                    if (!alreadyInTheCart)
                    {
                        if (product.AutomaticallyAddRequiredProducts)
                        {
                            //add to cart (if possible)
                            if (automaticallyAddRequiredProductsIfEnabled)
                            {
                                //pass 'false' for 'automaticallyAddRequiredProducsIfEnabled' to prevent circular references
								int shoppingCartItemId;
								var addToCartWarnings = AddToCart(customer, rp, shoppingCartType, storeId, "", decimal.Zero, 1, false, out shoppingCartItemId);
                                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"), rp.GetLocalized(x => x.Name)));
                                }
                            }
                            else
                            {
								warnings.Add(string.Format(_localizationService.GetResource("ShoppingCart.RequiredProductWarning"), rp.GetLocalized(x => x.Name)));
                            }
                        }
                        else
                        {
							warnings.Add(string.Format(_localizationService.GetResource("ShoppingCart.RequiredProductWarning"), rp.GetLocalized(x => x.Name)));
                        }
                    }
                }
            }

            return warnings;
        }
开发者ID:GloriousOnion,项目名称:SmartStoreNET,代码行数:79,代码来源:ShoppingCartService.cs


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