I'm trying to add non category links to the top nav using the following code. It displays "Test page" & "Test page3" but not "Test page2". So I'm assuming that there is something wrong with the code as it display the first and last. Any ideas?
<?php
namespace atharna\navUpdate\Observer;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Data\Tree\Node;
use Magento\Framework\Event\ObserverInterface;
class Topmenu implements ObserverInterface
{
/**
* @param EventObserver $observer
* @return $this
*/
public function execute(EventObserver $observer)
{
/** @var \Magento\Framework\Data\Tree\Node $menu */
$menu = $observer->getMenu();
$tree = $menu->getTree();
$data = [
'name' => __('Test page'),
'id' => 'test-page',
'url' => 'test-page',
];
$node = new Node($data, 'id', $tree, $menu);
$menu->addChild($node);
$data = [
'name' => __('Test page2'),
'id' => 'test-page2',
'url' => 'test-page2',
];
$node = new Node($data, 'id2', $tree, $menu);
$menu->addChild($node);
$data = [
'name' => __('Test page3'),
'id' => 'test-page3',
'url' => 'test-page3',
];
$node = new Node($data, 'id3', $tree, $menu);
$menu->addChild($node);
return $this;
}
}
?>