a client has now a shop with the following structure of categories:
Base
Shop
--Menu 1
---Sub menu 1
---Sub menu 2
--Menu 2
--etc
Normal magento would only show "shop" in the menu.
But i would like to start skip this subcategory and shop directly Menu 1, menu 2 etc in the menu.
I could remove the shop step, but thats not good for google, and would relate in many redirects in the .htaccess
because the client has many categories (100+)
Best Answer
Let's create a new module. We'll call it
StackExchange_Topmenu
.you will need the following files.
app/code/StackExchange/Topmenu/registration.php
- the registration fileapp/code/StackExchange/Topmenu/etc/module.xml
- the module declaration fileapp/code/StackExchange/Topmenu/etc/frontend/di.xml
- di file to declare a pluginapp/code/StackExchange/Topmenu/Plugin/Topmenu.php
- the actual pluginnow run in the console
bin/magento setup:upgrade
to install your module.Notice: This will remove any top level categories from the menu. If you only have one as you describe it will remove that one. If you have 2 or more, it will remove all top level categories and add the second level categories in the menu.
If you have other menu links that are not categories they will remain unchanged.
Edit
I added an
if
statement inside the plugin to make it apply for a single store. Check the id of the store and replace the1
in$storeId = 1;
with what you need.If you want to do this in a prettier way, you can add a yes/no config setting that will determine if the store should use only second level categories, and read that value in the plugin.
If not, you can leave it like this and just change the store id.