Overriding the Product Controller help/clarification

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 Jahre weitere
In a plugin -

I am trying to alter the logic in the PrepareProductDetailsPageModel method of product controller.  As such, I am trying to override the route of ProductController

routes.MapLocalizedRoute("XXX.Plugin.Misc.Core.Controller.Product",
                   "{SeName}",
                   new { controller = "Product", action = "ProductDetails" },
                   new[] { "XXX.Plugin.Misc.Core.Controllers" }
              );


My product controller inherits Nop.Web.Controller.ProductController and overrides the PrepareProductDetailsPageModel method.

I could not get overriding the route to work, because of the MapLocalizedRoute causing a "The parameters dictionary contains a null entry for parameter 'productId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult ProductDetails(Int32, Int32)' in 'Nop.Web.Controllers.ProductController'" error when I try to override the route.


I have tried copying GenericPathRoute.cs and GenericPathRouteExtensions.cs to my plugin folder and modifying it to use the namespace of my controller but that has not been a success.

After lots of playing and research, it seems that the only effective way to "override" the Product Controller is by use of Action Filters.  Is this statement true?

I absolutely do not want to alter the core code as this plugin will be used in multiple sites, one on 3.4 and one on 3.5 and I want to make the upgrade path as smooth as possible to 3.6. (and future).

Please advise.  Has anyone successfully overridden the Product Controller in a plug in?  Are filters my only option?

Am I missing something?  






If anyone has any other tips please advise.
8 Jahre weitere
Just an update - I tried action filters approach and it works perfectly.  I was trying the hard approach by attempting to override the route.  Action Filters are the way to go.
8 Jahre weitere
Hi!

Can you show us?
7 Jahre weitere
Hi,

I'm having the same issue, how dit you implement the OnActionExecuting function?

Thanks,
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.