Codementor Events

Tutorial: How to Create a Magento Extension

Published Aug 27, 2014Last updated Mar 25, 2019

Purpose:
– Thought it would fun to share how to make a simple Magento Extension, using a little tool called Magerun.

Requirements:
– Working Magento Store
– Command line access to the location where Magento is installed

Code Block Syntax:
– The $ represents the command line prompt.
– It is implied that we hit “enter” for each command.
– The … means that the server responded with something.

Milestones:

– Install n98-magerun (for the easy road)
– Create skeleton extension
– Check to make sure Magento recognizes it.

Step 1. Get n98-magerun.phar

(Github)

$ cd /path/to/your/magento-install 
your/magento-install$ wget https://raw..../n98-magerun.phar

You should see a few lines… then some file transfer business… then:

... (138 KB/s) - `n98-magerun.phar' saved ...

Check if it’s in the right place:

$ ls | grep n98-magerun.phar 
... 
n98-magerun.phar

And you should see: “n98-magerun.phar”. It’s there! Now let’s make it executable:

$ chmod +x ./n98-magerun.phar

Great. Now let’s try it out:

$ ./n98-magerun.phar -V 
... 
n98-magerun version 1.90.0 by netz98 new media GmbH

You should see: “n98-magerun version 1.90.0 by netz98 new media GmbH” Yay! We are on the right track.

Milestone 1 Reached!

Step 2. Create a skeleton extension

First step is to Choose a Vendor Namespace and a Module Name.
According to naming conventions, the Vendor Namespace and Module Name should be have the first letter capitalized and that is all. So for this tutorial let’s use “Bob” as our vendor, and “Scamper” as the Module.

$ ./n98-magerun.phar dev:module:create Bob Scamper
...
Created directory: /vagrant/app/code/local/Bob/Scamper
Created directory: /vagrant/app/code/local/Bob/Scamper/etc
Created file: /vagrant/app/etc/modules/Bob_Scamper.xml
Created file: /vagrant/app/code/local/Bob/Scamper/etc/config.xml

Wonderful! These are the basic files needed for every extension.

Let’s do a little check to make sure Magento is registering the extension:

$ ./n98-magerun.phar dev:module:list | grep Bob_Scamper
...
| local | Bob_Scamper | 1.0.0 | active |

Well done… You have officially made your first Magento Extension. It does absolutely nothing… but that’s ok.

Milestone 2 Reached!

Step 3. Check on Magento Backend

Now… just to check one more place… Let’s log into the Magento Backend.

Go to System > Configuration > Advanced > Disable Module Output:

We can see that Bob_Scamper made his way into our Magento Install

Milestone 3 Reached!

Thanks for playing. Let me know what you want the extension to do and we can work on it together.


This article was first posted at Geoffrey Douglas' blog.

Discover and read more posts from Geoff Douglas
get started