Plugin and RouteProvider

Posted: September 20, 2011 at 8:58 AM Quote #49373
Hi guys,

I have a plugin in NopCommerce 2.1 with a customize configuration page which is accessed through an URL. Most of the URL RouteProvider I saw in NopCommerce 2.1 follows the standard Plugins/NameOfThePlugin/Configure. The URL turns out to be not under Admin/. I'd like to be able to access the Plugin Configuration page which is not a [ChildActionOnly] through an URL which is as follow Admin/Plugins/NameOfThePlugin/Configure. I can't figure out a way to do this.

Please let me know. Thanks in advance

Tri
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: September 26, 2011 at 2:58 AM Quote #49845
Hi Tri,

You need to add a data token to your route.
Here is a code sample how to do this in the RegisterRoutes method of your RouteProvider class.

var route = routes.MapRoute(YourRouteName,
                  "admin/Plugins/YourPluginName/YourControllerName/YourActionName",
                  new { controller = "YourControllerName", action = "YourActionName" },
                  new[] { TheNamespaceOfYourControllerClass }
             );

route.DataTokens.Add("area", "admin");

Hope this helps!
This post/answer is useful
6
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
www.Nop-Templates.com - the best place for nopCommerce themes and plugins

Follow us on
Facebook: http://www.facebook.com/NopTemplates
Twitter: http://twitter.com/NopTemplates
Blog: http://www.nop-templates.com/blog

www.Nop-Templates.com
nopCommerce Solution Partners
Posted: September 26, 2011 at 8:18 AM Quote #49865
7Spikes wrote:
Hi Tri,

You need to add a data token to your route.
Here is a code sample how to do this in the RegisterRoutes method of your RouteProvider class.

var route = routes.MapRoute(YourRouteName,
                  "admin/Plugins/YourPluginName/YourControllerName/YourActionName",
                  new { controller = "YourControllerName", action = "YourActionName" },
                  new[] { TheNamespaceOfYourControllerClass }
             );

route.DataTokens.Add("area", "admin");

Hope this helps!


Thanks so much :). It works
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: October 12, 2011 at 8:16 PM Quote #51412
triho wrote:
Hi Tri,

You need to add a data token to your route.
Here is a code sample how to do this in the RegisterRoutes method of your RouteProvider class.

var route = routes.MapRoute(YourRouteName,
                  "admin/Plugins/YourPluginName/YourControllerName/YourActionName",
                  new { controller = "YourControllerName", action = "YourActionName" },
                  new[] { TheNamespaceOfYourControllerClass }
             );

route.DataTokens.Add("area", "admin");

Hope this helps!

Thanks so much :). It works


I'm having the same problem :S

Here my route provider:

public void RegisterRoutes(RouteCollection routes)
        {
            var route = routes.MapRoute("Plugin.UI.DynamicCategoryMenu.Configure",
                 "Admin/DynamicCategoryMenu/Configure",
                 new { controller = "Menu", action = "Configure" },
                 new[] { "Nop.Plugin.UI.DynamicCategoryMenu.Controllers" }
            );
            route.DataTokens.Add("area", "Admin");

            routes.MapRoute("Plugin.UI.DynamicCategoryMenu.PublicInfo",
                 "Plugins/DynamicCategoryMenu/PublicInfo",
                 new { controller = "Menu", action = "PublicInfo" },
                 new[] { "Nop.Plugin.UI.DynamicCategoryMenu.Controllers" }
            );
        }
        public int Priority
        {
            get
            {
                return 0;
            }
        }


When I load http://localhost/Admin/DynamicCategoryMenu/Configure, I get a 404...

If I change my route provider to Plugins/DynamicCategoryMenu/Configure, I can load the page @ http://localhost/Plugins/DynamicCategoryMenu/Configure without problem. Why is that?

Does anyone have a suggestion?
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
http://www.gsi-alarme-securite.com
http://www.securibay.com
Posted: October 26, 2011 at 1:40 AM Quote #52703
If I change my route provider to Plugins/DynamicCategoryMenu/Configure, I can load the page @ http://localhost/Plugins/DynamicCategoryMenu/Configure without problem. Why is that?

I have a lot to learn still, but I believe the page loads without the admin reference because as soon as the "admin/" url is used, the area routing from "Nop.Admin/AdminAreaRegistration.cs" kicks in, sending it looking for controllers in the "Nop.Admin.Controllers" namespace instead of your plugin. Of course I just might be way off on my understanding of how this works. :)

Either way my custom Plugin's RouteProvider is just about identical to the layout of esbee's one, but 7Spikes's solution doesn't seem to be working for me either. Has something changed causing this solution to no longer work?

Thanks
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: October 26, 2011 at 12:45 PM Quote #52789
esbee, try changing your custom route to something that uses at least 5 parts.

So instead of

Admin/DynamicCategoryMenu/Configure

Try something like

Admin/Plugin/DynamicCategoryMenu/Admin/Configure

There is a discussion on what I think is the same issue your having over at:

http://www.nopcommerce.com/boards/t/12699/admin-plugin-route.aspx?p=2
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: May 04, 2015 at 2:08 AM Quote #144507
Hi Guys,

I am building a plugin in 3.50.
I've added a new menu item, which appends under Plugins menu item by default.
var SubMenuItem = new SiteMapNode()
{
        Title = "Manage",
        ControllerName = "CustomManager",
        ActionName = "List",
        Visible = true,
        RouteValues = new RouteValueDictionary() { { "area", null } },
};
and the routing defined is as
routes.MapRoute("Plugin.Custom.Manager.List",
       "Plugins/CustomManager/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

also tried routing with many ways like

routes.MapRoute("Plugin.Custom.Manager.List",
       "Admin/Plugins/CustomManager/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

routes.MapRoute("Plugin.Custom.Manager.List",
       "Admin/Plugins/CustomManager/Admin/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

I've created the List.cshtml under Views-> CustomManager -> List.cshtml & the controller is named as CustomManagerController.cs

I also added in  List.cshtml
@{
    Layout = "~/Administration/Views/Shared/_AdminLayout.cshtml";
}

But still the url in the browser's generates as http://localhost:15536/CustomManager/List
instead http://localhost:15536/Admin/CustomManager/List
and also once I select my menu item, then some of the link items lose the Admin/ prefix like 'Clear cache', 'Restart application'

Please help me, what I've missed!
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: May 04, 2015 at 8:45 PM Quote #144580
danger wrote:
Hi Guys,

I am building a plugin in 3.50.
I've added a new menu item, which appends under Plugins menu item by default.
var SubMenuItem = new SiteMapNode()
{
        Title = "Manage",
        ControllerName = "CustomManager",
        ActionName = "List",
        Visible = true,
        RouteValues = new RouteValueDictionary() { { "area", null } },
};
and the routing defined is as
routes.MapRoute("Plugin.Custom.Manager.List",
       "Plugins/CustomManager/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

also tried routing with many ways like

routes.MapRoute("Plugin.Custom.Manager.List",
       "Admin/Plugins/CustomManager/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

routes.MapRoute("Plugin.Custom.Manager.List",
       "Admin/Plugins/CustomManager/Admin/List",
        new { controller = "CustomManager", action = "List", area = "Admin" },
        new[] { "Nop.Plugin.Custom.Manager.Controllers" }
).DataTokens.Add("area", "Admin");

I've created the List.cshtml under Views-> CustomManager -> List.cshtml & the controller is named as CustomManagerController.cs

I also added in  List.cshtml
@{
    Layout = "~/Administration/Views/Shared/_AdminLayout.cshtml";
}

But still the url in the browser's generates as http://localhost:15536/CustomManager/List
instead http://localhost:15536/Admin/CustomManager/List
and also once I select my menu item, then some of the link items lose the Admin/ prefix like 'Clear cache', 'Restart application'

Please help me, what I've missed!


Don't look at RouteProvider.

http://tech.sunnyw.net/2014/01/nopcommerce-register-your-customized.html
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
http://tech.sunnyw.net/search/label/NopCommerce
Posted: May 04, 2015 at 9:11 PM Quote #144581
sunnyw wrote:

Thank you sunnyw for the response and solution,

I am overriding product view, I just want to override a single partial view '_CreateOrUpdate.Info.cshtml'.
However I did that and loaded data successfully for Product Info tab from my controller of plugin but the rest tabs doesn't loads data with
404 found seems that the routing changes for all.
This is my routing for
var route =
  routes.MapRoute("Plugin.Custom.Manager.Product.Edit.Id",
   "Admin/Product/Edit/{id}",
   new { controller = "Manager", action = "Edit", area = "Admin" },
   new { id = @"\d+" },
   new[] { "Nop.Plugin.Custom.Manager.Controllers" }
);
routes.Remove(route);
routes.Insert(0, route);

and also when I navigate to Catalog -> Products -> Manage Products it removes the Admin/ prefix from 'Clear cache' & 'Restart application'.
This is my routing for Product List
var route =
  routes.MapRoute("Plugin.Custom.Manager.Product.List",
   "Admin/Product/List",
   new { controller = "Manager", action = "List", area = "Admin" },
   new[] { "Nop.Plugin.Custom.Manager.Controllers" }
  );
  
routes.Remove(route);
routes.Insert(1, route);

I am not able to figure out the issue of routing. So can please help me with this?
Thanks in advance.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
nopCommerce on facebook