NopCommerce 4.3 Override product details with action from plugin.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 anni tempo fa
Hi, It's me again :)

I need to override (i guess using routing) ProductDetails methode that is in ProductController.


    public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
    {
            var pattern = "{SeName}";
            if (DataSettingsManager.DatabaseIsInstalled)
            {
                var localizationSettings = endpointRouteBuilder.ServiceProvider.GetRequiredService<LocalizationSettings>();
                if (localizationSettings.SeoFriendlyUrlsForLanguagesEnabled)
                {
                    var langservice = endpointRouteBuilder.ServiceProvider.GetRequiredService<ILanguageService>();
                    var languages = langservice.GetAllLanguages().ToList();
                    pattern = "{language:lang=" + languages.FirstOrDefault().UniqueSeoCode + "}/{SeName}";
                }
            }

            endpointRouteBuilder.MapControllerRoute("Product", pattern,
         new { controller = "PluginProduct", action = "ProductDetails" });
    }


I tried to register route like that. "PluginProduct" is neame of controller inside the plugin, and ProductDetails is methode inside that controller. Still it always hits breakepoint in methode ProductDetails from ProductController (default one)

Does anyone knows right way to override nop methode with custome one from your plugin.

PS. I was changing Priority in my route provider from -20000 to 100.
2 anni tempo fa
Just one more thing, in case if change code like this


            endpointRouteBuilder.MapControllerRoute("Product", "some/hardcode/url",
         new { controller = "PluginProduct", action = "ProductDetails" });

And then navigate to:
https://localhost:44314/some/hardcode/url

Then it hits breakepoint in PluginProduct controller, but this solution is not good to me :/
2 anni tempo fa
After 8 hours spent trying to get right way to do it, i gave up and used this method.
https://www.nopcommerce.com/en/boards/topic/82002/override-generic-route-from-plugin-nopcommerce43

Hope i will not have to make another plugin with route overriding at this project. :)

It makes me sad, that nopCommerce has no proper documentation, and there is almost no community about it.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.