add plugin configure page in admin

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

I am creating a nopCommerce 2.0 QuickBooks integration, which is currently being sold here:

http://www.ablesf.com/nopCommerce-QuickBooks-Connector-P119.aspx

I would like to add a nopCommerce plugin under the configuration menu, however, I want it next to the plugins install page (same level in sitemap). How do I change the admin menu, using the code from a plugin project?

I currently have this code:

using System.Web.Mvc;
using System.Web.Routing;
using Nop.Web.Framework.Mvc.Routes;

namespace Nop.Plugin.Accounting.QuickBooks
{
    public partial class RouteProvider : IRouteProvider
    {
        //https://www.nopcommerce.com/boards/t/12699/admin-plugin-route.aspx?p=2
        public void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute("Admin.Plugin.QuickBooks.Configure",
                 "Admin/QuickBooks/Configure",
                 new { controller = "QuickBooks", action = "Configure" },
                 new[] { "Nop.Plugin.Accounting.QuickBooks.Controllers" }
            ).DataTokens.Add("Area", "Admin");
        }

        public int Priority
        {
            get
            {
                return 0;
            }
        }
    }
}


Sadly, this route fails to work:

/Admin/QuickBooks/Configure

Any ideas? The route Plugins/QuickBooks/Configure does work. It seems that the system can't pick up on admin.
12 years ago
Hi,

OK, I figured it out:

1. Provider must inherit from IAdminMenuPlugin. Here is my code:

   public void BuildMenuItem(Telerik.Web.Mvc.UI.MenuItemBuilder menuItemBuilder)
        {
            menuItemBuilder.Text("QuickBooks");
            menuItemBuilder.Url("/Admin/Plugin/QuickBooks/Admin/Configure");
            menuItemBuilder.Route("Admin.Plugin.QuickBooks.Configure");

        }


RouteProvider:

using System.Web.Mvc;
using System.Web.Routing;
using Nop.Web.Framework.Mvc.Routes;

namespace Nop.Plugin.Accounting.QuickBooks
{
    public partial class RouteProvider : IRouteProvider
    {
        //https://www.nopcommerce.com/boards/t/12699/admin-plugin-route.aspx?p=2
        public void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute("Admin.Plugin.QuickBooks.Configure",
                 "Admin/Plugin/QuickBooks/Admin/Configure",
                 new { controller = "QuickBooks", action = "Configure" },
                 new[] { "Nop.Plugin.Accounting.QuickBooks.Controllers" }
            ).DataTokens.Add("area", "admin");
        }

        public int Priority
        {
            get
            {
                return 0;
            }
        }
    }
}


Layout file must specify admin layout:

@{
    Layout = "~/Administration/Views/Shared/_AdminLayout.cshtml";
}
@model Nop.Plugin.Accounting.QuickBooks.Models.QuickBooksModel
@using Nop.Web.Framework;
@using (Html.BeginForm())
{

    <div class="section-header">
        <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-configuration.png")" alt="" />
            QuickBooks
        </div>
    </div>
12 years ago
The other key thing is the "5 part url".  

(P.S.  your url in your first post is broken)
12 years ago
quote: Any ideas? The route Plugins/QuickBooks/Configure does work. It seems that the system can't pick up on admin.



That would be because the default admin rout is higher up in the routing chain, so the request never reaches your custom route.

A solution for this is to load your custom route on the top of the routing chain.

i.e.


            // Register admin route    
            var route = routes.MapRoute("Admin.Nop.Plugin.MyPlugin", "Admin/MyPlugin/{action}/{id}",
                                            new { controller = "MyPlugin", action = "Index", id = UrlParameter.Optional },
                                            new[] { "Nop.Plugin.Misc.MyPlugin.Controllers" });
            route.DataTokens.Add("area", "admin");
            // Re-insert route at the top of the table
            routes.Remove(route);
            routes.Insert(0, route);



Regards,
Dennis
11 years ago
I don't know why is not working for me.... it works fine when I run the website on localhost but not when I run it on my server.

I've changed in the RoutProvider the code to this

var route = routes.MapRoute("Admin.Nop.Plugin.MyPlugin", "Admin/MyPlugin/{action}/{id}",
                                            new { controller = "MyPlugin", action = "Index", id = UrlParameter.Optional },
                                            new[] { "Nop.Plugin.Misc.MyPlugin.Controllers" });
            route.DataTokens.Add("area", "admin");
            // Re-insert route at the top of the table
            routes.Remove(route);
            routes.Insert(0, route);


I have a model named Feed, I have FeedController and in View I have Feed/Index.cshtml, and in sitemap I have

<siteMapNode title="Xml Feed" nopResource="Admin.Catalog.Feed" controller="Feed" action="Index"/>


I'm only getting only the path error.
7 years ago
I faced this problem too and came up with a solution that is cleaner IMHO. This is how I made it work in nop 3.80:

First I implemented the GetConfigurationRoute from IMiscPlugin:


public void GetConfigurationRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
        {
            actionName = "Configure";
            controllerName = "Configuration";
            routeValues = new RouteValueDictionary { { "Namespaces", NAMESPACES }, { "area", null } };
        }


This is used for the "Configure" button in the PlugIns List page. The generated URL now goes by: SERVERROOT/Admin/Plugin/ConfigureMiscPlugin?SystemName=Nop.Plugin.Cadilio.Customization

So it looks like we should simply use this URL in the config menu entry. This can be done this way, by implementing the IAdminMenuPlugin.ManageSiteMap(SiteMapNode rootNode) method as follows. It triggers the ConfigureMiscPlugin method from the Plugin controller and passes in the plugin name as "SystemName" route parameter:


public void ManageSiteMap(SiteMapNode rootNode)
        {
            var menuItem = new SiteMapNode()
            {
                SystemName = "Nop.Plugin.Cadilio.Customization",
                Title = "Cadilio",
                Visible = true,
                RouteValues = new RouteValueDictionary() { { "Namespaces", NAMESPACES }, { "area", null } },
            };

            var ConfigureMenuItem = new SiteMapNode()   // add child Custom menu
            {
                Title = _localizationService.GetLocaleStringResourceByName("admin.configuration.settings", _storeContext.CurrentStore.DefaultLanguageId).ResourceValue, //   Title for your Sub Menu item
                SystemName = "Nop.Plugin.Cadilio.Customization",
                ControllerName = "Plugin",
                ActionName = "ConfigureMiscPlugin",
                Visible = true,
                RouteValues = new RouteValueDictionary() { { "SystemName",  "Nop.Plugin.Cadilio.Customization" }, { "area", "Admin" } },
            };

            menuItem.ChildNodes.Add(ConfigureMenuItem);

            var pluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "Third party plugins");
            if (pluginNode != null)
                pluginNode.ChildNodes.Add(menuItem);
            else
                rootNode.ChildNodes.Add(menuItem);

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