Adding a new plugin to the Admin menu

4 years ago
Hi, I've been following the PluralSight tutorial "Introduction to NopCommerce Plugin Development".   I've run in to a dead stop, since it seems you guys have changed the implemented method for the IAdminMenuPlugin interface as of version 3.7.   The following is the code I've used, which worked for prior versions.   I have tried as-nausea tweaking this around, and for the life of me I can't get it to work using your new implemented ManageSiteMap method.    Can someone please re-construct this for me, translate it, so that it would work under new ManageSiteMap method for the IAdminMenuPlugin interface:

public SiteMapNode BuildMenuItem()
{
   var parentNode = new SiteMapNode()
   {
        Visible = true,
        Title = "Promo Slider",
        Url = "/PromoSlider/CreateUpdatePromoSlider"
   };
   var createUpdateNode = new SiteMapNode()
    {
        Visible = true,
        Title = "New Slider",
        Url = "PromoSlider/CreateUpdatePromoSlider"
    };
   var manageSliders = new SiteMapNode()
   {
       Visible = true,
      Title = "Manage Sliders",
      Url = "/PromoSlider/ManagePromoSliders"
   }
   // now add the 2 sub-menu items
    parentNode.ChildNodes.Add(createUpdateNode);
    parentNode.ChildNodes.Add(manageSliders);

     Return parentNode;
}

Please indicate how to code to get the same effect of seeing the new plugin parent menu, with its 2 child menus, under this new method:

public void ManageSiteMap(SiteMapNode rootNode)
{

}

I found something which worked for just creating one menu item, and I can see it appear in the admin menu.  But I can't find anything which adds the 2 sub-menu items like the above sample does under prior nopCommerce versions.  

Thanks for your help!
4 years ago
Try removing the Url property from the parentNode
4 years ago
Sample of something I've used, but note it references Controller/Action rather than URL

public void ManageSiteMap(SiteMapNode rootNode)
{
    if (!_permissionService.Authorize(StandardPermissionProvider.ManageXXXXXX))
        return;

    var myPluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "MyPlugin");
    if (myPluginNode == null)
    {
        myPluginNode = new SiteMapNode()
        {
            SystemName = "MyPlugin",
            Title = "My Plugin",
            Visible = true,
            IconClass = "fa-gear"
        };
        rootNode.ChildNodes.Add(myPluginNode);
    }

    myPluginNode.ChildNodes.Add(new SiteMapNode()
    {
        SystemName = "MyPlugin.Configure",
        Title = "Configure",
        ControllerName = "Plugin",
        ActionName = "ConfigureMiscPlugin",
        Visible = true,
        IconClass = "fa-dot-circle-o",
        RouteValues = new RouteValueDictionary() { { "systemName", "Nop.Plugin.Misc.MyPlugin" } },
    });

    myPluginNode.ChildNodes.Add(new SiteMapNode()
    {
        SystemName = "MyPlugin.SomeFeatureList",
        Title = "Some Feature",
        ControllerName = "MyPlugin",
        ActionName = "SomeFeatureList",
        Visible = true,
        IconClass = "fa-dot-circle-o",
        RouteValues = new RouteValueDictionary() { { "area", "Admin" } },  //need to register this route since it has /Admin prefix
    });
}
4 years ago
Thank you! That did it!
2 days ago
How to pass rootNode to ManageSiteMap?

I mean, while calling the ManageSiteMap we have to pass rootNode object.
If I pass SiteMapNode rootNode = new SiteMapNode(); object it doesn't gives me ChildNodes info,

Please help
2 days ago
The Plugin needs to inherit IAdminMenuPlugin

    public class PluginName : BasePlugin, IAdminMenuPlugin
    {
        public void ManageSiteMap(SiteMapNode rootNode)
        {

        }
    }
2 days ago
Yidna wrote:
The Plugin needs to inherit IAdminMenuPlugin

    public class PluginName : BasePlugin, IAdminMenuPlugin
    {
        public void ManageSiteMap(SiteMapNode rootNode)
        {

        }
    }


I have added this already...my question is while calling this method how to pass the object of root node..
like
_object.ManageSiteMap(rootNode);

If I do _object.ManageSiteMap(new SiteMapNode ());
It doesn't gives me child roots
1 day ago
Why do you need to call it ?
It should be being called automatically when nopCommerce displays the Admin menu
1 day ago
Yidna wrote:
Why do you need to call it ?
It should be being called automatically when nopCommerce displays the Admin menu


Ohh..is it..many thanks