Working with Magento modules
Last updated
When developing Magento 2 back-end, all the functionality you would like to add must be located in a module. Magento 2 module may contain:
Changes to admin looks
Modifications to Rest API, GraphQL endpoints
Modifications to Magento 2 routes (not ScandiPWA routes)
Do not modify the vendor folder* (a place where Magento 2 logic appears to be), this folder is auto-generated for every user, any modifications will be erased during the next composer install.
* you can do it for debugging, but do not forget to revert changes
There are two main ways to create a module in Magento 2:
Manually in app/code - for project-specific modules
Symlinking into vendor using composer - for modules you intend to share
After that, you might need to create an initial file structure for your module. Take a look at the official guide to learn how to do that!
app/codeIf you are building a module to be used by a single project, you can start by creating a new folder using a pattern <VENDOR>/<NAME> in app/code folder. For example: app/code/MyProject/MyModule.
If you are planning to share this module with other developers on ScandiPWA Marketplace or Magento Marketplace (or even within your company), opt-in to this approach. With it, you would need to define a composer.json for your package, and you might create it in any directory of your Magento 2 root (we prefer localmodules for example). Then, you need to symlink the package:
This approach is more complex for beginners. If you do not feel strong with composer it is probably better to create a module in app/code first, and then convert your module into a Composer one. See this guide for more details.
Again, there are two ways:
Composer way
The ZIP way
After the installation, the following commands must be executed to enable and run post-install scripts of the extensions:
That's a very simple operation, which requires a single command:
If installing extensions from any Marketplace, or other private composer repositories - you must make sure your credentials are valid and set. CMA uses COMPOSER_AUTH environmental variable to authenticate, but there are more ways to set the credentials. Usually, these credentials are provided by the marketplace in my account section.
All you need to do is extract the ZIP archive of an extension to app/code direcory of your Magento 2 project. Make sure the created folder matches a pattern <VENDOR>/<NAME>. For example: app/code/OtherVendor/OtherModule.
Last updated
composer config repo.<MODULE NAME> add <PATH TO MODULE>
composer require <"name" FIELD FROM composer.json FILE># see registration.php file to get Magento module name
magento module:enable <MAGENTO MODULE NAME>
magento setup:upgradecomposer require <COMPOSER PACKAGE NAME>