Ejemplo n.º 1
0
        //根据淘宝的父类目和子类目->获取后台供卖家发布商品的标准商品类目id
        /// <summary>
        /// 根据淘宝的父类目和子类目->获取后台供卖家发布商品的标准商品类目id
        /// </summary>
        /// <param name="parentCatalog">父类目, 如:男装</param>
        /// <param name="childCatalog">子类目,如:T恤</param>
        public string GetCid(string parentCatalog, string childCatalog)
        {
            var parentItemCat = GetAllItemCatByApi(0).Find(c => c.Name.Contains(parentCatalog));

            if (parentItemCat == null)
            {
                //如果在淘宝中没有找到就在映射中找
                parentItemCat = GetAllItemCatByApi(0).Find(c => c.Name.Contains(SysUtils.GetCustomCategoryMap(parentCatalog)));

                if (parentItemCat == null)
                {
                    throw new Exception(Resource.ExceptionTemplate_MethedParameterIsNullorEmpty.StringFormat(new System.Diagnostics.StackTrace().ToString()));
                }
            }


            ItemCat childItemCat = null;


            childItemCat = GetAllItemCatByApi(parentItemCat.Cid).Find(c => c.Name.Contains(childCatalog));


            //如果淘宝子类别下还有子类别,如:女童->外套->普通外套等。
            //那么直到遍历完相应子目录才结束。
            while (childItemCat != null && childItemCat.IsParent)
            {
                childItemCat = GetAllItemCatByApi(childItemCat.Cid).Find(c => c.Name.Contains(childCatalog));
            }

            if (childItemCat == null)
            {
                //没有找到然后在到GetCustomCidMap中查找
                return(SysUtils.GetCustomCidMap(parentCatalog, childCatalog));
            }

            return(childItemCat.Cid.ToString(CultureInfo.InvariantCulture));
        }