Magento 2 Basic Module

Noend Magento 2
0

Today we will built a basic module which we can use as base to start our journey to dive deep in Magento.

  1. Coding the module by handLet´s take a look how a module is looking like. As example take look of the module-catalog. I have installed Magento with composer, so you will find the modules from the core in Magento´s root directory.
    I´am using vagrant for setting up my local dev enviroment and Phpstorm. According to the image above my Magento root directory is magento2/web/magento2.2.2 the path can be different in your installation.
    Because i used composer you can find all Magento´s core modules in the folder vendor.
    The path to the module module-catalog is magento2/web/magento2.2.2/vendor/magento/module-catalog

    In the image above you can see the complete module with his subfolders and files. At this stage we need only a namespace a module a folder etc and finally 2 files which we modify slightly

    1. create a subdirectory with the name of your namespace at magento2/web/magento2.2.2/app/code/. i´am using Noend as my namespace.
    2. create a subdirectory in magento2/web/magento2.2.2/app/code/Noend with name of your module. I´ am using Test as my module name.
    3. create a subdirectory in magento2/web/magento2.2.2/app/code/Noend/Test with the name of etc.
    4. create a xml file in magento2/web/magento2.2.2/app/code/Noend/Test/etc module.xml.
    5. copy the content of magento2/web/magento2.2.2/vendor/magento/module-catalog/etc/module.xml in your file at magento2/web/magento2.2.2/app/code/Noend/Test/etc/module.xml.
    6, modify your module.xml file

    7. copy the content of magento2/web/magento2.2.2/vendor/magento/module-catalog/registration.php in your file at magento2/web/magento2.2.2/app/code/Noend/Test/registation.php
    8. modify your registration.php

    Your module structure should look like

    9. go to your shell login in ssh and go to magento´s root directory. in my case i have to type vagrant ssh and  cd /var/www/magento2/web/magento2.2.2/
    10. in your ssh type bin/magento module:enable Noend_Test
    11. when its finished type bin/magento setup:upgrade
    12. after its done verify your module is enabled by going to magento2/web/magento2.2.2/app/etc/config.php open it by the editor of your choice and check weather your module is in the array of module with the value of 1.

  2. Using Magicento to create a moduleMagicento is a plugin for Phpstorm which makes your life much easier as Magento developer
    After you have installed Magicento for Magento 2 in Phpstorm (https://magicento.com/) let´s start with our module. The namespace will be Noend, the module name testmagicento and the setup version will be 0.1.0.Use your shortcut key for Magicento, mine is alt M. A menu displays in Phpstormchose Create Module

    A small popup appears, fill in your Namespace, Module and Version.

    Click OK, in your editor you can see now your new module

    Now run bin/magento module:enable Noend_Magicento and bin/magento setup:upgrade and check your config file like we have done under I.

  3. Using Pestle to create a module
    pestle is code generator you can find it here https://alanstorm.com/magento2_pestle_code_generation/
    After installing it give it a try.run in your ssh terminal

    provide your namespace, modulename and version. And run bin/magento enable … and bin/magento setup:upgrade like above.
  4. Using Mage2Gen
    Mage2gen is an only code generator just follow the steps on their website https://mage2gen.com/

Leave a Reply

Your email address will not be published. Required fields are marked *

Do you need support in your project ?

Contact me