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.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Add new fields for the EntityURL - Controller/Action - allow to define your own url and redirect to Controller/Action
supporte2bd3a97d3ef
diff --git a/src/Business/Grand.Business.Catalog/Events/Handlers/CategoryDeletedEventHandler.cs b/src/Business/Grand.Business.Catalog/Events/Handlers/CategoryDeletedEventHandler.csindex ffa14c0b9..be09e1578 100644--- a/src/Business/Grand.Business.Catalog/Events/Handlers/CategoryDeletedEventHandler.cs+++ b/src/Business/Grand.Business.Catalog/Events/Handlers/CategoryDeletedEventHandler.cs@@ -29,7 +29,7 @@ namespace Grand.Business.Catalog.Events.Handlerspublic async Task Handle(EntityDeleted<Category> notification, CancellationToken cancellationToken){//delete url- await _entityUrlRepository.DeleteManyAsync(x => x.EntityId == notification.Entity.Id && x.EntityName == "Category");+ await _entityUrlRepository.DeleteManyAsync(x => x.EntityId == notification.Entity.Id && x.EntityName == EntityTypes.Category);//delete on the productawait _productRepository.PullFilter(string.Empty, x => x.ProductCategories, z => z.CategoryId, notification.Entity.Id);diff --git a/src/Business/Grand.Business.Catalog/Events/Handlers/CollectionDeletedEventHandler.cs b/src/Business/Grand.Business.Catalog/Events/Handlers/CollectionDeletedEventHandler.csindex 50792ea96..8c23b5d48 100644--- a/src/Business/Grand.Business.Catalog/Events/Handlers/CollectionDeletedEventHandler.cs+++ b/src/Business/Grand.Business.Catalog/Events/Handlers/CollectionDeletedEventHandler.cs@@ -27,7 +27,7 @@ namespace Grand.Business.Catalog.Events.Handlerspublic async Task Handle(EntityDeleted<Collection> notification, CancellationToken cancellationToken){//delete url- await _entityUrlRepository.DeleteManyAsync(x => x.EntityId == notification.Entity.Id && x.EntityName == "Collection");+ await _entityUrlRepository.DeleteManyAsync(x => x.EntityId == notification.Entity.Id && x.EntityName == EntityTypes.Collection);//delete on the productawait _productRepository.PullFilter(string.Empty, x => x.ProductCollections, z => z.CollectionId, notification.Entity.Id);diff --git a/src/Business/Grand.Business.Catalog/Events/Handlers/ProductDeletedEventHandler.cs b/src/Business/Grand.Business.Catalog/Events/Handlers/ProductDeletedEventHandler.csindex 98b6ed26c..56062cd3d 100644--- a/src/Business/Grand.Business.Catalog/Events/Handlers/ProductDeletedEventHandler.cs+++ b/src/Business/Grand.Business.Catalog/Events/Handlers/ProductDeletedEventHandler.cs@@ -64,7 +64,7 @@ namespace Grand.Business.Catalog.Events.Handlersawait _customerGroupProductRepository.DeleteManyAsync(x => x.ProductId == notification.Entity.Id);//delete url- await _entityUrlRepository.DeleteManyAsync(x => x.EntityId == notification.Entity.Id && x.EntityName == "Product");+ await _entityUrlRepository.DeleteManyAsync(x => x.EntityId == notification.Entity.Id && x.EntityName == EntityTypes.Product);//delete product tagsvar existingProductTags = _productTagRepository.Table.Where(x => notification.Entity.ProductTags.ToList().Contains(x.Name)).ToList();diff --git a/src/Core/Grand.Domain/Seo/EntityTypes.cs b/src/Core/Grand.Domain/Seo/EntityTypes.csnew file mode 100644index 000000000..56651e9f7--- /dev/null+++ b/src/Core/Grand.Domain/Seo/EntityTypes.cs@@ -0,0 +1,17 @@+namespace Grand.Domain.Seo;++public struct EntityTypes+{+ public const string Product = nameof(Catalog.Product);+ public const string Category = nameof(Catalog.Category);+ public const string Brand = nameof(Catalog.Brand);+ public const string Collection = nameof(Catalog.Collection);+ public const string Vendor = nameof(Vendors.Vendor);+ public const string NewsItem = nameof(News.NewsItem);+ public const string BlogPost = nameof(Blogs.BlogPost);+ public const string Page = nameof(Pages.Page);+ public const string KnowledgeBaseArticle = nameof(Knowledgebase.KnowledgebaseArticle);+ public const string KnowledgeBaseCategory = nameof(Knowledgebase.KnowledgebaseCategory);+ public const string Course = nameof(Courses.Course);++}\ No newline at end of filediff --git a/src/Core/Grand.Domain/Seo/EntityUrl.cs b/src/Core/Grand.Domain/Seo/EntityUrl.csindex 3c17fe4db..5f5d2144d 100644--- a/src/Core/Grand.Domain/Seo/EntityUrl.cs+++ b/src/Core/Grand.Domain/Seo/EntityUrl.cs@@ -29,5 +29,15 @@ namespace Grand.Domain.Seo/// Gets or sets the language identifier/// </summary>public string LanguageId { get; set; }++ /// <summary>+ /// Gets or sets the controller name+ /// </summary>+ public string Controller { get; set; }++ /// <summary>+ /// Gets or sets the action name+ /// </summary>+ public string Action { get; set; }}}diff --git a/src/Web/Grand.Web.Common/Routing/SlugRouteTransformer.cs b/src/Web/Grand.Web.Common/Routing/SlugRouteTransformer.csindex 8e44ce9b7..9e667ba2b 100644--- a/src/Web/Grand.Web.Common/Routing/SlugRouteTransformer.cs+++ b/src/Web/Grand.Web.Common/Routing/SlugRouteTransformer.cs@@ -1,5 +1,6 @@using Grand.Business.Core.Interfaces.Common.Localization;using Grand.Business.Core.Interfaces.Common.Seo;+using Grand.Domain.Seo;using Grand.Infrastructure.Configuration;using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Mvc.Routing;@@ -92,76 +93,81 @@ namespace Grand.Web.Common.Routing}}- //TODO - redirect when current lang is not the same as slug lang- switch (entityUrl.EntityName.ToLowerInvariant())+ switch (entityUrl.EntityName){- case "product":+ case EntityTypes.Product:values["controller"] = "Product";values["action"] = "ProductDetails";values["productid"] = entityUrl.EntityId;values["SeName"] = entityUrl.Slug;break;- case "category":+ case EntityTypes.Category:values["controller"] = "Catalog";values["action"] = "Category";values["categoryid"] = entityUrl.EntityId;values["SeName"] = entityUrl.Slug;break;- case "brand":+ case EntityTypes.Brand:values["controller"] = "Catalog";values["action"] = "Brand";values["brandid"] = entityUrl.EntityId;values["SeName"] = entityUrl.Slug;break;- case "collection":+ case EntityTypes.Collection:values["controller"] = "Catalog";values["action"] = "Collection";values["collectionid"] = entityUrl.EntityId;values["SeName"] = entityUrl.Slug;break;- case "vendor":+ case EntityTypes.Vendor:values["controller"] = "Catalog";values["action"] = "Vendor";values["vendorid"] = entityUrl.EntityId;values["SeName"] = entityUrl.Slug;break;- case "newsitem":+ case EntityTypes.NewsItem:values["controller"] = "News";values["action"] = "NewsItem";values["newsItemId"] = entityUrl.EntityId;values["SeName"] = entityUrl.Slug;break;- case "blogpost":+ case EntityTypes.BlogPost:values["controller"] = "Blog";values["action"] = "BlogPost";values["blogPostId"] = entityUrl.EntityId;values["SeName"] = entityUrl.Slug;break;- case "page":+ case EntityTypes.Page:values["controller"] = "Page";values["action"] = "PageDetails";values["pageId"] = entityUrl.EntityId;values["SeName"] = entityUrl.Slug;break;- case "knowledgebasearticle":+ case EntityTypes.KnowledgeBaseArticle:values["controller"] = "Knowledgebase";values["action"] = "KnowledgebaseArticle";values["articleId"] = entityUrl.EntityId;values["SeName"] = entityUrl.Slug;break;- case "knowledgebasecategory":+ case EntityTypes.KnowledgeBaseCategory:values["controller"] = "Knowledgebase";values["action"] = "ArticlesByCategory";values["categoryId"] = entityUrl.EntityId;values["SeName"] = entityUrl.Slug;break;- case "course":+ case EntityTypes.Course:values["controller"] = "Course";values["action"] = "Details";values["courseId"] = entityUrl.EntityId;values["SeName"] = entityUrl.Slug;break;default:+ if (!string.IsNullOrEmpty(entityUrl.Controller) && !string.IsNullOrEmpty(entityUrl.Action))+ {+ values["controller"] = entityUrl.Controller;+ values["action"] = entityUrl.Action;+ values["SeName"] = entityUrl.Slug;+ }break;}return values;