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)
    And more!

Heads up!

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

Creating Magento 2 modules

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!

Creating modules in app/code

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.

Symlinking with composer

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:
1
composer config repo.<MODULE NAME> add <PATH TO MODULE>
2
composer require <"name" FIELD FROM composer.json FILE>
Copied!
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.

Installing Magento 2 modules

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:
1
# see registration.php file to get Magento module name
2
magento module:enable <MAGENTO MODULE NAME>
3
magento setup:upgrade
Copied!

Composer way of installing Magento 2 extensions

That's a very simple operation, which requires a single command:
1
composer require <COMPOSER PACKAGE NAME>
Copied!

Heads up!

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.

Installing Magento 2 extensions with ZIP archives

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 7mo ago