Magento Module Generator

Making Magento modules is something that any Magento developer has to do at some point to extend core functionality, however they usually contain a lot of boilerplate code that we have to repeat every time we make a new extension.

Thanks to the power of Yeoman I created a generator that can help Magento developers quickly scaffold most of the initial files that they need to create a new Magento extension, including:

  • Blocks
  • Controllers
  • Helpers
  • Models
  • Resource Models, etc

You can have a quick look at how it works in the following GIF:

View post on

The code is using the latest version of Yeoman, it’s fully unit tested and customisable, all you need to install it is NodeJS (at least version 4), and run:

npm install -g yo
npm install -g generator-magento-module

And to generate your new extension just run the following command in your Magento base directory:

yo magento-module

The code is open source on Github to feel free to submit pull requests and issues if you come across any bugs, I plan to keep updating it and adding more features in the near future.

New Order Notification Extension

I started playing around with Magento 2 so I decided to create a quick extension to learn how the development workflow changes from Magento 1.

This extension lets you display a notification on the frontend of your Magento 2 store when someone places an order. It uses the power of Pusher to leverage the complexity of real time messaging between the front and backend so make sure you create a FREE account before enabling it.


The idea behind it is to simply increase customer engagement and product exposure in your e-commerce shop, plus the added “cool factor” doesn’t hurt either.

The extension is open source and the code is available in Github so feel free to report issues and make pull requests.

File Upload Attribute Extension

I created a Magento extension that allows you to create multiple file upload attributes for your products by adding a new input type to the attribute creation form.

It’s specially useful if you want to attach PDF files, audio, video, etc, to your products without having to rely on complicated code so feel free to give it a try. The extension is available in Magento Connect and the code is open sourced in Github.

5 ways to improve your Magento code quality

With the release of the SUPEE-6788 patch for Magento some functionality regarding admin routes and SQL statement filters have been deprecates for good, and even though they haven’t been encouraged for the past couple years there’s a list of over 800 extensions that are expected to break because they still follow some of these conventions.

For this reason I’d like to talk about some deprecated functionality in Magento (some are being addressed by SUPEE-6788 and some are not), but most importantly how to fix them so that your code is more resilient to future patches and updates.

1. Adminhtml router

This is probably the biggest ofender being addressed by the SUPEE-6788 patch, you might come across some extensions registering admin routes like this:

However the correct way to do it now is by rewriting the Mage_Adminhtml controller:

This is the same approach we take when we want to rewrite any controller but in this case, instead of changing a previously defined route, we’re adding a new one.

Keep in mind that if you want to add new routes it’s recommended to use the after property, that way you make sure that all built-in admin routes are loaded first so you don’t override them by mistake. However if you do want to override an admin route make sure to change the property to before and adjust your route names accordingly.

2. SQL statements as field names

If you need to use SQL statements as field names in your collection filter queries you might have code la looks like this:

Instead the correct way to do it now is to make sure the statement is escaped before executing the SQL query:

I’ve personally never had to use SQL statements as field names in Magento but if your use case requires it then that’s the way to go about it.

3. MySQL specific resources

When registering resources it’s common to see them registered like this in the config.xml file:

However since Magento 1.6 it’s not necessary to specify the database implementation (in this case MySQL) this allows the resources to be database agnostic and makes sure they run in all the supported database engines (including Oracle and Percona). Also if you are using a single database for read and write operations you can further simplify the configuration file by removing the connection nodes.

This also applies to installation and upgrade scripts, if your filenames look like this:


You can safely remove the mysql4 prefix:


4. SQL queries in setup scripts

While on the subject of setup scripts, it is quite common to find SQL queries embedded directly in the installation and upgrade script files.

Even though there’s nothing technically wrong about this approach it can lead to:

  • Easier to make mistakes.
  • Harder to debug code, specially for more complex queries.
  • Runtime errors if queries are ran in other supported SQL implementations.

Instead Magento provides a very powerful Varien_Db_Ddl class to abstract the way we can interact with databases. It can be used to manipulate SQL tables without worrying about the underlying syntax complexities, so the above script could be roughly rewritten to:

No direct SQL queries thanks to the Varien_Db_Ddl class handling the complexity for us.

5. Multi-store setups with symlinks

It’s complex enough to run a multi-store setup with Magento so there’s no need to create more complexity by bringing symlinks into the mix. Some developers recommend to create a new for each store domain and symlink Magento’s core files into each one of them but Magento has all the tools in place to handle this without including this extra step.

At the end of Magento’s index.php file we will find the following lines:

This basically means that if the MAGE_RUN_CODE or MAGE_RUN_TYPE server variables are set then Magento will run the store or website set in those variables.

If we are using apache we can set environment variables in the .htaccess file, so all we need to do is include the following lines:

SetEnvIf Host .*newstore.* MAGE_RUN_CODE=newstore
SetEnvIf Host .*newstore.* MAGE_RUN_TYPE=website # or store

This will make Magento display the store with the code newstore code if the URL matches for example.

If you have come across similar ways to improve our code quality when working with Magento feel free to let me know in the comments.

Minimum Order Quantity Extension Live in Magento Connect

The module to limit the minimum order quantity based on the tutorial I published a while ago is now available as a standalone extension in the Magento Connect marketplace you can also contribute to the source code on Github.