My client processes a lot of orders over the phone and wanted to save a little time in the order creation process in Magento. We decided to add a sub-menu under the Sales/Orders menu – it only saves one click but when you’re doing a lot of orders, that adds up.
So how do you modify the Magento Admin menus? The content of the menus are controlled by various config.xml files. If you open app/code/core/Mage/Sales/etc/config.xml and look for the adminhtml tag, you’ll see (note: I’ve only included the xml relevant for the menu):
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 | <adminhtml> <menu> <sales translate="title" module="sales"> <title>Sales</title> <sort_order>20</sort_order> <depends><module>Mage_Sales</module></depends> <children> <order translate="title" module="sales"> <title>Orders</title> <action>adminhtml/sales_order</action> <sort_order>10</sort_order> </order> <invoice translate="title" module="sales"> <title>Invoices</title> <action>adminhtml/sales_invoice</action> <sort_order>20</sort_order> </invoice> <shipment translate="title" module="sales"> <title>Shipments</title> <action>adminhtml/sales_shipment</action> <sort_order>30</sort_order> </shipment> <creditmemo translate="title" module="sales"> <title>Credit Memos</title> <action>adminhtml/sales_creditmemo</action> <sort_order>40</sort_order> </creditmemo> </children> </sales> </menu> </adminhtml> |
As you can see, the xml defines the menu items for Sales. Now my goal is to take the Orders item and add two children: View Orders and New Order. Now I could add the children directly to the app/code/core/Mage/Sales/etc/config.xml file but then when I upgrade Magento, my changes would be overwritten
Instead we’ll create a custom module to define the new children.
The first step in creating a custom module is to create the directory structure. Under app/code/local create a directory for you namespace; I used ULR. Under that, create a Sales directory since we’re going to be ovrriding the default Mage/Sales functionality. Finally create an etc directory under that. So you should have something like: app/code/local/[your_name_space]/Sales/etc.
In the etc directory, create a config.xml file with these contents:
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 | <?xml version="1.0"?> <config> <modules> <ULR_Sales> <version>0.1.0</version> </ULR_Sales> </modules> <adminhtml> <menu> <sales> <children> <order> <children> <orderView translate="title" module="sales"> <title>View Orders</title> <action>adminhtml/sales_order</action> <sort_order>1</sort_order> </orderView> <orderNew translate="title" module="sales"> <title>New Order</title> <action>adminhtml/sales_order_create/index</action> <sort_order>2</sort_order> </orderNew> </children> </order> </children> </sales> </menu> </adminhtml> </config> |
The modules section defines the name of this module – we’ll use its value in a minute. As you might guess, the adminhtml section defines the new menus; we are telling Magento to “merge” our custom config.xml with the default Sales config.xml. Magento actually overrides its default config with our config.
The last step in getting our modifications to work is to create a file defining our module in app/etc/modules; call it ULR.xml (use you namespace for the filename). Place this code into it:
1 2 3 4 5 6 7 8 9 | <?xml version="1.0"?> <config> <modules> <ULR_Sales> <active>true</active> <codePool>local</codePool> </ULR_Sales> </modules> </config> |
Notice that the “name” of the module (ULR_Sales) matches the name of the module in the config.xml config section.
That should do it. Now when you mouse over the Sales menu, you will see that Orders has a sub-menu with “View Orders” and “New Order”.
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.