There are small changes in the process of creating a module in Magento 2 as compared to Magento 1.Before knowing the steps,one should know required files and folder structure for modules in Magento 2.
Folder Structure of modules
First change in Magento 2 folder structure is,Code pool (local/community) is removed. You can place your module folder in app/code/<vendor_name>.
Inside module folder,there is no much change in folders,some folders and files are added.
Required Files for modules
- registration.php : Registers the module in Magento system.
- composer.json: Specifies component dependencies and includes basic information about module like name,version,type etc.
These files are required to register your module in Magento. For content in these files find link below to download the basic module.
Steps to create module in Magento 2
- Create folders as per above folder structure.
- Create new registration.php with module name.(For content check this page)
- Create file composer.json.(For all available options in this file check this page)
- Now declare the module by module.xml file in etc folder. This file is similar to app/etc/<vendor_module>.xml file in Magento 1. We don’t need to declare modules in app/etc folder in Magento 2.It consist of Module name and version of Magento that module uses.
- Enable this module by running these commands:
bin/magento module:enable --clear-static-content Module_Name
- Refresh cache if it is enabled.
You can check your module in Stores->Configuration->Advanced->Advanced.
- In newer versions, you can check modules in System > Web setup wizard > Module Manager.
- You might not find code folder in app folder,because all default magento folders are in root/vendor folder.
- Same as theme layout files, config files will be in parts. For frontend config you can place .xml files in module/etc/fronend folder,same as for admin config, .xml files will be in etc/adminhtml folder.For global config place xml files in etc folder itself.
You can download sample module from here.This extension is to check content of files and to view folder structure only. Do not install it.
Now learn about Magento 2 theme development.
Latest posts by Ankur Dholakia (see all)
- Cuisinart DGB-400 Automatic Grind & Brew 12-Cup Coffeemaker, Black/Silver - July 24, 2021
- Create module in magento 2 - January 12, 2016
- Magento 2 – Theme Development and Theme Structure - January 6, 2016