Skip to content

Commit

Permalink
Remove IHttpContextAccessor from method filter specification option
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofPajak committed Nov 2, 2021
1 parent 53b5d4d commit 937aa27
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Grand.Web.Models.Catalog;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -58,7 +59,7 @@ public async Task<BrandModel> Handle(GetBrand request, CancellationToken cancell
model.PagingFilteringContext = options.command;

IList<string> alreadyFilteredSpecOptionIds = await model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds
(_httpContextAccessor, _specificationAttributeService);
(_httpContextAccessor.HttpContext.Request.Query, _specificationAttributeService);

var products = (await _mediator.Send(new GetSearchProductsQuery()
{
Expand All @@ -85,7 +86,7 @@ public async Task<BrandModel> Handle(GetBrand request, CancellationToken cancell
//specs
await model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds,
products.filterableSpecificationAttributeOptionIds,
_specificationAttributeService, _httpContextAccessor, _cacheBase, request.Language.Id);
_specificationAttributeService, _httpContextAccessor.HttpContext.Request.GetDisplayUrl(), request.Language.Id);

return model;
}
Expand Down
35 changes: 14 additions & 21 deletions src/Web/Grand.Web/Features/Handlers/Catalog/GetCategoryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
using Grand.Domain.Customers;
using Grand.Domain.Media;
using Grand.Infrastructure.Caching;
using Grand.Web.Events.Cache;
using Grand.Web.Extensions;
using Grand.Web.Features.Models.Catalog;
using Grand.Web.Features.Models.Products;
using Grand.Web.Events.Cache;
using Grand.Web.Models.Catalog;
using Grand.Web.Models.Media;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -70,8 +71,7 @@ public async Task<CategoryModel> Handle(GetCategory request, CancellationToken c
request.Command.OrderBy = request.Category.DefaultSort;

//view/sorting/page size
var options = await _mediator.Send(new GetViewSortSizeOptions()
{
var options = await _mediator.Send(new GetViewSortSizeOptions() {
Command = request.Command,
PagingFilteringModel = request.Command,
Language = request.Language,
Expand All @@ -94,8 +94,7 @@ public async Task<CategoryModel> Handle(GetCategory request, CancellationToken c
languageId);
model.CategoryBreadcrumb = await _cacheBase.GetAsync(breadcrumbCacheKey, async () =>
(await _categoryService.GetCategoryBreadCrumb(request.Category))
.Select(catBr => new CategoryModel
{
.Select(catBr => new CategoryModel {
Id = catBr.Id,
Name = catBr.GetTranslation(x => x.Name, languageId),
SeName = catBr.GetSeName(languageId)
Expand All @@ -108,8 +107,7 @@ public async Task<CategoryModel> Handle(GetCategory request, CancellationToken c
var subCategories = new List<CategoryModel.SubCategoryModel>();
foreach (var x in (await _categoryService.GetAllCategoriesByParentCategoryId(request.Category.Id)).Where(x => !x.HideOnCatalog))
{
var subCatModel = new CategoryModel.SubCategoryModel
{
var subCatModel = new CategoryModel.SubCategoryModel {
Id = x.Id,
Name = x.GetTranslation(y => y.Name, languageId),
SeName = x.GetSeName(languageId),
Expand All @@ -119,8 +117,7 @@ public async Task<CategoryModel> Handle(GetCategory request, CancellationToken c
};
//prepare picture model
var picture = !string.IsNullOrEmpty(x.PictureId) ? await _pictureService.GetPictureById(x.PictureId) : null;
subCatModel.PictureModel = new PictureModel
{
subCatModel.PictureModel = new PictureModel {
Id = x.PictureId,
FullSizeImageUrl = await _pictureService.GetPictureUrl(x.PictureId),
ImageUrl = await _pictureService.GetPictureUrl(x.PictureId, _mediaSettings.CategoryThumbPictureSize),
Expand Down Expand Up @@ -149,8 +146,7 @@ public async Task<CategoryModel> Handle(GetCategory request, CancellationToken c

var hasFeaturedProductsCache = await _cacheBase.GetAsync<bool?>(cacheKey, async () =>
{
featuredProducts = (await _mediator.Send(new GetSearchProductsQuery()
{
featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() {
PageSize = _catalogSettings.LimitOfFeaturedProducts,
CategoryIds = new List<string> { request.Category.Id },
Customer = request.Customer,
Expand All @@ -164,8 +160,7 @@ public async Task<CategoryModel> Handle(GetCategory request, CancellationToken c
if (hasFeaturedProductsCache.Value && featuredProducts == null)
{
//cache indicates that the category has featured products
featuredProducts = (await _mediator.Send(new GetSearchProductsQuery()
{
featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() {
PageSize = _catalogSettings.LimitOfFeaturedProducts,
CategoryIds = new List<string> { request.Category.Id },
Customer = request.Customer,
Expand All @@ -176,8 +171,7 @@ public async Task<CategoryModel> Handle(GetCategory request, CancellationToken c
}
if (featuredProducts != null && featuredProducts.Any())
{
model.FeaturedProducts = (await _mediator.Send(new GetProductOverview()
{
model.FeaturedProducts = (await _mediator.Send(new GetProductOverview() {
Products = featuredProducts,
})).ToList();
}
Expand All @@ -192,9 +186,9 @@ public async Task<CategoryModel> Handle(GetCategory request, CancellationToken c
categoryIds.AddRange(await _mediator.Send(new GetChildCategoryIds() { ParentCategoryId = request.Category.Id, Customer = request.Customer, Store = request.Store }));
}
//products
IList<string> alreadyFilteredSpecOptionIds = await model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds(_httpContextAccessor, _specificationAttributeService);
var products = (await _mediator.Send(new GetSearchProductsQuery()
{
IList<string> alreadyFilteredSpecOptionIds = await model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds(
_httpContextAccessor.HttpContext.Request.Query, _specificationAttributeService);
var products = (await _mediator.Send(new GetSearchProductsQuery() {
LoadFilterableSpecificationAttributeOptionIds = !_catalogSettings.IgnoreFilterableSpecAttributeOption,
CategoryIds = categoryIds,
Customer = request.Customer,
Expand All @@ -207,8 +201,7 @@ public async Task<CategoryModel> Handle(GetCategory request, CancellationToken c
PageSize = request.Command.PageSize
}));

model.Products = (await _mediator.Send(new GetProductOverview()
{
model.Products = (await _mediator.Send(new GetProductOverview() {
PrepareSpecificationAttributes = _catalogSettings.ShowSpecAttributeOnCatalogPages,
Products = products.products,
})).ToList();
Expand All @@ -218,7 +211,7 @@ public async Task<CategoryModel> Handle(GetCategory request, CancellationToken c
//specs
await model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds,
products.filterableSpecificationAttributeOptionIds,
_specificationAttributeService, _httpContextAccessor, _cacheBase, request.Language.Id);
_specificationAttributeService, _httpContextAccessor.HttpContext.Request.GetDisplayUrl(), request.Language.Id);

return model;
}
Expand Down
25 changes: 10 additions & 15 deletions src/Web/Grand.Web/Features/Handlers/Catalog/GetCollectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
using Grand.Domain.Catalog;
using Grand.Domain.Customers;
using Grand.Infrastructure.Caching;
using Grand.Web.Events.Cache;
using Grand.Web.Extensions;
using Grand.Web.Features.Models.Catalog;
using Grand.Web.Features.Models.Products;
using Grand.Web.Events.Cache;
using Grand.Web.Models.Catalog;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -49,8 +50,7 @@ public async Task<CollectionModel> Handle(GetCollection request, CancellationTok
request.Command.OrderBy = request.Collection.DefaultSort;

//view/sorting/page size
var options = await _mediator.Send(new GetViewSortSizeOptions()
{
var options = await _mediator.Send(new GetViewSortSizeOptions() {
Command = request.Command,
PagingFilteringModel = request.Command,
Language = request.Language,
Expand All @@ -72,8 +72,7 @@ public async Task<CollectionModel> Handle(GetCollection request, CancellationTok
request.Store.Id);
var hasFeaturedProductsCache = await _cacheBase.GetAsync<bool?>(cacheKey, async () =>
{
var featuredProducts = (await _mediator.Send(new GetSearchProductsQuery()
{
var featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() {
PageSize = _catalogSettings.LimitOfFeaturedProducts,
CollectionId = request.Collection.Id,
Customer = request.Customer,
Expand All @@ -86,8 +85,7 @@ public async Task<CollectionModel> Handle(GetCollection request, CancellationTok
if (hasFeaturedProductsCache.Value && featuredProducts == null)
{
//cache indicates that the collection has featured products
featuredProducts = (await _mediator.Send(new GetSearchProductsQuery()
{
featuredProducts = (await _mediator.Send(new GetSearchProductsQuery() {
PageSize = _catalogSettings.LimitOfFeaturedProducts,
CollectionId = request.Collection.Id,
Customer = request.Customer,
Expand All @@ -98,18 +96,16 @@ public async Task<CollectionModel> Handle(GetCollection request, CancellationTok
}
if (featuredProducts != null && featuredProducts.Any())
{
model.FeaturedProducts = (await _mediator.Send(new GetProductOverview()
{
model.FeaturedProducts = (await _mediator.Send(new GetProductOverview() {
Products = featuredProducts,
})).ToList();
}
}

IList<string> alreadyFilteredSpecOptionIds = await model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds
(_httpContextAccessor, _specificationAttributeService);
(_httpContextAccessor.HttpContext.Request.Query, _specificationAttributeService);

var products = (await _mediator.Send(new GetSearchProductsQuery()
{
var products = (await _mediator.Send(new GetSearchProductsQuery() {
LoadFilterableSpecificationAttributeOptionIds = !_catalogSettings.IgnoreFilterableSpecAttributeOption,
CollectionId = request.Collection.Id,
Customer = request.Customer,
Expand All @@ -122,8 +118,7 @@ public async Task<CollectionModel> Handle(GetCollection request, CancellationTok
PageSize = request.Command.PageSize
}));

model.Products = (await _mediator.Send(new GetProductOverview()
{
model.Products = (await _mediator.Send(new GetProductOverview() {
Products = products.products,
PrepareSpecificationAttributes = _catalogSettings.ShowSpecAttributeOnCatalogPages
})).ToList();
Expand All @@ -133,7 +128,7 @@ public async Task<CollectionModel> Handle(GetCollection request, CancellationTok
//specs
await model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds,
products.filterableSpecificationAttributeOptionIds,
_specificationAttributeService, _httpContextAccessor, _cacheBase, request.Language.Id);
_specificationAttributeService, _httpContextAccessor.HttpContext.Request.GetDisplayUrl(), request.Language.Id);

return model;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Grand.Web.Models.Catalog;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc.Rendering;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -229,7 +230,7 @@ public async Task<SearchModel> Handle(GetSearch request, CancellationToken cance
var searchInProductTags = searchInDescriptions;

IList<string> alreadyFilteredSpecOptionIds = await request.Model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds
(_httpContextAccessor, _specificationAttributeService);
(_httpContextAccessor.HttpContext.Request.Query, _specificationAttributeService);

//products
var searchproducts = (await _mediator.Send(new GetSearchProductsQuery() {
Expand Down Expand Up @@ -263,7 +264,7 @@ public async Task<SearchModel> Handle(GetSearch request, CancellationToken cance
//specs
await request.Model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds,
searchproducts.filterableSpecificationAttributeOptionIds,
_specificationAttributeService, _httpContextAccessor, _cacheBase, request.Language.Id);
_specificationAttributeService, _httpContextAccessor.HttpContext.Request.GetDisplayUrl(), request.Language.Id);

request.Model.NoResults = !request.Model.Products.Any();

Expand Down
23 changes: 9 additions & 14 deletions src/Web/Grand.Web/Features/Handlers/Catalog/GetVendorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Grand.Web.Models.Media;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -58,8 +59,7 @@ public class GetVendorHandler : IRequestHandler<GetVendor, VendorModel>

public async Task<VendorModel> Handle(GetVendor request, CancellationToken cancellationToken)
{
var model = new VendorModel
{
var model = new VendorModel {
Id = request.Vendor.Id,
Name = request.Vendor.GetTranslation(x => x.Name, request.Language.Id),
Description = request.Vendor.GetTranslation(x => x.Description, request.Language.Id),
Expand All @@ -71,16 +71,14 @@ public async Task<VendorModel> Handle(GetVendor request, CancellationToken cance
UserFields = request.Vendor.UserFields
};

model.Address = await _mediator.Send(new GetVendorAddress()
{
model.Address = await _mediator.Send(new GetVendorAddress() {
Language = request.Language,
Address = request.Vendor.Address,
ExcludeProperties = false,
});

//prepare picture model
var pictureModel = new PictureModel
{
var pictureModel = new PictureModel {
Id = request.Vendor.PictureId,
FullSizeImageUrl = await _pictureService.GetPictureUrl(request.Vendor.PictureId),
ImageUrl = await _pictureService.GetPictureUrl(request.Vendor.PictureId, _mediaSettings.VendorThumbPictureSize),
Expand All @@ -90,8 +88,7 @@ public async Task<VendorModel> Handle(GetVendor request, CancellationToken cance
model.PictureModel = pictureModel;

//view/sorting/page size
var options = await _mediator.Send(new GetViewSortSizeOptions()
{
var options = await _mediator.Send(new GetViewSortSizeOptions() {
Command = request.Command,
PagingFilteringModel = request.Command,
Language = request.Language,
Expand All @@ -102,11 +99,10 @@ public async Task<VendorModel> Handle(GetVendor request, CancellationToken cance
model.PagingFilteringContext = options.command;

IList<string> alreadyFilteredSpecOptionIds = await model.PagingFilteringContext.SpecificationFilter.GetAlreadyFilteredSpecOptionIds
(_httpContextAccessor, _specificationAttributeService);
(_httpContextAccessor.HttpContext.Request.Query, _specificationAttributeService);

//products
var products = (await _mediator.Send(new GetSearchProductsQuery()
{
var products = (await _mediator.Send(new GetSearchProductsQuery() {
LoadFilterableSpecificationAttributeOptionIds = !_catalogSettings.IgnoreFilterableSpecAttributeOption,
Customer = request.Customer,
VendorId = request.Vendor.Id,
Expand All @@ -118,8 +114,7 @@ public async Task<VendorModel> Handle(GetVendor request, CancellationToken cance
PageSize = request.Command.PageSize
}));

model.Products = (await _mediator.Send(new GetProductOverview()
{
model.Products = (await _mediator.Send(new GetProductOverview() {
Products = products.products,
PrepareSpecificationAttributes = _catalogSettings.ShowSpecAttributeOnCatalogPages
})).ToList();
Expand All @@ -129,7 +124,7 @@ public async Task<VendorModel> Handle(GetVendor request, CancellationToken cance
//specs
await model.PagingFilteringContext.SpecificationFilter.PrepareSpecsFilters(alreadyFilteredSpecOptionIds,
products.filterableSpecificationAttributeOptionIds,
_specificationAttributeService, _httpContextAccessor, _cacheBase, request.Language.Id);
_specificationAttributeService, _httpContextAccessor.HttpContext.Request.GetDisplayUrl(), request.Language.Id);

return model;
}
Expand Down
Loading

0 comments on commit 937aa27

Please sign in to comment.