Working with Magento modules
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)
There are two main ways to create a module in Magento 2:
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!
If 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:composer config repo.<MODULE NAME> add <PATH TO MODULE>
composer require <"name" FIELD FROM composer.json FILE>
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:
# see registration.php file to get Magento module name
magento module:enable <MAGENTO MODULE NAME>
magento setup:upgrade
That's a very simple operation, which requires a single command:
composer require <COMPOSER PACKAGE NAME>
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 modified 2yr ago