向下拉菜单中添加自定义链接到magento 2菜单

时间:2019-03-27 17:26:06

标签: magento2

我正在尝试将自定义菜单链接添加到我的magento网站。我只设法添加了顶层,但不知道如何添加下拉菜单(嵌套的子项)。

    public function beforeGetHtml(
        \Magento\Theme\Block\Html\Topmenu $subject,

        $outermostClass = '',
        $childrenWrapClass = '',
        $limit = 0
    ) {
        // Add custom page in menu


            $node = $this->nodeFactory->create(
                [
                    'data' => [
                        'name' => __('Custom menu'),
                        'id' => 'customMenu',
                        'url' => $this->_urlBuilder->getUrl(null, ['_direct' =>'custommenu']),
                        'has_active' => false,
                        'is_active' => false
                    ],
                    'idField' => 'id',
                    'tree' => $subject->getMenu()->getTree()
                ]
            );
            $subject->getMenu()->addChild($node);
    }

0 个答案:

没有答案