1

Nop Commerce を使用して、カテゴリ ナビゲーションを変更して、childsiblingsonly を取得する必要があります。

親カテゴリには、categoryID と 0 の ParentCategoryID があります。子カテゴリには、次の例に示すように、categoryID があり、独自の CategoryId を持つ ParentCategoryID にマップされます。

ID PCID NAME 
10  0   Computers 
11  10  Software 
12  10  Hardware
13  0   Football
14  13  Tottenham
15  15  Manchester United 

カタログ コントローラーには、以下に示す非アクションとパブリック アクションの 2 つのメソッドがあります。子カテゴリから製品に移動すると、ナビゲーション ビューが消えますが、意味がある場合は、製品が接続されている currentCategory Id のままにしたいと思います。

[NonAction]
    private IList<CategoryNavigationModel> GetOnlySiblings(Category currentCategory) 
    { 
        var result = new List<CategoryNavigationModel>();
        int Id = 0;
        if (currentCategory != null)
            Id = currentCategory.Id;

        foreach (var category in _categoryService.GetAllCategoriesByParentCategoryId(Id)) 
        {
            var model = new CategoryNavigationModel()
            {
                Id = category.Id,
                Name = category.GetLocalized(x => x.Name),
                SeName = category.GetSeName(),
                IsActive = currentCategory != null && currentCategory.Id == category.ParentCategoryId,
                NumberOfParentCategories = 0,
            };

            result.Add(model); 
        } 
        return result; 
    }

そして公の行動

[ChildActionOnly]
    //[OutputCache(Duration = 120, VaryByCustom = "WorkingLanguage")]
    public ActionResult CategoryNavigation(int currentCategoryId, int currentProductId)
    {
        string cacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_NAVIGATION_MODEL_KEY, currentCategoryId, currentProductId, _workContext.WorkingLanguage.Id);
        var cacheModel = _cacheManager.Get(cacheKey, () =>
        {
            var currentCategory = _categoryService.GetCategoryById(currentCategoryId);
            if (currentCategory == null && currentProductId > 0)
            {
                var productCategories = _categoryService.GetProductCategoriesByProductId(currentProductId);
                if (productCategories.Count > 0)
                    currentCategory = productCategories[0].Category;
            }
            var breadCrumb = currentCategory != null ? GetCategoryBreadCrumb(currentCategory) : new List<Category>();
            var model = GetOnlySiblings(currentCategory);
            return model;
        });

        return PartialView(cacheModel);
    }
4

1 に答える 1

0

次のような既存のロジックを再利用してみませんか。

public IList<CategoryNavigationModel> GetOnlySiblings(int currentCategoryId)
        {
            var currentCategory = _categoryService.GetCategoryById(currentCategoryId);
            var siblingCategories = GetChildCategoryNavigationModel(new List<Category>(), currentCategory.ParentCategoryId, currentCategory, 0);

            return siblingCategories;
        }
于 2012-11-20T12:51:47.333 に答える