Override Category Details action in Nop.Web Catalog controller from plugin in Nop 4.0

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
Hi,

Any one tried overriding category details or any generic url via plugin?


Tried to override virtual actions and thru actionfilter but did not worked in 4.0.
5 years ago
Hi,

Has any one tried to override generic route like category details, product details, topic or blog details in Nop Commerce 4.00?
5 years ago
Hi guys,

Here is a simple solution to handle localized routes via Action filters in Nop Commerce 4.0.

Class: CustomActionFilter.cs

public class CustomActionFilter : IActionFilter
    {
        public  void OnActionExecuting(ActionExecutingContext context)
        {          
            //Check Action and controller of the route and use it to redirect to your custom action or do any customization as per your requirement.
            var actionName = ((Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)context.ActionDescriptor).ActionName;
            var controllerName = ((Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)context.ActionDescriptor).ControllerName;
            if (!string.IsNullOrEmpty(controllerName) && !string.IsNullOrEmpty(actionName))
            {
                switch (controllerName)
                {
                    case "Catalog":                        
                        context.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "TestCategory", action = "Category", categoryId =context.ActionArguments["categoryId"], command=context.ActionArguments["command"] }));
                        break;

                    case "Product":
//your customization
                        break;
                }
            }
        }

        public void OnActionExecuted(ActionExecutedContext context)
        {
            //No implementation here. Do it as per your requirement
        }

    }

=========================================

Custom Startup

public class StartupTest : INopStartup
    {
        public void ConfigureServices(IServiceCollection services, IConfigurationRoot configuration)
        {
            
            services.AddMvc(options =>
            {
                //an instant  
                options.Filters.Add(new CustomActionFilter());
                //By the type  
                options.Filters.Add(typeof(CustomActionFilter));
            });
        }

        public void Configure(IApplicationBuilder application)
        {
        }

        public int Order
        {
            get { return int.MaxValue; }
        }
    }


This may not be an appropriate solution. But can help if you want to handle generic localized routes.

I will try to find a better solution and will share with you guys.
5 years ago
puneetnopdev wrote:
Hi,

Has any one tried to override generic route like category details, product details, topic or blog details in Nop Commerce 4.00?
.

I am also looking  solution which you require.

Hope someone could help us.
5 years ago
sk5202 wrote:
Hi,

I am also looking  solution which you require.

Hope someone could help us.


You can try with the Action Filter solution as I mentioned above. Using action filters you can check the Controller and action and can perform you customization.
5 years ago
I try with the Action Filter solution as you mentioned above. Its working fine but there is an issue its not maintaining the slug
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.