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.

KnowledgebaseController use GetCategoryBreadCrumb method

KrzysztofPajak88d1f0390b93
diff --git a/src/Web/Grand.Web/Controllers/KnowledgebaseController.cs b/src/Web/Grand.Web/Controllers/KnowledgebaseController.cs
index 5eff685b1..a0bbacf0a 100644
--- a/src/Web/Grand.Web/Controllers/KnowledgebaseController.cs
+++ b/src/Web/Grand.Web/Controllers/KnowledgebaseController.cs
@@ -115,7 +115,7 @@ public class KnowledgebaseController : BasePublicController
string.Join(",", _workContext.CurrentCustomer.GetCustomerGroupIds()), _workContext.CurrentStore.Id,
_workContext.WorkingLanguage.Id);
model.CategoryBreadcrumb = await _cacheBase.GetAsync(breadcrumbCacheKey, async () =>
- (await category.GetCategoryBreadCrumb(_knowledgebaseService, _aclService, _workContext))
+ (await GetCategoryBreadCrumb(category))
.Select(catBr => new KnowledgebaseCategoryModel {
Id = catBr.Id,
Name = catBr.GetTranslation(x => x.Name, _workContext.WorkingLanguage.Id),
@@ -250,7 +250,7 @@ public class KnowledgebaseController : BasePublicController
_workContext.CurrentStore.Id,
_workContext.WorkingLanguage.Id);
model.CategoryBreadcrumb = await _cacheBase.GetAsync(breadcrumbCacheKey, async () =>
- (await category.GetCategoryBreadCrumb(_knowledgebaseService, _aclService, _workContext))
+ (await GetCategoryBreadCrumb(category))
.Select(catBr => new KnowledgebaseCategoryModel {
Id = catBr.Id,
Name = catBr.GetTranslation(x => x.Name, _workContext.WorkingLanguage.Id),
@@ -304,4 +304,30 @@ public class KnowledgebaseController : BasePublicController
await PrepareKnowledgebaseArticleModel(model, article, customerService);
return View("Article", model);
}
+
+ private async Task<IList<KnowledgebaseCategory>> GetCategoryBreadCrumb(KnowledgebaseCategory category, bool showHidden = false)
+ {
+ ArgumentNullException.ThrowIfNull(category);
+
+ var result = new List<KnowledgebaseCategory>();
+
+ //used to prevent circular references
+ var alreadyProcessedCategoryIds = new List<string>();
+
+ while (category != null && //not null
+ (showHidden || category.Published) && //published
+ (showHidden || _aclService.Authorize(category, _workContext.CurrentCustomer)) && //ACL
+ (showHidden || _aclService.Authorize(category, _workContext.CurrentStore.Id)) && //Store acl
+ !alreadyProcessedCategoryIds.Contains(category.Id)) //prevent circular references
+ {
+ result.Add(category);
+
+ alreadyProcessedCategoryIds.Add(category.Id);
+
+ category = await _knowledgebaseService.GetKnowledgebaseCategory(category.ParentCategoryId);
+ }
+
+ result.Reverse();
+ return result;
+ }
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web/Extensions/KnowledgebaseExtensions.cs b/src/Web/Grand.Web/Extensions/KnowledgebaseExtensions.cs
index 3a62da767..ab76885c9 100644
--- a/src/Web/Grand.Web/Extensions/KnowledgebaseExtensions.cs
+++ b/src/Web/Grand.Web/Extensions/KnowledgebaseExtensions.cs
@@ -1,52 +1,10 @@
using Grand.Business.Core.Extensions;
-using Grand.Business.Core.Interfaces.Cms;
-using Grand.Business.Core.Interfaces.Common.Security;
using Grand.Domain.Knowledgebase;
-using Grand.Infrastructure;
namespace Grand.Web.Extensions;
public static class KnowledgebaseExtensions
{
- /// <summary>
- /// Get category breadcrumb
- /// </summary>
- /// <param name="category">Category</param>
- /// <param name="knowledgebaseService">Knowledge base Service</param>
- /// <param name="aclService">ACL service</param>
- /// <param name="workContext">WorkContext</param>
- /// <param name="showHidden">A value indicating whether to load hidden records</param>
- /// <returns>Category breadcrumb </returns>
- public static async Task<IList<KnowledgebaseCategory>> GetCategoryBreadCrumb(this KnowledgebaseCategory category,
- IKnowledgebaseService knowledgebaseService,
- IAclService aclService,
- IWorkContext workContext,
- bool showHidden = false)
- {
- ArgumentNullException.ThrowIfNull(category);
-
- var result = new List<KnowledgebaseCategory>();
-
- //used to prevent circular references
- var alreadyProcessedCategoryIds = new List<string>();
-
- while (category != null && //not null
- (showHidden || category.Published) && //published
- (showHidden || aclService.Authorize(category, workContext.CurrentCustomer)) && //ACL
- (showHidden || aclService.Authorize(category, workContext.CurrentStore.Id)) && //Store acl
- !alreadyProcessedCategoryIds.Contains(category.Id)) //prevent circular references
- {
- result.Add(category);
-
- alreadyProcessedCategoryIds.Add(category.Id);
-
- category = await knowledgebaseService.GetKnowledgebaseCategory(category.ParentCategoryId);
- }
-
- result.Reverse();
- return result;
- }
-
/// <summary>
/// Get formatted category breadcrumb
/// Note: ACL and store acl is ignored