Get Free Audit

Extending Magento 2 Functionality

Feb 27, 2018

1868 Andrey Litvin

Extending Magento 2 Functionality

Magento 2 uses module concept as the main tool to extend or alter Magento functionality. Every module contains a chunk of PHP code that is related to the specific task like new widget, new payment method or changing the way taxes are calculated.

Installing and enabling a module

There are two main ways to install a module:

Manually

1. Download or purchase extension.
2. Upload extension to Magento root directory.
Your new module should be located in app/code directory. Example path: app/code/ModuleVendor/ModuleName
3. Enable module.
In order to enable your new module, you should run this command in the terminal as a Magento file system owner:


ecommerce development

Ecommerce Development

Take your online store to the next level with BelVG Ecommerce Development

Visit the page

4. Run setup.
After enabling the new module, you need to upgrade the Magento database. In order to perform this, do this run:

Via Composer tool

Installing a module via composer is a more reliable way to install modules. Composer automatically installs all required dependencies and makes sure that your module won’t be conflicting with others.

In order to install a module via composer, you need to do the following:
1. Purchase extension.
2. Use Composer tool to install a module.
As a Magento file system owner, run:


3. Follow steps 3 and 4 from manual installation.

Writing simple module

In order to create a basic module, first, you need to prepare your Magento installation for development. This includes enabling developer mode and turning caching off to be able to see all your changes immediately and be aware of any errors that might come up.

To change Magento mode, you need to log in as Magento file system owner and run the command:


So to switch Magento into developer mode run:

Andrey_Dubina
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Andrey


To disable caching you can run:

Creating module

All custom modules should be placed into app/code directory. Unlike Magento 1, there are no code pools. Create directory like app/code/ModueVendor/ModuleName

Then create registration.php file in this folder.


This file is responsible for registering your module. The second required file is module.xml file which should be placed in etc subfolder of our module.


This file provides Magento with information regarding the version of our module and optional dependencies.

Magento 2 Development

Take your online store to the next level with BelVG Magento 2 Development

Visit the page
Andrey Dubina
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Andrey

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *