Smartstore icon indicating copy to clipboard operation
Smartstore copied to clipboard

Could sub-menus also be added to the menu?

Open suatsuphi opened this issue 2 years ago • 6 comments

Merhaba,

Could sub-menus also be added to the menu?

https://ibb.co/GVbJ4bC there is a Terms Of Use menu under the sub menu in the example

suatsuphi avatar Nov 23 '23 12:11 suatsuphi

Hi, could you add this feature to 5.2?

suatsuphi avatar Apr 30 '24 17:04 suatsuphi

Hi,

I made an arrangement as follows.

image

@using Smartstore.Web.Rendering.Menus
@using Smartstore.Collections
@using Smartstore.Core.Content.Menus

@model MenuModel
<style>
     
    .navbar :hover > .dropdown-item {
        background-color: var(--dropdown-link-active-bg);
    }
     
    .navbar .dropdown-menu div > .dropdown-menu {
        display: block;
        visibility: hidden;
        opacity: 0;
        position: absolute;
        z-index: 1000;
        top: -8px !important;
        left: 0px !important;
        margin-left: 212px;
    }

    .navbar .dropdown-menu div:hover > .dropdown-menu {
        opacity: 1;
        display: block;
        visibility: visible;
    }

</style>
@{
    Layout = "";

    if (Model.Root == null)
    {
        return;
    }

    var cutOffItems = Model.Root.Children
        .Where(x => x.Value.Id != "brand" && x.GetMetadata<bool>("spare", false))
        .ToList();
}

<div class="megamenu simple">

    @*TODO: (core) Find a better solution, maybe by extending ViewExpander *@

    @{
        await Html.RenderPartialAsync("Components/Menu/Navbar", Model);
    }
</div>

<div class="megamenu-dropdown-container simple">
    @foreach (var node in Model.Root.Children)
    {
        <div id="[email protected]" data-id="@node.Value.Id">
            @{
                await CreateDrilldownMenuAsync(node.Children, true);
            }
        </div>
    }

    <div sm-if="cutOffItems.Any()" id="dropdown-menu--1" data-id="-1">
        @{
            await CreateDrilldownMenuAsync(cutOffItems, true);
        }
    </div>
</div>

@{
    async Task CreateDrilldownMenuAsync(IEnumerable<TreeNode<MenuItem>> nodes, bool isRoot)
    {
        if (isRoot)
        {
            @Html.Raw("<div class='dropdown-menu'>")
        }

        foreach (var node in nodes.Where(x => x.Value.Visible))
        {
            var item = node.Value;
            var itemUrl = item.GenerateUrl(this.ViewContext);
            var itemState = node.GetNodePathState(Model.Path);

            var attrs = item.GetCombinedAttributes().PrependCssClass("dropdown-item" + ((itemState & NodePathState.Selected) == NodePathState.Selected ? " selected" : ""));

            <div id="[email protected]" data-id="@item.Id" attr-class='(node.HasChildren, "dropdown-group")'>
                <a href="@itemUrl" attrs="@attrs">
                    <span sm-language-attributes-for="item">@item.Text</span>
                </a>
                @if (node.HasChildren)
                {
                    await CreateDrilldownMenuAsync(node.Children, node.HasChildren);
                }
            </div>

        }

        if (isRoot)
        {
            @Html.Raw("</div>")
        }
    }
}

<script>
    $(function () {
        $(".megamenu-container").megaMenu();
    });
</script>

suatsuphi avatar May 18 '24 14:05 suatsuphi

Can it be added to 5.2.0?

image

css

<style>

     
    .navbar .dropdown-group:hover > .dropdown-item {
        background-color: var(--dropdown-link-active-bg);
 
    }
     
    .navbar .dropdown-menu div > .dropdown-menu {
        display: block;
        visibility: hidden;
        opacity: 0;
        position: absolute;
        z-index: 1000;
        top: -8px !important;
        left: 0px !important;
        margin-left: 214px;
    }

    .navbar .dropdown-menu div:hover > .dropdown-menu {
        opacity: 1;
        display: block;
        visibility: visible;
    }

</style>

Main.cshtml

@{
    async Task CreateDrilldownMenuAsync(IEnumerable<TreeNode<MenuItem>> nodes, bool isRoot)
    {
        if (isRoot)
        {
            @Html.Raw("<div class='dropdown-menu'>")
        }

        foreach (var node in nodes.Where(x => x.Value.Visible))
        {
            var item = node.Value;
            var itemUrl = item.GenerateUrl(this.ViewContext);
            var itemState = node.GetNodePathState(Model.Path);

            var attrs = item.GetCombinedAttributes().PrependCssClass("dropdown-item" + ((itemState & NodePathState.Selected) == NodePathState.Selected ? " selected" : ""));
            <div id="[email protected]" data-id="@item.Id" attr-class='(node.HasChildren, "dropdown-group")'>
                <a href="@itemUrl" attrs="@attrs">
                    <span sm-language-attributes-for="item">@item.Text</span>
                </a>
                @if (node.HasChildren)
                {
                    await CreateDrilldownMenuAsync(node.Children, node.HasChildren);
                }
            </div>

        }

        if (isRoot)
        {
            @Html.Raw("</div>")
        }
    }
}

suatsuphi avatar Jun 12 '24 11:06 suatsuphi

but when we add a submenu, the menu does not appear

suatsuphi avatar Jun 20 '24 07:06 suatsuphi

Out-of-the-box, Smartstore only provides a 2-level menu in the front end. For more complex layouts, there is the MegaMenu plugin. In addition, the left-hand navigation bar on a category page displays the entire category tree.

muratcakir avatar Jun 20 '24 18:06 muratcakir

yes it works for categories but sometimes you may need it for pages. may be required for pages, even available in admin menus. Anyway, you used a precise language that it will not be done.

suatsuphi avatar Jun 20 '24 21:06 suatsuphi

https://github.com/smartstore/Smartstore/commit/f33f8407cc6232cec31f667698bb117da69aa925

suatsuphi avatar Jul 23 '24 13:07 suatsuphi