Timeline: 2h
...
Note before start developing module in magento
-Enable dev mode:
Enable the developer mode: bin/magento deploy:mode:set developer
Rename file : pub/errors/local.xml.sample to local.xml
-Magento has cache, so if you doesn't see the code change on the screen, you can run:
Code Block |
---|
bin/magento cache:clean |
to clean the cache
-Some time when code, you need to clear some directory: https://devdocs.magento.com/guides/v2.4/howdoi/php/php_clear-dirs.html
in most case, it is “generated” folder
...
https://devdocs.magento.com/guides/v2.4/architecture/extensibility.html
Module is a structural element of Magento 2 – the whole system is built upon modules. Typically, the first step in creating a customization is building a module.
...
Let’s go through each of these steps in detail.
Create the module folder
Let’s create the folder app/code/Learning and inside this folder place another folder: FirstUnit. If you're using the command line, the code would be:
...
Module name:
Learning_FirstUnit
(based on the folders we created)Dependency: Magento_Catalog. We could have multiple dependencies. In this case, we would put
<module name=”..” />
nodes under the sequence node.
Create the registration.php file
Each module must have this file, which tells Magento how to locate the module. Continuing our example, create the file app/code/Learning/FirstUnit/registration.php
. Then put the following content into it:
...
The only thing that varies is the module name, which in our case is Learning_FirstUnit
.
Run the “setup:upgrade” command
Running this command makes your new module active, notifying Magento of its presence.
...
It should echo a large amount of output, one line of which should be Learning_FirstUnit
. Verify that this line of code is there.
Check that the new module is active¶
So far, we haven't added any useful code to our module – it is still empty (and therefore invisible). In order to verify that it has been recognized, check the file app/etc/config.php
. It has a list of auto-generated modules that are active.
...
Employing these steps, you can successfully create a new module in Magento 2
Exercise:
Create module with the vendor: Magestore, module name: your name