Override Default Category action method of Catalog Controller using Plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
sohel wrote:




Ok let me understand your requirement first. If you want to show "CategoryNavigation.cshtm" view from your plugin then at _ColumnsTwo.cshtml you may write

@Html.Action("YourCustomCategoryNavigation", "YourPluginController", new { currentCategoryId = currentCategoryId, currentProductId = currentProductId })

The "YourCustomCategoryNavigation" method will have the same functionality as the default one but it will return

return PartialView("~/Plugins/YourPlugin/Views/YourView/CategoryNavigation.cshtml", model);



Hi Dear sina.islam,

What will be happened when the plugin will unavailable or uninstall?

if anybody write

@Html.Action("YourCustomCategoryNavigation", "YourPluginController", new { currentCategoryId = currentCategoryId, currentProductId = currentProductId })

and the plugin is not exist then the above method will not work.

And also error occurred!!!!!


obviously it will occur error as action is exist at plugin controller and at beginning I also told that it can be handle by widget plugin. If anybody do this by widget plugin then after uninstall the plugin the application run as it run before.
7 years ago
rahat wrote:
My plugin has a custom view engine as following:
CustomViewEngine : ThemeableRazorViewEngine

The plugin has a view file called CategoryNavigation.cshtml which also exists at Views\Catalog\CategoryNavigation.cshtml
Now if I delete the files the error reported by the view engines are as following:



As you can see the first searched location is the plugin folder. If the file exists in the plugin folder it is displayed without any error. But if the file exists both in the plugin folder and in Views\Catalog  then the view from Views\Catalog  is rendered instead of the plugin folder. Tho that is way down in the search location.
Any idea what might be causing the issue?

Nop 3.70


Plugin's View Engine's priority is high so happen. For testing it you can put the file in a plugin(which has high index) and also theme. Then you will find view will use from that plugin not  from theme ..for testing it you can use two different text.
7 years ago
sina.islam wrote:




Ok let me understand your requirement first. If you want to show "CategoryNavigation.cshtm" view from your plugin then at _ColumnsTwo.cshtml you may write

@Html.Action("YourCustomCategoryNavigation", "YourPluginController", new { currentCategoryId = currentCategoryId, currentProductId = currentProductId })

The "YourCustomCategoryNavigation" method will have the same functionality as the default one but it will return

return PartialView("~/Plugins/YourPlugin/Views/YourView/CategoryNavigation.cshtml", model);



Hi Dear sina.islam,

What will be happened when the plugin will unavailable or uninstall?

if anybody write

@Html.Action("YourCustomCategoryNavigation", "YourPluginController", new { currentCategoryId = currentCategoryId, currentProductId = currentProductId })

and the plugin is not exist then the above method will not work.

And also error occurred!!!!!

obviously it will occur error as action is exist at plugin controller and at beginning I also told that it can be handle by widget plugin. If anybody do this by widget plugin then after uninstall the plugin the application run as it run before.


Well User can switch themes, Can restore nopCommerce files. So its not a viable solution to edit the nopCommerce files.
The way I am trying to do is _CategoryNavigation.cshtml file exists in theme and also in my plugin.
So if my plugin has a higher route (which is already done as you can see in the search locations) then the view from the plugin will be rendered not the Themes\Views\Catalog folder.
Same plugin works properly on nopCommerce 2.4 but not for 3.7.
7 years ago
sohel wrote:
My plugin has a custom view engine as following:
CustomViewEngine : ThemeableRazorViewEngine

The plugin has a view file called CategoryNavigation.cshtml which also exists at Views\Catalog\CategoryNavigation.cshtml
Now if I delete the files the error reported by the view engines are as following:



As you can see the first searched location is the plugin folder. If the file exists in the plugin folder it is displayed without any error. But if the file exists both in the plugin folder and in Views\Catalog  then the view from Views\Catalog  is rendered instead of the plugin folder. Tho that is way down in the search location.
Any idea what might be causing the issue?

Nop 3.70

Plugin's View Engine's priority is high so happen. For testing it you can put the file in a plugin(which has high index) and also theme. Then you will find view will use from that plugin not  from theme ..for testing it you can use two different text.


Well the plugin has a higher index. As the first search location is the Feed plugin folder.
I have different texts on the views so it is certain that the view from the plugin is not rendered when the file exists in both locations.
7 years ago
sina.islam wrote:
I did everything as described and I just changed the following code:

data.Values["controller"] = "WidgetsBrowse";
data.Values["action"] = "categoryNew";

Still I am getting the same error. Do I need to change anything else?

Thanks

Can you please give me your email address? I want to send you the working code that I implement at my plugin. Is it possible to send email address?


I'm getting the same error, after I did everything as described. Can you tell me how you fixed this?
7 years ago
marijag wrote:
I did everything as described and I just changed the following code:

data.Values["controller"] = "WidgetsBrowse";
data.Values["action"] = "categoryNew";

Still I am getting the same error. Do I need to change anything else?

Thanks

Can you please give me your email address? I want to send you the working code that I implement at my plugin. Is it possible to send email address?

I'm getting the same error, after I did everything as described. Can you tell me how you fixed this?

It was not fixed. I excluded the one which is not needed for now.
7 years ago
I want to override the generic route for category action, I did everything like is described here and it's working now but for other generic routes I get the following error:

"Multiple types were found that match the controller named 'Product'. This can happen if the route that services this request ('{generic_se_name}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

The request for 'Product' has found the following matching controllers:
Nop.Web.Controllers.ProductController
Nop.Admin.Controllers.ProductController"
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.