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)

Heads up!

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:

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.

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:

# see registration.php file to get Magento module name
magento module:enable <MAGENTO MODULE NAME>
magento setup:upgrade

Composer way of installing Magento 2 extensions

That's a very simple operation, which requires a single command:

composer require <COMPOSER PACKAGE NAME>

Heads up!

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 updated

Was this helpful?