Developer forum

Forum » Development » Custom menu item to the Commerce navigation in the administration?

Custom menu item to the Commerce navigation in the administration?

Anders Ebdrup
Reply

Hi DynamicWeb,

We would like to know if it is possible to add a custom menu item to the Commerce navigation in the DynamicWeb administration.

 

For example, in the Commerce section, under areas such as Order Management or Promotions, we would like to add an additional custom menu item that links to a custom administration page/module.

Is there a supported way to extend this navigation in DW10?

More specifically:

  • Can we register a custom menu item in the Commerce navigation?
  • Can it be placed under an existing group such as “Promotions” or “Order Management” what displays a custom screen that we provide with content just like the other menu items?
  • Is there any documentation or recommended approach for this?

I have attached a screenshot showing the area where we would like to add the custom menu item.

Best regards,
Anders


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer

Hi Anders,

>> Can we register a custom menu item in the Commerce navigation?

Yes. Create a new class that inherits EcommerceSectionBase and then set the name and sort order:

public sealed class MyDemoSection : EcommerceSectionBase
{
  public MyDemoSection(NavigationContext context) : base(context)
  {
    Name = "New top-level node";
    Sort = 50; // Promotions is 40, so this places it at the end of the list.
  }
}

Then create another class that inherits NavigationNodeProvider<MyDemoSection> (where MyDemoSection is the Section created above) and add child nodes:

public sealed class DemoNodeInCustomSectionProvider : NavigationNodeProvider<MyDemoSection>
{
  internal const string SectionDemoNodeId = "SectionDemoNodeId ";
  internal const string AnotherNodeId = "AnotherNodeId";

  public override IEnumerable<NavigationNode> GetRootNodes()
  {
    yield return
      new()
      {
        Name = "Demo node in custom section",
        Id = SectionDemoNodeId,
        Icon = Icon.Ticket,
        NodeAction = NavigateScreenAction.To<VoucherListScreen>().With(new VoucherListsAllQuery()), // Change to your action / screen
        Sort = 10
      };
    yield return
      new()
      {
        Name = "Another node",
        Id = AnotherNodeId,
        Icon = Icon.Ticket,
        NodeAction = NavigateScreenAction.To<VoucherListScreen>().With(new VoucherListsAllQuery()), // Change to your action / screen
        Sort = 20
      };
  }

  public override IEnumerable<NavigationNode> GetSubNodes(NavigationNodePath parentNodePath) => [];
}

>> Can it be placed under an existing group such as “Promotions” or “Order Management” what displays a custom screen that we provide with content just like the other menu items?

Yes. Inherit NavigationNodeProvider<T> T where T is an existing NavigationSection, like PromotionsSection.

public sealed class DemoNodeProvider : NavigationNodeProvider<PromotionsSection>
{
  internal const string DemoNodeId = "DemoNodeId";

  public override IEnumerable<NavigationNode> GetRootNodes()
  {
    yield return
      new()
      {
        Name = "Demo node",
        Id = DemoNodeId,
        Icon = Icon.Ticket,
        NodeAction = NavigateScreenAction.To<VoucherListScreen>().With(new VoucherListsAllQuery()), // Change to your action / screen
        Sort = 100
      };
  }

  public override IEnumerable<NavigationNode> GetSubNodes(NavigationNodePath parentNodePath) => [];
}

Here's how the two implementations show up under Ecommerce:

>> Is there any documentation or recommended approach for this?

Yes, Here's the Custom UI section: https://doc.dynamicweb.dev/documentation/extending/administration-ui/index.html The section Area tree explains the concepts shown above: https://doc.dynamicweb.dev/documentation/extending/administration-ui/areatree.html

Hope this helps,

Imar

Votes for this answer: 1
 
Anders Ebdrup
Reply

Awesome, Imar! Thank you very much! It works very well! :-D

 

You must be logged in to post in the forum