From f9e275072de84d87778c04805cd1a6f1ed628b6f Mon Sep 17 00:00:00 2001 From: KrzysztofPajak Date: Tue, 20 Jul 2021 10:44:40 +0200 Subject: [PATCH] Allow to use recommended products per store --- .../Queries/Handlers/GetRecommendedProductsQueryHandler.cs | 6 +++--- .../Queries/Models/GetRecommendedProductsQuery.cs | 1 + .../Caching/Constants/ProductCacheKey.cs | 3 ++- src/Web/Grand.Web/Components/CustomerRecommendedProducts.cs | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Business/Grand.Business.Catalog/Queries/Handlers/GetRecommendedProductsQueryHandler.cs b/src/Business/Grand.Business.Catalog/Queries/Handlers/GetRecommendedProductsQueryHandler.cs index 364b30ebc..e07ce5d84 100644 --- a/src/Business/Grand.Business.Catalog/Queries/Handlers/GetRecommendedProductsQueryHandler.cs +++ b/src/Business/Grand.Business.Catalog/Queries/Handlers/GetRecommendedProductsQueryHandler.cs @@ -1,10 +1,10 @@ using Grand.Business.Catalog.Interfaces.Products; using Grand.Business.Catalog.Queries.Models; -using Grand.Infrastructure.Caching; -using Grand.Infrastructure.Caching.Constants; using Grand.Domain.Catalog; using Grand.Domain.Customers; using Grand.Domain.Data; +using Grand.Infrastructure.Caching; +using Grand.Infrastructure.Caching.Constants; using MediatR; using System.Collections.Generic; using System.Linq; @@ -32,7 +32,7 @@ public class GetRecommendedProductsQueryHandler : IRequestHandler> Handle(GetRecommendedProductsQuery request, CancellationToken cancellationToken) { - return await _cacheBase.GetAsync(string.Format(CacheKey.PRODUCTS_CUSTOMER_GROUP, string.Join(",", request.CustomerGroupIds)), async () => + return await _cacheBase.GetAsync(string.Format(CacheKey.PRODUCTS_CUSTOMER_GROUP, string.Join(",", request.CustomerGroupIds), request.StoreId), async () => { var query = from cr in _customerGroupProductRepository.Table where request.CustomerGroupIds.Contains(cr.CustomerGroupId) diff --git a/src/Business/Grand.Business.Catalog/Queries/Models/GetRecommendedProductsQuery.cs b/src/Business/Grand.Business.Catalog/Queries/Models/GetRecommendedProductsQuery.cs index dbfe1bda1..51f42c51d 100644 --- a/src/Business/Grand.Business.Catalog/Queries/Models/GetRecommendedProductsQuery.cs +++ b/src/Business/Grand.Business.Catalog/Queries/Models/GetRecommendedProductsQuery.cs @@ -7,5 +7,6 @@ namespace Grand.Business.Catalog.Queries.Models public class GetRecommendedProductsQuery : IRequest> { public string[] CustomerGroupIds { get; set; } + public string StoreId { get; set; } } } diff --git a/src/Core/Grand.Infrastructure/Caching/Constants/ProductCacheKey.cs b/src/Core/Grand.Infrastructure/Caching/Constants/ProductCacheKey.cs index 998ed0dc6..a388154dd 100644 --- a/src/Core/Grand.Infrastructure/Caching/Constants/ProductCacheKey.cs +++ b/src/Core/Grand.Infrastructure/Caching/Constants/ProductCacheKey.cs @@ -20,8 +20,9 @@ public static partial class CacheKey /// /// /// {0} : customer group IDs + /// {1} : store ident /// - public static string PRODUCTS_CUSTOMER_GROUP => "Grand.product.cr-{0}"; + public static string PRODUCTS_CUSTOMER_GROUP => "Grand.product.cr-{0}-{1}"; /// /// Key for caching diff --git a/src/Web/Grand.Web/Components/CustomerRecommendedProducts.cs b/src/Web/Grand.Web/Components/CustomerRecommendedProducts.cs index 3edcfcb40..3d9355cbd 100644 --- a/src/Web/Grand.Web/Components/CustomerRecommendedProducts.cs +++ b/src/Web/Grand.Web/Components/CustomerRecommendedProducts.cs @@ -43,7 +43,7 @@ public async Task InvokeAsync(int? productThumbPictureSize if (!_catalogSettings.RecommendedProductsEnabled) return Content(""); - var products = await _mediator.Send(new GetRecommendedProductsQuery() { CustomerGroupIds = _workContext.CurrentCustomer.GetCustomerGroupIds() }); + var products = await _mediator.Send(new GetRecommendedProductsQuery() { CustomerGroupIds = _workContext.CurrentCustomer.GetCustomerGroupIds(), StoreId =_workContext.CurrentStore.Id }); if (!products.Any()) return Content("");