How is a Magento Extension created?;
An important factor in the Magento platform, crucial for its operation, are extensions or modules. A previous article mentioned the importance and what one should know about extensions. In the article “How important are Magento Modules?;” detailed information can be found. In reality, the cost of extensions is crucial for the development of a Magento store and some people turn to creating personalized extensions. But how easy is this and what are the benefits and pitfalls that may be hidden?;
What is a Magento extension?;
A Magento extension is a package of code that is responsible for specific functionality in Magento. Technically, it is a directory containing PHP and XML files in blocks, controllers, helpers, and models that are related to a specific business feature. While both a module and an extension are similar in theory, the term module often refers to core code, i.e. code that is part of Magento itself. In contrast, an extension refers to a component that can extend and customize Magento functionality. Extensions can be distributed and installed across multiple stores to help achieve specific functionality.
Magento scalability.
Over the years, the main focus behind Magento's development has been to maximize its extensibility. At the core of Magento's development model is the practice of extending the core code. This strategy helps maintain the Magento core code and allows merchants and developers to customize Magento to their requirements. Magento's code follows most of the PSR2 Coding Standards for PHP.
In addition, Magento is also based on many well-known architectural structures and incorporates recognized and tested software structures called design patterns. Of these, MVC (model-view-controller) is the one most relevant to developing an extension. Using these structures and design patterns helps PHP developers navigate development issues that could arise while developing extensions.
By placing code in modules, an extension is self-contained, making it possible to modify or replace it without negatively affecting other areas of the code. The purpose of any extension is to provide specific features by extending existing functionality or implementing new ones. Finally, designing each extension to work independently mitigates the risk of one extension conflicting with another and allows them to work in parallel.

Magento extensions are crucial to its operation.
Types of Magento extensions.
- Magento has an official marketplace called Magento Marketplace, where users of the platform can purchase and download third-party extensions and themes to extend their online stores. Magento has a robust Extension Quality Program that combines Magento expertise, development guidelines, and verification tools to ensure that all extensions in its marketplace meet coding standards and follow best practices.
- Out-of-the-box extensions. In addition to the extensions in its marketplace, Magento comes with additional third-party extensions. These extensions are called “Vendor Pack Extensions”. They have been thoroughly tested before being included in any supported version of Magento for their quality. Some of the “Vendor Pack Extensions” that will be packaged with the latest Magento releases are Amazon Pay, dotdigital, Klarna, and Vertex.
- Custom extensions. Many store owners often overuse third-party extensions, as they are cheap and easily accessible. However, overusing such extensions, and especially using poorly coded extensions, can hinder a store's performance. It is highly recommended to use custom extensions to avoid such an outcome. In cases where custom creation is not feasible, out-of-the-box third-party extensions should be tested before deploying to live stores and modified to use only the required functionality.
How to create a custom extension in Magento 2.
Magento 2 extension development is big news in the market. Already Magneto 2 has helped thousands of e-commerce stores by providing superior experiences to their customers. It is more mobile-friendly than Magento 1. Magento 2 has been developed to support PWA (Progressive Web Applications). It also acts as a highly developed platform that provides: powerful marketing, smooth catalog management tools, visual merchandising, stage and preview updates, and search engine optimization. Recently, Magento 2 extension development has been carried out.
- The latest Magento 2 version must be installed on the system.
- Magento cache should be disabled.
- Developer mode selection: Allows checking all errors.

The creation of Magento Modules opens up new avenues for development.
Steps for developing Magento Module.
Step 1: Create extension files and folders for installation and registration. Create the folder and extension:
app/code/Fixit/HelloWorld
In case the code folder does not exist, it can be created manually. Here, the extension name is Helloworld and the extension namespace is the Fixit folder.
Now with another code, a module.XML file needs to be created in the “Helloworld” folder. To register this module, a register.php file needs to be created in the same helloworld folder. Go to Magento 2 root and then run the upgrade command.
app/code/Fixit/HelloWorld/etc/module.xml
And the content:
<?xml version=”1.0″?>
<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:Module/etc/module.xsd”>
<module name=”Fixit_HelloWorld” setup_version=”1.0.0″>
</module>
</config>
Step 2: Create etc/registration.php file
app/code/Fixit/HelloWorld/registration.php
And the content:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
‘'Fixit_HelloWorld',
__DIR__
);
Step 3: Turn on the unit:
php bin/magento module:enable Fixit_HelloWorld
The module should be available now. After this step, when the website is opened in the browser, an error will be received saying “Upgrade your database”:
php bin/magento setup:upgrade
Then, because the website will appear broken:
php bin/magento setup:static-content:deploy
After the deployment is complete, the extension is visible from the backend in System Configuration -> Advanced -> Disable Modules Output. Now, a controller will be created for module testing. But before, a route for the HelloWorld module will be created. Routes in magento are divided into 3 parts: Route Address Name, Controller and Action like the following example:
http://fixit.com/index.php/frontname/controller/action
To add a route, a routes.xml file must be created:
app/code/Fixit/HelloWorld/etc/frontend/routes.xml
since this is a frontend path, it is added to the frontend/ folder otherwise it should be added to the adminhtml/ folder
The content:
<?xml version=”1.0″ ?>
<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:App/etc/routes.xsd”>
<router id=”standard”>
<route frontName=”helloworld” id=”helloworld”>
<module name=”Fixit_HelloWorld”/>
</route>
</router>
</config>
It should create another folder:
app/code/Fixit/HelloWorld/Controller/Index/Test.php
and content:
<?php
namespace Fixit\HelloWorld\Controller\Index;
class Test extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $pageFactory)
{
$this->_pageFactory = $pageFactory;
return parent::__construct($context);
}
public function execute()
{
echo “Hello World”;
exit?;
}
}
The Url must have this format:
http://<yourhost.com>/helloworld/index/test
The first Magento extension was created, which when opened displays: “Hello World!” However, the field of Magento extensions is vast and there is a lot to learn in order to proceed with their development.




