0

I have \app\code\core\Mage\Catalog\etc\adminhtml.xml where I have the admin menu and I want to have a sub menu for my manage products item:

<products translate="title" module="catalog">
                    <title>Manage Products</title>
                    <action>adminhtml/catalog_product/</action>
                    <sort_order>0</sort_order>
                </products>

so because it is a core file I need to override it in a new place: I created app\code\local\Mage\Catalog\etc\adminhtml.xml but it doesn't read from this path

how can I override this file?

so in my extension I tried the following in my config.xml:

<?xml version="1.0" ?> <config>
    <modules>
        <Lenmar_LightBulbs>
            <version>0.0.1</version>
        </Lenmar_LightBulbs>
    </modules>
    <!-- Define frontend and backend routers -->
    <admin>
        <routers>
            <lightbulbs>
                <use>admin</use>
                <args>
                    <module>Lenmar_LightBulbs</module>
                    <frontName>LightBulbs</frontName>
                </args>
            </lightbulbs>
        </routers>
    </admin>
    <!-- /Define frontend and backend routers -->
    <global>
        <helpers>
            <lightbulbs>
                <class>Lenmar_LightBulbs_Helper</class>
            </lightbulbs>
        </helpers>  
        <blocks>
            <lightbulbs>
                <class>Lenmar_LightBulbs_Block</class>
            </lightbulbs>
        </blocks>
    </global>
    <adminhtml>  <acl>
    <resources>
        <all>
            <title>Allow Everything</title>
        </all>
        <admin>
            <children>
            <products translate="title" module="catalog">
                    <title>Manage Products</title>
                    <action>adminhtml/catalog_product/</action>
                    <sort_order>0</sort_order>
                 <children>
                 <lightbulbs module="lightbulbs">
                <title>Manage Light Bulbs</title>
                <sort_order>2</sort_order>  
                <action>lightbulbs/adminhtml_lightbulbs</action>
                </lightbulbs>
                 </children>
                </products>

                </children>
        </admin>
    </resources> </acl>
        <menu>
     <products translate="title" module="catalog">
                    <title>Manage Products</title>
                    <action>adminhtml/catalog_product/</action>
                    <sort_order>0</sort_order>
                <children>
                 <lightbulbs module="lightbulbs">
                <title>Manage Light Bulbs</title>
                <sort_order>2</sort_order>  
                <action>lightbulbs/adminhtml_lightbulbs</action>
                </lightbulbs>
                </children>
       </products>
        </menu>
       <!-- define layout updates -->
        <layout>
            <updates>
                <lightbulbs>
                    <file>lightbulbs.xml</file>
                </lightbulbs>
            </updates>
        </layout>
        <!-- /define layout updates -->
    </adminhtml>  </config>

PS: working now:

   <menu>
        <catalog>
        <children>
     <products translate="title" module="catalog">
                    <title>Manage Products</title>
                <children>
                 <lightbulbs module="lightbulbs">
                <title>Manage Light Bulbs</title>
                <sort_order>2</sort_order>  
                <action>lightbulbs/adminhtml_lightbulbs</action>
                </lightbulbs>
                </children>
       </products>
       </children>
       </catalog>
        </menu>
0

You should just add the menu from your own extension and make sure it has the same structure as in the adminhtml.xml from Mage/catalog. Copying corefiles to your local folder is not done in most cases. Alan storm has an article about creating admin extensions, you can use information from that article as a starting point.

http://alanstorm.com/magento_admin_controllers

You can read the following in the article:

  <adminhtml>
    <menu>
        <tutorial_menu translate="title" module="adminhelloworld">
            <title>Tutorial Menu</title> 
            <sort_order>9999</sort_order>
            <children>
                <first_page module="adminhelloworld">
                    <title>Our First Page</title> 
                    <action>adminhelloworld/index/index</action>
                </first_page>
            </children>
        </tutorial_menu>
    </menu> 

Appoligies I did read it wrong, will check the rest the first difference I see is that your menu does not have an action at the moment.

Edit,

I have made a test in my adminhtml.xml: this works completely, you should make sure to inherit all the structure top down, so not straight to products but from admin to catalog to products

<config>
     <menu>
        <catalog>
            <children>
                <products>
                    <children>
                        <lightbulbs translate="title" module="lightbulbs">
                            <sort_order>20</sort_order>
                            <title>Manage Light Bulbs</title>
                            <action>lightbulbs/adminhtml_lightbulbs/</action>
                        </lightbulbs>
                    </children>
                </products>
            </children>
        </catalog>
    </menu>
    <acl>
        <resources>
            <admin>
                <children>
                    <catalog>
                        <children>
                            <products>
                                <children>
                                    <lightbulbs translate="title" module="lightbulbs">
                                        <title>Manage Light Bulbs</title>
                                        <sort_order>20</sort_order>
                                    </lightbulbs>
                                </children>
                            </products>
                        </children>
                    </catalog>
                </children>
            </admin>
        </resources>
    </acl>
</config>
8
  • I tried to do that too and I was unable I will update my question – Nickool Nov 13 '14 at 18:15
  • See the edit, and plz read the article, it will teach you alot more. – Toon Van Dooren Nov 13 '14 at 18:21
  • I edited my question, thank you yes I forgot the action method but still I have problem I will try to study that and try if it works thanks – Nickool Nov 13 '14 at 18:27
  • @NeginNickparsa see my working example, add it to your adminhtml.xml – Toon Van Dooren Nov 13 '14 at 18:39
  • I got it done! :) I am happy!!!!!! but I accept yours;) thank you – Nickool Nov 13 '14 at 18:40
0

Why do you go on with bad practices ??? Feel free to create an extension for this.

I will give you an example. I am going to call this module as Rkt_ExtCatMenu.

So here is what your modules's adminhtml.xml looks like

File : app/code/local/Rkt/ExtCatMenu/etc/adminhtml.xml

<config>
    <menu>
        <catalog>
            <children>
                <products>
                    <children>
                        <submenu_code translate="title" module="rkt_extcatmenu">
                            <title>Manage Submenu</title>
                            <action>rkt_extcatmenu/catalog_product_submenu/</action>
                        </submenu_code>
                    </children>
                </products>
            </children>
        </catalog>
    </menu>
</config>

The code inside children node is important for you. Change it as your wish.

  1. submenu_code is a unique keyword for custom submenu and which will used for internal purpose and it is the reference for your submenu.

  2. title is what that will show in sub menu. Feel free to edit it.

3.action is what that is going to call when you select your submenu from the main menu.

On submenu_code node you can see a module and traslate keywords. What they are means actually ? traslate hold title as its value. It means it will traslate title field which you can see inside that node. So it is used for language translation if any. In order to translate, Magento needs a "help". This what that is provided by module attribute. It holds a value rkt_extcatmenu. It tells to magento that, use Rkt_ExtCatMenu module's helper for traslate the title part. How magento will understand rkt_extcatmenu stands for the module Rkt_ExtCatMenu ? I will come to this point later.

So this is what an admin menu configuraton. So easy. It uses a parent-children relation which is expressed in xml beautifully !!

Now it is the time to to do general configuration of your module. It should at least hold two declarations.

File : app/code/local/Rkt/ExtCatMenu/etc/config.xml

<config>
    <modules>
        <Rkt_ExtCatMenu>
            <version>1.0.0</version>
        </Rkt_ExtCatMenu>
    </modules>
    <!-- admin router definition -->
     <admin>  
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <rkt_extcatmenu before="Mage_Adminhtml">Rkt_ExtCatMenu_Adminhtml</rkt_extcatmenu>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>


    <global>
        <!-- helper definition -->
        <helpers>
            <rkt_extcatmenu> 
                <class>Rkt_ExtCatMenu_Helper</class>
            </rkt_extcatmenu>
        </helpers>
    </global>
</config>
  1. It defines admin router for your module. Here you can see that, router configuration tells to magento that, it needs router that is used by the module Mage_Adminhtml which is the module that controlls almost all admin related processes. That is enough for the description. The key point you should note here is, in order to uniquely identify this router configuration, we are using the value rkt_extcatmenu

        <rkt_extcatmenu before="Mage_Adminhtml">Rkt_ExtCatMenu_Adminhtml</rkt_extcatmenu>
    

So whenever we use rkt_extcatmenu in order to access a controller file (admin side), magento will now understand it should look inside the module Rkt_ExtCatMenu. Keeping this in mind, now I want you to again go through the menu configuration.

  <action>rkt_extcatmenu/catalog_product_submenu/</action>

Yes you can see an application of what i have said above. Here action node uses rkt_extcatmenu as its first part. Rest part will use to find which controller file specifically. In this case, Magento expects a controller file ProductController.php with a method submenuAction() in the location app/code/local/Rkt/ExtCatMenu/controllers/Adminhtml/Catalog/ProductController.php

<?php
class Rkt_ExtCatMenu_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Controller_Action
{
     public function submenuAction()
     {
           //do something here.
     }
}

So we just studied how the router worked. Now we need to look what is the important of second part of configuration file

  1. It defines a helper class. The helper configuration comes inside global node. You can see that we used a unique alias name for our helper. It is rkt_extcatmenu. So as in the case of router, whenever magento finds rkt_extcatmenu in a helper context, it will now look into Rkt_ExtCatMenu module. We have used this keyword as value for module property in our submenu.

        <submenu_code translate="title" module="rkt_extcatmenu">
    

So magento now tries to use helper class of our module for translation. So it is important to define that helper class now.

File : app/code/local/Rkt/ExtCatMenu/Helper/Data.php

<?php
class Rkt_ExtCatMenu_Helper_Data extends Mage_Core_Helper_Abstract
{
}

This is all you need for set up a menu in admin. Hope that helps future visitors too..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.