1
Nop Commerce 사용하기 childsiblingsonly을 얻으려면 카테고리 내비게이션을 변경해야합니다.currentCategoryId = currentId 변수 int?
상위 카테고리는 categoryID와 ParentCategoryID가 0입니다. 하위 카테고리는 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
카탈로그 컨트롤러에는 다음과 같은 두 가지 메소드가 있습니다 (Non Action 및 Public Action). 하위 카테고리에서 제품으로 이동하면 내비게이션보기가 사라지지만 제품이 연결되면 현재의 카테고리 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);
}