How to create an admin plugin?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Good day.


I’m trying to create my own plugin (using tutorials from this thread: https://www.nopcommerce.com/boards/t/11315/how-to-extending-nopcommerce-v20.aspx).

This is my register routes code:

------------
public void RegisterRoutes(System.Web.Routing.RouteCollection routes)
        {
             routes.MapRoute("Banners",
                 "Banners",
                 new { controller = "Banners", action = "Index" },
                 new[] { "Banners.Controllers" }
            );
        }


When I’m trying to see the Banners Index view in the my Web application, there are no any problems – the app can find the Banners controller and calls its Index action. Now I want to add the same view in the Admin area. This is part of SiteMap.xml:

<siteMapNode title="Banners" nopResource="Admin.ContentManagement.Banners" controller="Banners" action="Index"  />

The menu item’s path is Admin/Banners, but when I’m clicking on it, I see the standard “The resource cannot be found” message, so, the Admin app can’t find the controller. What should I do to make my plugin visible in the Admin application? I’ve tried to change the Route path to Admin/Banners and move the plugin to the Admin’s Plugin folder – no result.

Thank you in advance,
Serge
12 years ago
Serge Gusev wrote:
Good day.


I’m trying to create my own plugin (using tutorials from this thread: https://www.nopcommerce.com/boards/t/11315/how-to-extending-nopcommerce-v20.aspx).

This is my register routes code:

------------
public void RegisterRoutes(System.Web.Routing.RouteCollection routes)
        {
             routes.MapRoute("Banners",
                 "Banners",
                 new { controller = "Banners", action = "Index" },
                 new[] { "Banners.Controllers" }
            );
        }


When I’m trying to see the Banners Index view in the my Web application, there are no any problems – the app can find the Banners controller and calls its Index action. Now I want to add the same view in the Admin area. This is part of SiteMap.xml:

<siteMapNode title="Banners" nopResource="Admin.ContentManagement.Banners" controller="Banners" action="Index"  />

The menu item’s path is Admin/Banners, but when I’m clicking on it, I see the standard “The resource cannot be found” message, so, the Admin app can’t find the controller. What should I do to make my plugin visible in the Admin application? I’ve tried to change the Route path to Admin/Banners and move the plugin to the Admin’s Plugin folder – no result.

Thank you in advance,
Serge


1. If you want to see the same view in either admin or public it is the same code. Your route doesn't need to change.
2. If you want two different URL's for the same view (not recommended) you will need to add a new route.
3. Your plugin should live in the main plugin folder not the admin plugin folder.
4. To add a menu item on the admin page: Your plugin class should extend IAdminMenuPlugin and you can read how to implement the "BuildMenuItem" method on Teleriks website http://demos.telerik.com/aspnet-mvc/menu
12 years ago
skyler.severns wrote:

4. To add a menu item on the admin page: Your plugin class should extend IAdminMenuPlugin


Thank you very much.

This is my BuildMenuItem implementaion:

------------------

public class BannersProvider : BasePlugin, IAdminMenuPlugin
    {
        #region IAdminMenuPlugin Members

        public void BuildMenuItem(Telerik.Web.Mvc.UI.MenuItemBuilder menuItemBuilder)
        {
            menuItemBuilder.Text("Banners");
            menuItemBuilder.Url("/Banners");
        }

        #endregion
    }
--------------------

I can see Plugins/Banners menu now and the Admin app can find the Banners controller. But it can't find the Index view (It is an embedded resource in the plugin). What should I do in this situaion? Is there way to say: "Search my views in the resources" ?

Thank you in advance,
Serge.
12 years ago
Serge Gusev wrote:

4. To add a menu item on the admin page: Your plugin class should extend IAdminMenuPlugin


Thank you very much.

This is my BuildMenuItem implementaion:

------------------

public class BannersProvider : BasePlugin, IAdminMenuPlugin
    {
        #region IAdminMenuPlugin Members

        public void BuildMenuItem(Telerik.Web.Mvc.UI.MenuItemBuilder menuItemBuilder)
        {
            menuItemBuilder.Text("Banners");
            menuItemBuilder.Url("/Banners");
        }

        #endregion
    }
--------------------

I can see Plugins/Banners menu now and the Admin app can find the Banners controller. But it can't find the Index view (It is an embedded resource in the plugin). What should I do in this situaion? Is there way to say: "Search my views in the resources" ?

Thank you in advance,
Serge.


Is it that it cannot find your view, or that it cannot find the layout? If the view is embedded it should be found, but there is a bug that plugins cannot use admin layouts until nopCommerce version 2.2 is released.
12 years ago
skyler.severns wrote:

Is it that it cannot find your view, or that it cannot find the layout?


The view, I think:

----------
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Themes/RedRibbonStickers/Views/Banners/Index.cshtml
~/Themes/RedRibbonStickers/Views/Banners/Index.vbhtml
~/Themes/RedRibbonStickers/Views/Shared/Index.cshtml
~/Themes/RedRibbonStickers/Views/Shared/Index.vbhtml
~/Views/Banners/Index.cshtml
~/Views/Banners/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
-------------

The Index.cshtml source is:
--------------------------------
@{
    Layout = "";
}
Banners admin
--------------------------------
12 years ago
Serge Gusev wrote:

Is it that it cannot find your view, or that it cannot find the layout?

The view, I think:

----------
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Themes/RedRibbonStickers/Views/Banners/Index.cshtml
~/Themes/RedRibbonStickers/Views/Banners/Index.vbhtml
~/Themes/RedRibbonStickers/Views/Shared/Index.cshtml
~/Themes/RedRibbonStickers/Views/Shared/Index.vbhtml
~/Views/Banners/Index.cshtml
~/Views/Banners/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
-------------

The Index.cshtml source is:
--------------------------------
@{
    Layout = "";
}
Banners admin
--------------------------------


Can you clean the project. Ensure the view is marked embedded then rebuild and rerun.  Can you get your view to display under any scenario after cleaning and rebuilding? The 2.x framework definitely picks up embedded views from plugins and if it finds your controller it should find your view.

p.s. Also ensure that the plugin project file is saved once you've made your change.
12 years ago
skyler.severns wrote:
The 2.x framework definitely picks up embedded views from plugins and if it finds your controller it should find your view.


Thank you for the help. You are right - the framework works fine with the resource views. It was my stupid mistake - I did not pass the resource name in the controller's action. This way does work:

-----------
public ActionResult Configure()
        {
            return View("Banners.Views.Banners.Configure");
        }
-----------


Ok, I'm waiting for 2.2 for the Admin layout from Plugins.

UPD. Found your solution with ThemableRazorViewEngine, thank you.
12 years ago
Serge Gusev wrote:
The 2.x framework definitely picks up embedded views from plugins and if it finds your controller it should find your view.

Thank you for the help. You are right - the framework works fine with the resource views. It was my stupid mistake - I did not pass the resource name in the controller's action. This way does work:

-----------
public ActionResult Configure()
        {
            return View("Banners.Views.Banners.Configure");
        }
-----------


Ok, I'm waiting for 2.2 for the Admin layout from Plugins.

UPD. Found your solution with ThemableRazorViewEngine, thank you.


I'm glad you figured it out Serge. Good luck on the rest of your plugin! Don't forget you can submit finished plugins, gain 200 karma points, and give something back to the community :).
12 years ago
skyler.severns wrote:
Don't forget you can submit finished plugins, gain 200 karma points, and give something back to the community :).


Well, I'll try, but I'm not sure it will be helpful for the comunity - I'm a newbie in MVC =(. I prefer to share my themes:

https://www.nopcommerce.com/boards/t/10525/is-anybody-interested-in-a-new-theme.aspx
12 years ago
Hi guys,

I don't think you need to wait until nopCommerce 2.2 is released to use admin layout in your views as all of our plugins for nopCommerce 2.0 and 2.1 have admin views. You can go to our website www.Nop-Templates.com , download the FREE extensions and play with them.

Not quite sure if you have finally resolved your issue but this might be helpful anyway:
https://www.nopcommerce.com/boards/t/12009/plugin-and-routeprovider.aspx

Hope this helps!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.