9.2 C
Thursday, March 23, 2023

Create custom module in Magento 2

Must read

In this topic, we going to see how to create module in Magento 2 step by step in simple way.

What is Module in Magento 2 ? Create custom module

The module is a structural element for M2 Magento 2 , the full system is built on modules. So that’s why typically, the first step in the creation of customization is building a module.

For creating a module in magento 2, we need to complete the following all steps:

  • Create module folder.
  • Create etc/module.xml file.
  • Create registration.php file.
  • Run bin/magento setup:upgrade script to install the new module.
  • Check that the module is working.

To understand more about create custom module in magento 2 we will do a practice.

Lets do this practically for create custom module, you need to follow step by step.

Step 1: Create a new module called Techone_Custommodule :

  • Create the namespace Techone in the path app\code.
  • Create the module name PluginTutorial in the path app\code\Techone.
  • Create the file named registration.php in the path app\code\Techone\Custommodule
use \Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Techone_Custommodule', __DIR__);

Step 2 : Declare module:

  • Create the file name module.xml in the path app\code\Techone\Custommodule\etc.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    <module name="Techone_PluginTutorial" >

Step 3 : Run setup upgrade command

After Running this command it makes your new module active and notifying Magento of its presence.

$ php bin/magento setup:upgrade

After running this above command you will see in cmd or git bash your module created. You can check the status of the module whether the module is enabled or disabled. To check this you have to execute the below command in cmd or git bash. You can download git bash by click this link to download git bash.

$ bin/magento module:status [--enabled] [--disabled] [<module-name>]
  • The --enabled : lists all enabled modules.
  • The --disabled : lists all disabled modules.
  • The <module-name> : specifies which module to return the status of.

With the above command you can check the module status for module which you have create.So finally we have done with the creation of module in magento 2. From below video you come to know more deeply about module creation.

- Advertisement -spot_img

More articles


Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest article