Пример #1
0
        /**
         * Get categories using GetCategory2CS and GetCategories calls,
         * and merge the categories
         *
         */
        public CategoryTypeCollection GetAllMergedCategories()
        {
            if (!siteMergedCategoriesTable.ContainsKey(apiContext.Site))
            {
                //Get all categories that are mapped to characteristics sets
                CategoryCSDownloader categoryCSDownloader = new CategoryCSDownloader(apiContext);
                CategoryTypeCollection cats = categoryCSDownloader.GetCategoriesCS();
                Hashtable csCatsTable = new Hashtable();
                foreach (CategoryType cat in cats)
                {
                    if (csCatsTable.ContainsKey(cat.CategoryID)) continue;
                    csCatsTable.Add(cat.CategoryID, cat);
                }

                //get all categories
                Hashtable allCatsTable = GetAllCategoriesTable();

                foreach (CategoryType cat in allCatsTable.Values)
                {
                    CategoryType csCat = csCatsTable[cat.CategoryID] as CategoryType;
                    if (csCat != null)
                    {
                        //copy category name and leaf category fields, since these
                        //fields are not set when using GetCategoryCS call.
                        csCat.CategoryName = cat.CategoryName;
                        csCat.LeafCategory = cat.LeafCategory;
                    }
                    else
                    {
                        //some category has no characteristics sets,
                        //but it may has custom item specifics
                        csCatsTable.Add(cat.CategoryID, cat);
                    }
                }

                CategoryTypeCollection catCol = new CategoryTypeCollection();
                foreach (CategoryType cat in csCatsTable.Values)
                {
                    catCol.Add(cat);
                }

                siteMergedCategoriesTable.Add(apiContext.Site, catCol);

                return catCol;
            }
            else
            {
                return siteMergedCategoriesTable[apiContext.Site] as CategoryTypeCollection;
            }
        }