示例#1
0
        /// <summary>
        /// 取三级分类的筛选属性
        /// </summary>
        /// <param name="categoryId"></param>
        /// <returns></returns>
        public List <CategoryAttribute> GetCategoryAttribute(int categoryId, int language)
        {
            try
            {
                string cacheName = ConstClass.RedisKey4MPrefix + "_CategoryAttribute_" + categoryId;
                List <CategoryAttribute> list = RedisCacheHelper.Get <List <CategoryAttribute> >(cacheName);
                //if (list == null)
                //{
                list = new List <CategoryAttribute>();
                list = categoryDal.GetCategoryAttribute(categoryId, language).ToList();
                //所有商品都有品牌,是否退货选项
                list.Insert(0, new CategoryAttribute()
                {
                    CategoryId    = categoryId,
                    CategoryName  = list.Count > 0 ? list.First().CategoryName : "",
                    KeyName       = "IsReturn",
                    KeyValue      = "是否可退货",
                    SubKeyName    = "否",
                    SubKeyValue   = "否",
                    IsSkuAttr     = 0,
                    IsSkuMainAttr = 0
                });
                list.Insert(0, new CategoryAttribute()
                {
                    CategoryId    = categoryId,
                    CategoryName  = list.Count > 0 ? list.First().CategoryName : "",
                    KeyName       = "IsReturn",
                    KeyValue      = "是否可退货",
                    SubKeyName    = "是",
                    SubKeyValue   = "是",
                    IsSkuAttr     = 0,
                    IsSkuMainAttr = 0
                });


                string noBrandCategoryIds = ConfigHelper.GetAppSetting <string>("NoBrandCategoryIds");

                if (!string.IsNullOrEmpty(noBrandCategoryIds) &&
                    !noBrandCategoryIds.Contains(categoryId.ToString()))
                {
                    DataTable dt = product.GetBrand();
                    if (dt != null)
                    {
                        foreach (DataRow r in dt.Rows)
                        {
                            var brand = new CategoryAttribute()
                            {
                                CategoryId    = categoryId,
                                CategoryName  = list.Count > 0 ? list.First().CategoryName : "",
                                KeyName       = "Brand",
                                KeyValue      = "品牌",
                                SubKeyName    = r["NameCN"].ToString(),
                                SubKeyValue   = r["NameCN"].ToString(),
                                IsSkuAttr     = 0,
                                IsSkuMainAttr = 0
                            };
                            list.Add(brand);
                        }
                    }
                }


                // RedisCacheHelper.Add(cacheName, list, 60);
                //}
                return(list);
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(new List <CategoryAttribute>());
            }
        }