Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Allow to use recommended products per store

KrzysztofPajake794e7e135b4
diff --git a/src/Business/Grand.Business.Catalog/Queries/Handlers/GetRecommendedProductsQueryHandler.cs b/src/Business/Grand.Business.Catalog/Queries/Handlers/GetRecommendedProductsQueryHandler.cs
index 364b30ebc..a875dcbdc 100644
--- a/src/Business/Grand.Business.Catalog/Queries/Handlers/GetRecommendedProductsQueryHandler.cs
+++ b/src/Business/Grand.Business.Catalog/Queries/Handlers/GetRecommendedProductsQueryHandler.cs
@@ -32,7 +32,7 @@ namespace Grand.Business.Catalog.Queries.Handlers
public async Task<IList<Product>> 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..f44154c13 100644
--- a/src/Business/Grand.Business.Catalog/Queries/Models/GetRecommendedProductsQuery.cs
+++ b/src/Business/Grand.Business.Catalog/Queries/Models/GetRecommendedProductsQuery.cs
@@ -7,5 +7,7 @@ namespace Grand.Business.Catalog.Queries.Models
public class GetRecommendedProductsQuery : IRequest<IList<Product>>
{
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 @@
/// </summary>
/// <remarks>
/// {0} : customer group IDs
+ /// {1} : store ident
/// </remarks>
- public static string PRODUCTS_CUSTOMER_GROUP => "Grand.product.cr-{0}";
+ public static string PRODUCTS_CUSTOMER_GROUP => "Grand.product.cr-{0}-{1}";
/// <summary>
/// Key for caching
diff --git a/src/Web/Grand.Web/Components/CustomerRecommendedProducts.cs b/src/Web/Grand.Web/Components/CustomerRecommendedProducts.cs
index 3edcfcb40..a17b76e43 100644
--- a/src/Web/Grand.Web/Components/CustomerRecommendedProducts.cs
+++ b/src/Web/Grand.Web/Components/CustomerRecommendedProducts.cs
@@ -43,7 +43,8 @@ namespace Grand.Web.Components
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("");