Let’s initiate a discussion!!
1) To define plugin, add below code
1 2 3 4 5 6 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Theme\Block\Html\Topmenu"> <plugin name="custom_menu_item" type="Magemonkeys\AddCustomeMenu\Plugin\Topmenu" sortOrder="10" disabled="false"/> </type> </config> |
in your app/code/Magemonkeys/AddCustomeMenu/etc/frontend/di.xml file.
2) Now, Create Topmenu.php Plugin file at app/code/Magemonkeys/AddCustomeMenu/Plugin/ and paste the below code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
<?php namespace Magemonkeys\AddCustomeMenu\Plugin; use Magento\Framework\Data\Tree\NodeFactory; use Magento\Framework\UrlInterface; class Topmenu { /** * @var NodeFactory */ protected $nodeFactory; /** * @var UrlInterface */ protected $urlBuilder; /** * @param NodeFactory $nodeFactory * @param UrlInterface $urlBuilder */ public function __construct( NodeFactory $nodeFactory, UrlInterface $urlBuilder ) { $this->nodeFactory = $nodeFactory; $this->urlBuilder = $urlBuilder; } public function beforeGetHtml( \Magento\Theme\Block\Html\Topmenu $subject, $outermostClass = '', $childrenWrapClass = '', $limit = 0 ) { /** * Parent Menu */ $menuNode = $this->nodeFactory->create( [ 'data' => $this->getNodeAsArray("CMS Pages", "cms-page"), 'idField' => 'id', 'tree' => $subject->getMenu()->getTree(), ] ); /** * Add Child Menu */ $menuNode->addChild( $this->nodeFactory->create( [ 'data' => $this->getNodeAsArray("Abouts us", "abouts-us"), 'idField' => 'id', 'tree' => $subject->getMenu()->getTree(), ] ) ); $menuNode->addChild( $this->nodeFactory->create( [ 'data' => $this->getNodeAsArray("Store Location", "store-location"), 'idField' => 'id', 'tree' => $subject->getMenu()->getTree(), ] ) ); $subject->getMenu()->addChild($menuNode); } protected function getNodeAsArray($name, $id) { $url = $this->urlBuilder->getUrl($id); return [ 'name' => __($name), 'id' => $id, 'url' => $url, 'has_active' => false, 'is_active' => false, ]; } } |
3) Output :
[crayon-641f01917e829819942464/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.