@model CategoryNavigationModel
@using Nop.Web.Models.Catalog;
@functions{
public bool BreadCrumbContainsCurrentCategoryId(CategorySimpleModel category)
{
if (Model.CurrentCategoryId == 0)
return false;
if (category.Id == Model.CurrentCategoryId)
return true;
foreach (var subCategory in category.SubCategories)
{
if (BreadCrumbContainsCurrentCategoryId(subCategory))
{
return true;
}
}
return false;
}
}
@helper RenderCategoryLine(CategorySimpleModel category)
{
@category.Name
@if (category.NumberOfProducts.HasValue)
{
@T("Categories.TotalProducts", category.NumberOfProducts.Value)
}
@{
if (category.Id == Model.CurrentCategoryId ||
category.SubCategories.Count(BreadCrumbContainsCurrentCategoryId) > 0)
{
if (category.SubCategories.Count > 0)
{
@foreach (var subCategory in category.SubCategories)
{
@RenderCategoryLine(subCategory)
}
}
}
}
}
@if (Model.Categories.Count > 0)
{
@T("Categories")
@foreach (var category in Model.Categories)
{
@RenderCategoryLine(category)
}
}