nopCommerce Version: 4.5
Steps to reproduce the problem:
Why I am doing so: I want to override this method in the catalog controller
public override async Task Category(int categoryId, CatalogProductsCommand command)
For this matter, I have to override the slugrouteTransformer but it is not hitting, it's always going to the Nop.Web.Framework.Mvc.Routing.SlugRouteTransformer
Code snippets:
public class MyCustomRouteTransformer : DynamicRouteValueTransformer
{
public override async ValueTask TransformAsync(HttpContext httpContext, RouteValueDictionary values)
{
.......
switch (urlRecord.EntityName.ToLowerInvariant())
{
case "category":
values[NopPathRouteDefaults.ControllerFieldKey] = "MyCustomCatalog";
values[NopPathRouteDefaults.ActionFieldKey] = "Category";
values[NopPathRouteDefaults.CategoryIdFieldKey] = urlRecord.EntityId;
values[NopPathRouteDefaults.SeNameFieldKey] = urlRecord.Slug;
break;
default:
}
}
Nopstartup.cs:
services.AddScoped();
RouteProvider.cs:
public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
{
var genericPattern = $"/{{SeName}}";
endpointRouteBuilder.MapDynamicControllerRoute<CustomSideRouteTransformer>(genericPattern);
}
public partial class MyCustomCatalogController : CatalogController
{
public override async Task Category(int categoryId, CatalogProductsCommand command)
{
my code
}
}
THanks
Aditya