1

My question is almost similar like this question except a little bit change. There is a solution for adding menu, like I also want to add menu but in a different process.

Currently I am developing a project on combo promotional offer. So therefore I want to add a sub menu under Promotion Like all other submenus image

But what I have developed is creating a separate menu named Plugins and adding a submenu there. Like this image

And here is the code I have used for creating that menu.

public void ManageSiteMap(SiteMapNode rootNode)
        {
            var menuItem = new SiteMapNode()
            {
                SystemName = "Promotion.Combo",
                Title = "Combo Offer",
                ControllerName = "PromotionCombo",
                ActionName = "Configure",
                Visible = true,
                RouteValues = new RouteValueDictionary() { { "area", null } },
            };
            var pluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "Third party plugins");
            if (pluginNode != null)
                pluginNode.ChildNodes.Add(menuItem);
            else
                rootNode.ChildNodes.Add(menuItem);
        }

I would like to know from which SystemName shall I add this submenu?

Community
  • 1
  • 1
Shoumen Agdm
  • 187
  • 15

1 Answers1

6

You can use:

public void ManageSiteMap(SiteMapNode rootNode)
{
    var menuItem = new SiteMapNode()
    {
       SystemName = "Promotion.Combo",
       Title = "Combo Offer",
       ControllerName = "PromotionCombo",
       ActionName = "Configure",
       IconClass = "fa-dot-circle-o"
       Visible = true,
       RouteValues = new RouteValueDictionary() { { "area", null } },
    };

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

System name you looked for is

Promotions

Updated answer to show you can use the IconClass in your menuItem object to add the icon in front of the menu item name.

Also, just for completeness, don't forget to add IAdminMenuPlugin to your plugin cs file, like so:

public class MyCustomPlugin : BasePlugin, IAdminMenuPlugin
Andrew
  • 238
  • 1
  • 9
Gökçer Gökdal
  • 950
  • 1
  • 11
  • 18
  • Hi @Div. Thanks for the comment but I must disagree. NopCommerce re-evaluates ManageSiteMap method of each active plugin every time admin page is being rendered. So if your plugin is disabled (uninstalled) menu item will disappear since it has not been added again for the request. Also for performance be careful not to write non-performant code at ManageSiteMap otherwise admin side page rendering will be more slow. BTW thanks a lot for the edit my friend :) – Gökçer Gökdal Jan 24 '17 at 16:15
  • Yes, of course. It disappeared. I also debugged the ManageSiteMap to reverse engineer and verify plugin loading mechanism. For anyone in interest, the code which constructs left admin menu Admnistration/Views/Shared/menu.cshtml under Nop.Web project. – Gökçer Gökdal Jan 24 '17 at 16:32
  • It's working fine, but there is a icon ahead of the list, but on, my custom menu it's not available. – Shoumen Agdm Jan 27 '17 at 08:11
  • @Shoumen Agdm you can add IconClass = "fa-dot-circle-o" inside the menuItem SiteMapNode object – Andrew Nov 06 '19 at 21:43