Skip to content

Commit

Permalink
Resolves #479 Product filter: Wrong count of manufacturers if product…
Browse files Browse the repository at this point in the history
…s of sub-categories are included
  • Loading branch information
mgesing committed Sep 22, 2014
1 parent 358e4f7 commit 6af6073
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 52 deletions.
3 changes: 2 additions & 1 deletion changelog.md
@@ -1,4 +1,4 @@
#Release Notes#
#Release Notes#

##SmartStore.NET 2.1#

Expand Down Expand Up @@ -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#
Expand Down
32 changes: 31 additions & 1 deletion src/Libraries/SmartStore.Services/Filter/FilterService.cs
Expand Up @@ -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<Product> _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; } }
Expand Down Expand Up @@ -308,6 +314,30 @@ public virtual string Serialize(List<FilterCriteria> 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<int> { 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)
Expand Down
2 changes: 2 additions & 0 deletions src/Libraries/SmartStore.Services/Filter/IFilterService.cs
Expand Up @@ -12,6 +12,8 @@ public partial interface IFilterService
List<FilterCriteria> Deserialize(string jsonData);
string Serialize(List<FilterCriteria> criteria);

FilterProductContext CreateFilterProductContext(string filter, int categoryID, string path, int? pagesize, int? orderby, string viewmode);

bool ToWhereClause(FilterSql context);
bool ToWhereClause(FilterSql context, List<FilterCriteria> findIn, Predicate<FilterCriteria> match);

Expand Down
53 changes: 3 additions & 50 deletions 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
{
/// <remarks>codehint: sm-add</remarks>
public partial class FilterController : Controller // not BaseController cause of performance
{
private readonly IFilterService _filterService;
Expand All @@ -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<int> { 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);

Expand Down Expand Up @@ -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<int> { 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
}
}

0 comments on commit 6af6073

Please sign in to comment.