Inheritance: Nop.Web.Framework.Mvc.BaseNopEntityModel
コード例 #1
0
        protected IList<CategoryNavigationModel.CategoryModel> PrepareCategoryNavigationModel(int rootCategoryId,
            IList<int> breadCrumbIds)
        {
            var result = new List<CategoryNavigationModel.CategoryModel>();
            foreach (var category in _categoryService.GetAllCategoriesByParentCategoryId(rootCategoryId))
            {
                var categoryModel = new CategoryNavigationModel.CategoryModel()
                {
                    Id = category.Id,
                    Name = category.GetLocalized(x => x.Name),
                    SeName = category.GetSeName()
                };

                //product number for each category
                if (_catalogSettings.ShowCategoryProductNumber)
                {
                    var categoryIds = new List<int>();
                    categoryIds.Add(category.Id);
                    //include subcategories
                    if (_catalogSettings.ShowCategoryProductNumberIncludingSubcategories)
                        categoryIds.AddRange(GetChildCategoryIds(category.Id));
                    categoryModel.NumberOfProducts = _productService
                        .SearchProducts(categoryIds: categoryIds,
                        storeId: _storeContext.CurrentStore.Id,
                        visibleIndividuallyOnly: true,
                        pageSize: 1)
                        .TotalCount;
                }

                //subcategories
                for (int i = 0; i <= breadCrumbIds.Count - 1; i++)
                    if (breadCrumbIds[i] == category.Id)
                        categoryModel.SubCategories.AddRange(PrepareCategoryNavigationModel(category.Id, breadCrumbIds));

                result.Add(categoryModel);
            }

            return result;
        }
コード例 #2
0
ファイル: CatalogController.cs プロジェクト: nopmcs/hcc_dev
        protected IList<CategoryNavigationModel.CategoryModel> PrepareCategoryNavigationModel(int rootCategoryId)
        {
            var result = new List<CategoryNavigationModel.CategoryModel>();
            foreach (var category in _categoryService.GetAllCategoriesByParentCategoryId(rootCategoryId))
            {
                var categoryModel = new CategoryNavigationModel.CategoryModel()
                {
                    Id = category.Id,
                    Name = category.GetLocalized(x => x.Name),
                    SeName = category.GetSeName()
                };

                //product number for each category
                if (_catalogSettings.ShowCategoryProductNumber)
                {
                    var categoryIds = new List<int>();
                    categoryIds.Add(category.Id);
                    //include subcategories
                    if (_catalogSettings.ShowCategoryProductNumberIncludingSubcategories)
                        categoryIds.AddRange(GetChildCategoryIds(category.Id));
                    IList<int> filterableSpecificationAttributeOptionIds = null;
                    categoryModel.NumberOfProducts = _productService.SearchProducts(categoryIds,
                        0, null, null, null, 0, string.Empty, false, false, 0, null,
                        ProductSortingEnum.Position, 0, 1,
                        false, out filterableSpecificationAttributeOptionIds).TotalCount;
                }

                //subcategories
                categoryModel.SubCategories.AddRange(PrepareCategoryNavigationModel(category.Id));

                result.Add(categoryModel);
            }

            return result;
        }