Magento 2 Module Development – Step By Step Guide

Home >> Blog >> Magento 2 >> Magento 2 Module Development – Step By Step Guide
Magento 2 Module Development - Step By Step Guide

What is a Magento Extension?

An extension is a logical group – that is, a directory containing blocks, controllers, helpers, models – that are related to a specific business feature. In keeping with Magento’s commitment to optimal modularity
, a module encapsulates one feature and has minimal dependencies on other modules.

Extensionsand themes are the units of customization in Magento. Modules provide business features, with supporting logic, while themes strongly influence user experience and storefront appearance.

Both components have a life cycle that allows them to be installed, deleted, and disabled. From the perspective of both merchants and extension developers, modules are the central unit of Magento organization.

The Magento Framework provides a set of core logic: PHP code, libraries, and the basic functions that are inherited by the modules and other components.

You must follow a PSR compliant structure when building a module.

In this guide we will help you create a simple Magento 2 extension which can be useful as a base to create more advanced extensions for your Magento 2 webshop

Follow below steps for Magento 2 extension development:

Disable Cache

Make sure that Magento cache is disabled so that you don’t have to clear the cache while making changes in the extension. This will save you a lot of time in development.

You can disable the cache from Admin -> System -> Cache Management -> select all types and disable.

Developer Mode

Ensure that your Magento store is in developer mode so that all changes are reflected in real time and you can view any errors you come across while doing coding.

For this you have to run commands from terminal using SSH access. Login to your Magento store SSH account then in Magento root directory run below command:

php bin/magento deploy:mode:set developer

Module Initialization

You may already have experience with this if you are Magento 1 developer and have used its terminology before for code pools. Magento 2 framework is same but doesn’t have extra code pools. They are grouped with namespaces and have to reside in app/code directory.

We have to first create files and directories to initialize and register the extension. Create below directories:

app/code/Icecube
app/code/Icecube/Firstextension

After that create a file named module.xml in directory app/code/Icecube/Firstextension/etc and place following code:



    
    

Next we need to register your module by creating file registration.php in directory app/code/Icecube/Firstextension with and inserting code:


ABOUT THE AUTHOR

Bhavin M

Bhavin M, co-founder of Icecube Digital, spends much of his time creating simple but valuable content which helps ecommerce entrepreneurs to grow their online business.

Share
Get Free Quote Now

Send us your project notes