How to add new menu in Magento Admin panel

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5,00 out of 5)
Загрузка...
Опубликовано автором Alex

While creating a new Magento theme I needed to move a few configuration options to the admin panel. For example I want to create an option to change a background color and fonts of a theme. This is very convenient, no need to know which HTML / CSS file have to be edited.

I’ve spent some time with Google to find a solution, have read dozens of articles. In this series of articles I will try to describe briefly the creation of new options in Magento Admin panel. In the first article we will look at the Magento architecture and will create a new menu item. This will be a dummy item, when you click on it nothing will happen.

Some theory.

Magento uses a programming template MVC. I will not dwell on this term, details can be read on Wikipedia page. The main idea of MVC — the separation of appearance, business logic and data into different parts, so that a change in one part, has minimal impact on other parts. You do not need to take MVC as a dogma, it is just a pattern that Magento development team have significantly revised. I met the name Configuration-Based MVC. At the heart of Magento a global XML-configuration file is located, that is used as the script for the Magento engine, it describes what modules are connected, what layout should be used, etc. You may say: «Keeping everything in one file is not very convenient.» So it is, this global XML is gathering from many local files. Thus, each module has a part of the configuration that is required to operate this module only. A very flexible mechanism, isn’t it?

Magento engine includes a very low level/basic functions, such as the formation of the global configuration file, modules connection, the call of controllers, pages formation. Shop functions are not included to Magenta engine. All functions of the store are made in the form of modules. They are in the app/code/core/Mage. To extend the functions we need to create a new module. Unlike modules developed by Magento, modules from other developers need to be located in the app/code/local.

That’s all with the theory, it’s time to have a practice. Lets start with the creating of module.

Creating a Module

In Google you can find a lot of articles on this subject. As I noticed, most of them — it is a smaller version of the article — http://www.magentocommerce.com/wiki/custom_module_with_custom_database_table. It contains a detailed description of the module directory structure and files. At this stage, do not suggest going into details, just download the extension ModuleCreator. You can download the add-on with MagentoConnect, read comments how to upgrade it to the branch 1.7.x. More simple way is to download the updated version here and copy to the root directory of your Magento site. To launch the extension:

  1. — Open www.youmagentostore.com/moduleCreator
  2. — Enter your login/password of administrator
  3. — Fill in 2 fields in the form: Namespace, Module
  4. — Click on create button
  5. — ModuleCreator will perform all routine to create the initial file of the module.

As a result, you should see
How to create - add new menu in Magento admin panel - screenshot of created files

List of files is pretty big. Lets understand what’s what.

What the module is built from

My goal in this article is to learn how to create a dummy menu item in the admin panel, so all module files will not be considered, we will consider only the important files

File — app/etc/modules/TonyTemplate_Blog.xml

This file reads by Magento engine and add file to the global config. Now Magento knows about our new module.

File — app/code/local/TonyTemplate/Blog/etc/config.xml

This is the main configuration file of our module (the file will also be added to the global XML configuration file). This file describes the structure of our menu section

.

 

With the help of <sort_order> it is possible to sort the menu items.

To create sub-elements of the menu use <children>. New elements can have arbitrary names. For example to add a new menu item Comments, you can add

As a result, you should get

That’s all with the creation of the menu.

But if you decide to delete all other files, leaving only the two described, you’ll get an error

“Fatal error: Class ‘Mage_Blog_Helper_Data’ not found”.

This is due to the peculiarities of Magento engine, it needs a helper. We don’t need it yet, so lets create an empty helper.

File — app/code/local/TonyTemplate/Blog/Helper/Data.php

So that Magento knows about helper in the module config file, the following should be left:

The archive file of the resulting module can be downloaded here

That’s all. See you in the new posts.

If you like Magento, check our premium Magento themes here.

Запись опубликована в рубрике Learning sessions с метками . Добавьте в закладки постоянную ссылку.
6 комментариев: How to add new menu in Magento Admin panel
  1. link webpage говорит:

    I actually relish, result in I found just the thing I’d been interested in. You’ve finished this 5 time extensive look! God Bless you person. Have a very wonderful working day. Bye

  2. Smithf580 говорит:

    I was very pleased to discover this website. I wanted to thank you for your time for this fantastic read!! decefdbfaceefcgd

  3. GF-REX говорит:

    Rock on! After trying tutorials on this all day, this one finally worked for me. All I wanted was a simple little link, and with this, I got just that!

  4. kartik говорит:

    Very nice idea. Working Great.!!!

  5. Shalini говорит:

    Hello ,

    It helped me a ton . Much obliged to YOU.

    I might want to take in more … have you proceeded with advance ?

  6. Alex Morco говорит:

    Here are the 5 tips to speed up Magento admin panel. (https://www.cloudways.com/blog/how-to-speed-up-magento-admin-panel/)

    Delete unused extensions
    Delete unused and outdated products
    Reindexing
    Tune up the database
    Clear the Cache

    It will help you to speed up Magento admin panel, ake a back-up before you begin working on your Magento website. Nothing is more frustrating than a broken website.

Post a comment