Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Peter 27 posts 192 karma points
    Oct 25, 2016 @ 12:54
    Peter
    0

    Adding a custom section to the Merchello tree

    Hello,

    I would like to add a TreeNode to the Merchello tree resulting in a structure somewhat like this:

    Merchello

    • Products
    • Sales
    • ...
    • My Custom MenuItem

    I have tried fiddling around with the backoffice section in merchello.config, but the resulting menu item is missing locales. I have also tried adding a TreeNode manually in the TreeNodesRendering event, doing something like this:

    private void TreeControllerBase_TreeNodesRendering(TreeControllerBase sender, TreeNodesRenderingEventArgs e)
    {
        if (sender.TreeAlias == "merchello")
        {
            var node = sender.CreateTreeNode(...);
            e.Nodes.Add(node);
        }
    }
    

    In the latter case I lack some control over the node, for example being able to specify the sort order.

    Is there a better/right way to do this, and if so what would an example of this look like?

    BR Peter

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Oct 25, 2016 @ 17:08
    Rusty Swayne
    100

    Hi Peter,

    The Merchello.config method is the quickest way - basically it just setups up an angular route ...

    The localization is based off the "id" ... e.g. add the "id" to the merchelloTree area.

    <tree id="test" title="Test" icon="icon-settings" routePath="merchello/merchello/gatewayproviderlist/manage" visible="true" sortOrder="7" />
    

    Language file.

    <area alias="merchelloTree">
       <key alias="products">Products</key>
       <key alias="sales">Sales</key>
       <key alias="customers">Customers</key>
       <key alias="marketing">Marketing</key>
       <key alias="collections">Collections</key>
       <key alias="reports">Reports</key>
       <key alias="gateways">Gateway Providers</key>
       <key alias="test">Test</key>
    </area>
    

    I'm not sure if you can override plugin areas in your own App_Plugins like you can with the core sections, but you could try it =) Would be interested in knowing if that works.

  • Peter 27 posts 192 karma points
    Oct 27, 2016 @ 12:27
    Peter
    0

    Hey Rusty,

    Thank you for the reply,

    I tried overriding the plugin areas, however I was unsuccessful - can be that I messed up something, but I found an unsolved Umbraco issue describing the same problem: http://issues.umbraco.org/issue/U4-6617

    I hope that solving this issue will allow me to add my own plugin area for handling custom Merchello views, but in the meantime I will have to place my views in the Merchello folder.

    BR Peter

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Oct 28, 2016 @ 15:24
    Rusty Swayne
    0

    I'd say the easiest way to do it would be to add a localization key in the Merchello local files ...

    /App_Plugins/Merchello/Lang/

    ... but you would have to keep replacing the key after you upgrade.

    If you go the config route, there should be no issue with routing in the back office as long as your pathing is correct. You'll notice the the Merchello.Providers App_Plugins folder, and we've done it quite a few times in other projects.

  • mmaty 100 posts 230 karma points
    Nov 09, 2016 @ 11:29
    mmaty
    0

    Hi Rusty,

    thanks for your tip with the config file. That way it's a matter of 5 minutes to make a new subtree appear in the merchello tree.

    But how about subnodes of the new subtree?

    ...
    "childNodesUrl":"/umbraco/backoffice/Merchello/MerchelloTree/GetNodes?id=suppliers&application=merchello&tree=&isDialog=false"
    ...
    

    It seems that I need to intercept the GetNodes call for the tree somehow to provide my own subnodes. How can I do that?

    -Mirko

  • mmaty 100 posts 230 karma points
    Nov 09, 2016 @ 15:57
    mmaty
    0

    EDIT: Got the solution.

    Add a tree in merchello.config:

    <tree id="suppliers" title="Suppliers" icon="icon-truck" routePath="merchello/merchello/suppliers/manage" visible="true" sortOrder="4" />
    

    Write an event handler to add the nodes. Note the setting of the HasChildren property.

    public class TreeEvents : ApplicationEventHandler
    {
    
        protected override void ApplicationStarted( UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext )
        {
            TreeControllerBase.TreeNodesRendering += TreeControllerBase_TreeNodesRendering;
        }
    
        private void TreeControllerBase_TreeNodesRendering( TreeControllerBase sender, TreeNodesRenderingEventArgs e )
        {
            if (sender.TreeAlias == "merchello")
            {
                var node = e.Nodes.FirstOrDefault(n=>n.Name == "Suppliers");
                if (node != null)
                    node.HasChildren = true;
                if (e.QueryStrings["id"] == "suppliers")
                {
                    e.Nodes.Add( sender.CreateTreeNode( "ff01", "suppliers", e.QueryStrings, "Formfakten", "icon-truck", false ) );
                    e.Nodes.Add( sender.CreateTreeNode( "ff02", "suppliers", e.QueryStrings, "Japanese", "icon-truck", false ) );
                    e.Nodes.Add( sender.CreateTreeNode( "ff03", "suppliers", e.QueryStrings, "English", "icon-truck", false ) );
                }
            }
        }
    }
    
  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 10, 2016 @ 14:31
    Rusty Swayne
    0

    Nice - had not seen that one before =)

Please Sign in or register to post replies

Write your reply to:

Draft