0

I need to add submenu in top navigation menu

I am using below code but it is adding in top & not sub menu.

$menu = $observer->getMenu();
        $tree = $menu->getTree();
        $data = [
            'name'      => __('Menu item label here'),
            'id'        => 'some-unique-id-here',
            'url'       => 'url goes here',
            'has_active' => false,
            'is_active' => false //
        ];

        $node = new Node($data, 'id', $tree, $menu);
        foreach ($menu->getChildren() as $node) {
            if ($node->getName() == 'Carpet') {
                // echo "<pre>";
                // print_r($node->getId());
            }
        }
        //die();
        
        
        $menu->addChild($node);
        return $this;

I want to add submenu based on condition like for 1 top menu category I want to add 1 link e.g. color & 2nd link in another top menu category e.g. size

I have a category top navigation menu by default of magento. Now I need to add color filter for each menu item.

For e.g. Shoes is the main menu & when we hover shoes it should display colors like White, black etc.. & on click of white I want to add redirection URL of filter. So in short white will be like a submenu

  • Specify your requirement in details. – Dhiren Vasoya Aug 14 at 7:01
  • @DhirenVasoya I have added more details. – Arjun Aug 14 at 7:09
  • codes looks ok i think there could be an issue with layout files – Pramod Aug 14 at 12:02
0

Try this extension

https://github.com/faranaky/magento2-simple-menu

I think this should satisfy your requirement as it provides a feature to add Mega Menu with navigation type as product's attribute

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.