diff --git a/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/ViewModels/FilterCategory.cs b/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/ViewModels/FilterCategory.cs index 003680db97..0093c435a0 100644 --- a/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/ViewModels/FilterCategory.cs +++ b/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/ViewModels/FilterCategory.cs @@ -9,5 +9,7 @@ public class FilterCategory public string Slug { get; set; } public int Count { get; set; } + + public long? ParentId { get; set; } } } diff --git a/src/Modules/SimplCommerce.Module.Search/Areas/Search/Controllers/SearchController.cs b/src/Modules/SimplCommerce.Module.Search/Areas/Search/Controllers/SearchController.cs index 021672ffe3..1c109ed8c3 100644 --- a/src/Modules/SimplCommerce.Module.Search/Areas/Search/Controllers/SearchController.cs +++ b/src/Modules/SimplCommerce.Module.Search/Areas/Search/Controllers/SearchController.cs @@ -1,15 +1,16 @@ using System; +using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using SimplCommerce.Infrastructure.Data; using SimplCommerce.Module.Catalog.Models; +using SimplCommerce.Module.Catalog.Services; using SimplCommerce.Module.Catalog.ViewModels; -using SimplCommerce.Module.Search.ViewModels; -using Microsoft.EntityFrameworkCore; using SimplCommerce.Module.Core.Services; using SimplCommerce.Module.Search.Models; -using Microsoft.Extensions.Configuration; -using SimplCommerce.Module.Catalog.Services; +using SimplCommerce.Module.Search.ViewModels; namespace SimplCommerce.Module.Search.Controllers { @@ -50,7 +51,7 @@ public IActionResult Index(SearchOption searchOption) } var brand = _brandRepository.Query().FirstOrDefault(x => x.Name == searchOption.Query && x.IsPublished); - if(brand != null) + if (brand != null) { return Redirect(string.Format("~/{0}", brand.Slug)); } @@ -155,10 +156,12 @@ private static void AppendFilterOptionsToModel(SearchResult model, IQueryable x.Price); model.FilterOption.Categories = query - .SelectMany(x => x.Categories).Where(x => x.Category.Parent == null) - .GroupBy(x => new { + .SelectMany(x => x.Categories) + .GroupBy(x => new + { x.Category.Id, x.Category.Name, + x.Category.ParentId, x.Category.Slug }) .Select(g => new FilterCategory @@ -166,6 +169,7 @@ private static void AppendFilterOptionsToModel(SearchResult model, IQueryable
    - @foreach (var category in Model.FilterOption.Categories) + @foreach (var category in Model.FilterOption.Categories.Where(x => x.ParentId == null)) { -
  • - -
  • - } +
  • + + @{ + var children = Model.FilterOption.Categories.Where(x => x.ParentId == category.Id); + } + + @if (children.Any()) + { +
      + @foreach (var child in children) + { +
    • + +
    • + } +
    + } +
  • + }
@@ -70,30 +88,31 @@ - @if (Model.FilterOption.Price.MaxPrice != Model.FilterOption.Price.MinPrice) { -
-
- -
-
-
-
- - - - + @if (Model.FilterOption.Price.MaxPrice != Model.FilterOption.Price.MinPrice) + { +
+
+ +
+
+
+
+ + + + +
-
}
@@ -112,18 +131,18 @@
@*
  • - -
    - - -
    -
  • *@ + +
    + + +
    + *@
    diff --git a/src/Modules/SimplCommerce.Module.Search/Areas/Search/Views/_ViewImports.cshtml b/src/Modules/SimplCommerce.Module.Search/Areas/Search/Views/_ViewImports.cshtml index a4266a2c8b..52ca8f5db8 100644 --- a/src/Modules/SimplCommerce.Module.Search/Areas/Search/Views/_ViewImports.cshtml +++ b/src/Modules/SimplCommerce.Module.Search/Areas/Search/Views/_ViewImports.cshtml @@ -3,5 +3,5 @@ @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper "*, cloudscribe.Web.Pagination" - -@inject IViewLocalizer Localizer \ No newline at end of file +@addTagHelper *, SimplCommerce.Module.Search +@inject IViewLocalizer Localizer