From 6af6073b2e39907010d0ff2ef9b6a41c03b7bb2c Mon Sep 17 00:00:00 2001 From: Marcus Gesing Date: Mon, 22 Sep 2014 17:38:50 +0200 Subject: [PATCH] Resolves #479 Product filter: Wrong count of manufacturers if products of sub-categories are included --- changelog.md | 3 +- .../Filter/FilterService.cs | 32 ++++++++++- .../Filter/IFilterService.cs | 2 + .../Controllers/FilterController.cs | 53 ++----------------- 4 files changed, 38 insertions(+), 52 deletions(-) diff --git a/changelog.md b/changelog.md index fec978addc..49509714df 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -#Release Notes# +#Release Notes# ##SmartStore.NET 2.1# @@ -74,6 +74,7 @@ * #434 Shipping.ByTotal: Make grid pageable * #419 email account password hidden * #424 Localize return reasons & return actions +* #479 Product filter: Wrong count of manufacturers if products of sub-categories are included ##SmartStore.NET 2.0.2# diff --git a/src/Libraries/SmartStore.Services/Filter/FilterService.cs b/src/Libraries/SmartStore.Services/Filter/FilterService.cs index 422769a45e..069af2abf8 100644 --- a/src/Libraries/SmartStore.Services/Filter/FilterService.cs +++ b/src/Libraries/SmartStore.Services/Filter/FilterService.cs @@ -21,14 +21,20 @@ public partial class FilterService : IFilterService private readonly IProductService _productService; private readonly ICategoryService _categoryService; private readonly IStoreContext _storeContext; + private readonly CatalogSettings _catalogSettings; + private IQueryable _products; private bool? _includeFeatured; - public FilterService(IProductService productService, ICategoryService categoryService, IStoreContext storeContext) + public FilterService(IProductService productService, + ICategoryService categoryService, + IStoreContext storeContext, + CatalogSettings catalogSettings) { _productService = productService; _categoryService = categoryService; _storeContext = storeContext; + _catalogSettings = catalogSettings; } public static int MaxDisplayCriteria { get { return 4; } } @@ -308,6 +314,30 @@ public virtual string Serialize(List criteria) return ""; } + public virtual FilterProductContext CreateFilterProductContext(string filter, int categoryID, string path, int? pagesize, int? orderby, string viewmode) + { + var context = new FilterProductContext() + { + Filter = filter, + ParentCategoryID = categoryID, + CategoryIds = new List { categoryID }, + Path = path, + PageSize = pagesize ?? 12, + ViewMode = viewmode, + OrderBy = orderby, + Criteria = Deserialize(filter) + }; + + if (_catalogSettings.ShowProductsFromSubcategories) + { + context.CategoryIds.AddRange( + _categoryService.GetAllCategoriesByParentCategoryId(categoryID).Select(x => x.Id) + ); + } + + return context; + } + public virtual bool ToWhereClause(FilterSql context) { if (context.Values == null) diff --git a/src/Libraries/SmartStore.Services/Filter/IFilterService.cs b/src/Libraries/SmartStore.Services/Filter/IFilterService.cs index 0a38d10769..6fedebac89 100644 --- a/src/Libraries/SmartStore.Services/Filter/IFilterService.cs +++ b/src/Libraries/SmartStore.Services/Filter/IFilterService.cs @@ -12,6 +12,8 @@ public partial interface IFilterService List Deserialize(string jsonData); string Serialize(List criteria); + FilterProductContext CreateFilterProductContext(string filter, int categoryID, string path, int? pagesize, int? orderby, string viewmode); + bool ToWhereClause(FilterSql context); bool ToWhereClause(FilterSql context, List findIn, Predicate match); diff --git a/src/Presentation/SmartStore.Web/Controllers/FilterController.cs b/src/Presentation/SmartStore.Web/Controllers/FilterController.cs index 8bdb1422cc..bcba603e32 100644 --- a/src/Presentation/SmartStore.Web/Controllers/FilterController.cs +++ b/src/Presentation/SmartStore.Web/Controllers/FilterController.cs @@ -1,36 +1,10 @@ using System.Collections.Generic; -using System.Linq; -using System.Linq.Dynamic; using System.Web.Mvc; -using SmartStore.Core.Infrastructure; using SmartStore.Services.Filter; -using SmartStore.Core.Data; -using SmartStore.Core.Domain.Catalog; using SmartStore.Web.Models.Filter; -using SmartStore.Web.Framework.Mvc; -using System.Net.Mime; -using SmartStore.Web.Models.Catalog; -using System; -using SmartStore.Services.Catalog; -using SmartStore.Services.Security; -using System.Diagnostics; -using SmartStore.Web.Infrastructure.Cache; -using SmartStore.Core; -using SmartStore.Services.Localization; -using SmartStore.Core.Domain.Tax; -using SmartStore.Services.Directory; -using SmartStore.Core.Domain.Directory; -using SmartStore.Services.Tax; -using SmartStore.Services.Media; -using SmartStore.Core.Domain.Media; -using SmartStore.Web.Models.Media; -using SmartStore.Core.Caching; -using SmartStore.Services.Seo; -using SmartStore.Web.Framework.Controllers; namespace SmartStore.Web.Controllers { - /// codehint: sm-add public partial class FilterController : Controller // not BaseController cause of performance { private readonly IFilterService _filterService; @@ -42,17 +16,7 @@ public FilterController(IFilterService filterService) public ActionResult Products(string filter, int categoryID, string path, int? pagesize, int? orderby, string viewmode) { - var context = new FilterProductContext() - { - Filter = filter, - ParentCategoryID = categoryID, - CategoryIds = new List { categoryID }, - Path = path, - PageSize = pagesize ?? 12, - ViewMode = viewmode, - OrderBy = orderby, - Criteria = _filterService.Deserialize(filter) - }; + var context = _filterService.CreateFilterProductContext(filter, categoryID, path, pagesize, orderby, viewmode); _filterService.ProductFilterable(context); @@ -96,22 +60,11 @@ public ActionResult Products(string active, string inactive, int categoryID, int public ActionResult ProductsMultiSelect(string filter, int categoryID, string path, int? pagesize, int? orderby, string viewmode, string filterMultiSelect) { - var context = new FilterProductContext() - { - Filter = filter, - ParentCategoryID = categoryID, - CategoryIds = new List { categoryID }, - Path = path, - PageSize = pagesize ?? 12, - ViewMode = viewmode, - OrderBy = orderby, - Criteria = _filterService.Deserialize(filter) - }; + var context = _filterService.CreateFilterProductContext(filter, categoryID, path, pagesize, orderby, viewmode); _filterService.ProductFilterableMultiSelect(context, filterMultiSelect); return PartialView(new ProductFilterModel { Context = context }); } - - } // class + } }