Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

Default.cshtml

@model CategoryNavigationModel

@using Nop.Core.Domain.Catalog

@functions {
    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;
    }

    async Task CategoryLine(CategoryNavigationModel.CategoryLineModel lineModel)
    {
        var active = lineModel.Category.Id == lineModel.CurrentCategoryId || lineModel.Category.SubCategories.Count(BreadCrumbContainsCurrentCategoryId) > 0;
        var last = lineModel.Category.Id == lineModel.CurrentCategoryId;
        var liClass = active ? "active" : "inactive";
        if (last)
        {
            liClass += " last";
        }

        <li class="@liClass">
            <a href="@(await NopUrl.RouteGenericUrlAsync<Category>(new { SeName = lineModel.Category.SeName }))">
                @lineModel.Category.Name
                @if (lineModel.Category.NumberOfProducts.HasValue)
                {
                    <text> </text>@T("Categories.TotalProducts", lineModel.Category.NumberOfProducts.Value)
                }
            </a>
            @{
                if (lineModel.Category.Id == lineModel.CurrentCategoryId ||
                    lineModel.Category.SubCategories.Count(BreadCrumbContainsCurrentCategoryId) > 0)
                {
                    if (lineModel.Category.SubCategories.Count > 0)
                    {
                        <ul class="sublist">
                            @foreach (var subCategory in lineModel.Category.SubCategories)
                            {
                                var categoryLineModel = new CategoryNavigationModel.CategoryLineModel
                                {
                                    CurrentCategoryId = lineModel.CurrentCategoryId,
                                    Category = subCategory
                                };
                                await CategoryLine(categoryLineModel);
                            }
                        </ul>
                    }
                }
            }
        </li>
    }
}

@if (Model.Categories.Count > 0)
{
    <section class="block block-category-navigation">
        <h2 class="title">
            @T("Categories")
        </h2>
        <div class="listbox">
            <ul class="list">
                @foreach (var category in Model.Categories)
                {
                    var categoryLineModel = new CategoryNavigationModel.CategoryLineModel
                    {
                        CurrentCategoryId = Model.CurrentCategoryId,
                        Category = category
                    };
                    await CategoryLine(categoryLineModel);
                }
            </ul>
        </div>
    </section>
}