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.

Fix - Menu/Search box categories - cache key without language

KrzysztofPajak9f8c91c34e83
diff --git a/src/Web/Grand.Web/Components/SearchBox.cs b/src/Web/Grand.Web/Components/SearchBox.cs
index a6c88c16c..363c6273b 100644
--- a/src/Web/Grand.Web/Components/SearchBox.cs
+++ b/src/Web/Grand.Web/Components/SearchBox.cs
@@ -24,7 +24,8 @@ namespace Grand.Web.ViewComponents
{
var model = await _mediator.Send(new GetSearchBox() {
Customer = _workContext.CurrentCustomer,
- Store = _workContext.CurrentStore
+ Store = _workContext.CurrentStore,
+ Language = _workContext.WorkingLanguage
});
return View(model);
}
diff --git a/src/Web/Grand.Web/Events/Cache/CacheKeyConst.cs b/src/Web/Grand.Web/Events/Cache/CacheKeyConst.cs
index baf398c58..413c83d0a 100644
--- a/src/Web/Grand.Web/Events/Cache/CacheKeyConst.cs
+++ b/src/Web/Grand.Web/Events/Cache/CacheKeyConst.cs
@@ -126,17 +126,19 @@ namespace Grand.Web.Events.Cache
/// Key for caching
/// </summary>
/// <remarks>
- /// {0} : store ID
- /// {1} : customer groups
+ /// {1} : language ID
+ /// {2} : store ID
+ /// {3} : customer groups
/// </remarks>
- public static string CATEGORIES_BY_MENU => "Grand.category.menu-{0}-{1}.pres";
+ public static string CATEGORIES_BY_MENU => "Grand.category.menu-{0}-{1}-{1}.pres";
/// <summary>
/// Key for CategorySearchBoxModel caching
/// </summary>
/// <remarks>
- /// {1} : comma separated list of customer groups
- /// {2} : current store ID
+ /// {1} : language ID
+ /// {2} : store ID
+ /// {3} : comma separated list of customer groups
/// </remarks>
public const string CATEGORY_ALL_SEARCHBOX = "Grand.category.all.searchbox-{0}-{1}";
diff --git a/src/Web/Grand.Web/Features/Handlers/Catalog/GetMenuHandler.cs b/src/Web/Grand.Web/Features/Handlers/Catalog/GetMenuHandler.cs
index 4af59db59..b1734fb81 100644
--- a/src/Web/Grand.Web/Features/Handlers/Catalog/GetMenuHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Catalog/GetMenuHandler.cs
@@ -63,7 +63,9 @@ namespace Grand.Web.Features.Handlers.Catalog
public async Task<MenuModel> Handle(GetMenu request, CancellationToken cancellationToken)
{
- string cacheKey = string.Format(CacheKeyConst.CATEGORIES_BY_MENU, request.Store.Id, string.Join(",", request.Customer.GetCustomerGroupIds()));
+ var cacheKey = string.Format(CacheKeyConst.CATEGORIES_BY_MENU,
+ request.Language.Id,
+ request.Store.Id, string.Join(",", request.Customer.GetCustomerGroupIds()));
var cachedCategoriesModel = await _cacheBase.GetAsync(cacheKey, async () =>
{
//categories
diff --git a/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchBoxHandler.cs b/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchBoxHandler.cs
index baca49d4f..1441c130f 100644
--- a/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchBoxHandler.cs
+++ b/src/Web/Grand.Web/Features/Handlers/Catalog/GetSearchBoxHandler.cs
@@ -1,10 +1,10 @@
-using Grand.Infrastructure.Caching;
-using Grand.Domain.Catalog;
-using Grand.Business.Catalog.Interfaces.Categories;
-using Grand.Business.Customers.Interfaces;
+using Grand.Business.Catalog.Interfaces.Categories;
using Grand.Business.Common.Interfaces.Localization;
-using Grand.Web.Features.Models.Catalog;
+using Grand.Domain.Catalog;
+using Grand.Domain.Customers;
+using Grand.Infrastructure.Caching;
using Grand.Web.Events.Cache;
+using Grand.Web.Features.Models.Catalog;
using Grand.Web.Models.Catalog;
using MediatR;
using Microsoft.AspNetCore.Mvc.Rendering;
@@ -12,7 +12,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
-using Grand.Domain.Customers;
namespace Grand.Web.Features.Handlers.Catalog
{
@@ -37,9 +36,9 @@ namespace Grand.Web.Features.Handlers.Catalog
public async Task<SearchBoxModel> Handle(GetSearchBox request, CancellationToken cancellationToken)
{
- string cacheKey = string.Format(CacheKeyConst.CATEGORY_ALL_SEARCHBOX,
- string.Join(",", request.Customer.GetCustomerGroupIds()),
- request.Store.Id);
+ var cacheKey = string.Format(CacheKeyConst.CATEGORY_ALL_SEARCHBOX,
+ request.Language.Id, request.Store.Id,
+ string.Join(",", request.Customer.GetCustomerGroupIds()));
return await _cacheBase.GetAsync(cacheKey, async () =>
{
diff --git a/src/Web/Grand.Web/Features/Models/Catalog/GetSearchBox.cs b/src/Web/Grand.Web/Features/Models/Catalog/GetSearchBox.cs
index 20094eac1..ffd73f082 100644
--- a/src/Web/Grand.Web/Features/Models/Catalog/GetSearchBox.cs
+++ b/src/Web/Grand.Web/Features/Models/Catalog/GetSearchBox.cs
@@ -1,4 +1,5 @@
using Grand.Domain.Customers;
+using Grand.Domain.Localization;
using Grand.Domain.Stores;
using Grand.Web.Models.Catalog;
using MediatR;
@@ -9,5 +10,7 @@ namespace Grand.Web.Features.Models.Catalog
{
public Customer Customer { get; set; }
public Store Store { get; set; }
+ public Language Language { get; set; }
+
}
}