Adds

How to create module in magento 2

How to create a custom module in Magento 2

Creating a module in Magento 2 consists of several steps. This short guide will explain the simple steps of creating a module in Magento 2.
Step 1: Create the module directory First, create a new directory in the app/code directory with the name of your module. For example, if your name is "MyModule", create a directory named MyModule in the app/code directory.

Step 2: Create a registration form.
php file Create a file named.php in the root directory of the module. This file is responsible for registering your module in Magento 2. The contents of the file should look like this:

PHP Code:-

<?php

\Magento\Framework\Component\ComponentRegistrar::register(

    \Magento\Framework\Component\ComponentRegistrar::MODULE,

    'MyModule',

    __DIR__

);


Step 3: Create a module.xml file Create a module.xml file in the module's other directory. This file contains the configuration and properties of the module. This is an example of a module.

XML Code:-

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">

    <module name="MyModule" setup_version="1.0.0">

        <sequence>

            <module name="Magento_Catalog"/>

        </sequence>

    </module>

</config>


Step 4: Create the main file module Create the main file in the root directory of the module. This file contains the main logic of the module. For example, if your module is about product listing, create a file named Products.php and define a class that will handle product listing logic.


Step 5: Open the module Finally, open the module by running the following command in the Magento 2 root directory:

Bash:-

php bin/magento module: enable MyModule

After enabling the module, run the following command to update the database schema:

php bin/magento setup: upgrade

[ if you want more Magento useful commands, Please Check Here] 

Free Module for News:- 👉Download

In summary, creating a module in Magento 2 involves creating a domain, domain file, configuration file, and key file and activating the module from the command line. Once enabled, your module should be available in your Magento 2 store.

No comments

Powered by Blogger.