Ich habe folgenden Code verwendet, um benutzerdefinierte Links in das Topmenü einzufügen.
Aber die kommen in der letzten Hauptnavigation. Ich möchte zuerst über uns, dann eine andere Kategorie, dann kontaktiert uns usw.
<?php
namespace Dcw\Customer\Plugin\Block;
use Magento\Framework\Data\Tree\NodeFactory;
class Topmenu
{
/**
* @var NodeFactory
*/
protected $nodeFactory;
public function __construct(
NodeFactory $nodeFactory
) {
$this->nodeFactory = $nodeFactory;
}
public function beforeGetHtml(
\Magento\Theme\Block\Html\Topmenu $subject,
$outermostClass = '',
$childrenWrapClass = '',
$limit = 0
) {
$node = $this->nodeFactory->create(
[
'data' => [
'name' => __('ABOUT US'),
'id' => 'aboutus',
'url' => 'http://www.example.com/',
'has_active' => true,
'is_active' => true // (expression to determine if menu item is selected or not)
],
'idField' => 'id',
'tree' => $subject->getMenu()->getTree()
]
);
$subject->getMenu()->addChild($node);
$node = $this->nodeFactory->create(
[
'data' => [
'name' => __('CONTACT US'),
'id' => 'contactus',
'url' => 'http://www.example.com/',
'has_active' => true,
'is_active' => true // (expression to determine if menu item is selected or not)
],
'idField' => 'id',
'tree' => $subject->getMenu()->getTree()
]
);
$subject->getMenu()->addChild($node);
$node = $this->nodeFactory->create(
[
'data' => [
'name' => __('CATALOG DOWNLOAD'),
'id' => 'catalogdownload',
'url' => 'http://www.example.com/',
'has_active' => true,
'is_active' => true // (expression to determine if menu item is selected or not)
],
'idField' => 'id',
'tree' => $subject->getMenu()->getTree()
]
);
$subject->getMenu()->addChild($node);
}
}