Building a Magento Admin Module

Have you ever wanted to build a custom module for the Magento admin panel? Today I am going to share this information hoping you will find this post useful!

Creating the Module Folder Structure

Lets start by creating the following folders:

app/code/community/Toto/ImportXml/etc
app/code/community/Toto/ImportXml/controllers
app/code/community/Toto/ImportXml/Helper

Building the Module

Within the ‘etc’ folder create a file called config.xml and paste in the following code:

configxml

Next create a file called adminhtml.xml within the ‘etc’ folder and paste in the following:

adminhtml

We need to tell Magento to load our module and to do this we need to create a file within /app/etc/modules. I called my file Toto_ImportXml.xml and it contained the below XML code:

xml

Now if you refresh your Magento admin panel, you should notice a new tab called ‘Tofu & Tomato Commerce’. However, if you click on it you will be given a PHP error saying that Magento can’t find a helper class. This is because within adminhtml.xml we told Magento that the tab is associated with the module ‘importxml’ and by default Magento looks for a helper file called Data.php.

module=”importxml”

In the config file we also declared the helper class within the global node.

globalhelper

To fix this problem we need to create a file called Data.php with the Helper folder (/app/code/community/ Toto/ImportXml/ Helper/Data.php). This will be an empty class for the time being but it will fix the warning we are currently getting. Paste the following into Data.php:

helper

Note: The class name needs to be file path structure to Helper/Data.php.

The final stage is to add the controller. This will route the user to the method specified within adminhtml.xml. For example lets take the following:

<action>greenmodule/index/index</action>

Magento will look in the module ‘Greenmodule’ for an index controller with the method called indexAction. So lets create a php file called ‘IndexController.php’ within the controllers folder (/app/code/community/Toto/ImportXml/controllers/ IndexController.php). Paste in the below PHP code:

controller

The above method simply creates a block with a the heading ‘Tofu & Tomato Commerce’ by using Magento factory methods. Refresh your browser and you click on the custom menu tab – you should now see a brand new page with the h1 tag.

Note: You may have to clear your magento cache or log out and log back in for the new page to show. This has caught me out many times.

tofu&tomato-commerce

Enjoy!

[Solved] How to use language package from locale folder in magento

Magento is a multi-language eCommerce platform, among other things. Meaning it can support multiple languages through its multiple store concept. Each store presents one locale which further breaks down to language. Default Magento installation comes with en_US locale, meaning US variation of English language. Multi-language support is a highly important feature, even essential one, for most of the modern web shops.

Today, I’ve faced an interesting task dealing with magento’s multi language feature (using different language in each store view). In this blog post, I just wanted to note what I’ve done. That’s extreme simple. Let’s go through the following steps:

1- Access to http://www.magentocommerce.com/magento-connect/ and find language package which you want i.e I find French’s package.

2- Install it from magento connect in admin’s backend.

3- From Configuration into backend. pic 1

We choose Scope from Current Configuration Scope area (left above corner) that we want to change language i.e I choice France.

4- Find Locale Options area => Set locale is French (France)

5- Save Config