Book Image

Magento Extensions Development

By : Jérémie Bouchet
Book Image

Magento Extensions Development

By: Jérémie Bouchet

Overview of this book

Magento has been revealed as the best and the most popular open source e-commerce platform in the world, with about 250k+ online stores. Magento 2 is the most recent version of this awesome toolset: every new and modern development techniques are used to offer a real modular approach and powerful architecture. The book will support you in the writing of innovative and complex extensions. Starting from the beginning, we will cover how to set up a development environment that allows you to be really efficient in your functionality writing, including GIT registering and many other development tools. We then move on to provide a large overview of the best practices to scale your module in a high-load environment. After these foundations, you will see how to use test driven-development (TDD) and unit tests to handle your code. We then build a complex extension together, step by step, and internationally-ready. Next, you will find out how to protect the users’ data. Finally, we will take a look a publishing the extension on the new Magento Connect marketplace and how to protect your intellectual property. After you read this book, you will know everything you need to know to become an invaluable extension editor, whether it is for your customers’ needs or for your own requirements.
Table of Contents (16 chapters)
Magento Extensions Development
About the Author
About the Reviewer

Registering dependencies

If your module wants to override some preference values, or just change the default work of a module, you must be able to specify that your configuration must be loaded after the one you override.

In another way, your module could use some class methods defined by other modules and extensions to do its work.

We will discover dependency registering, and we are going to use it for our extension.

Discovering Composer

Composer is a package manager for PHP that provides a standard format for managing dependencies and handling complete complex installation processes. Magento 2 decided to base all platform development on Composer because it's very powerful, open source, and can manage autoloading for third party libraries and code (such as our extension).

We will now see how to use it to manage our extension and its dependencies, which are now published in a public repository on Bitbucket:

  1. Create the [extension_path]/composer.json file and add the following code:

        "name": "blackbird/ticketblaster",
        "description": "Ticket manager for events",
        "type": "magento2-module",
        "version": "1.0.0",
        "license": [
        "require": {
            "magento/magento-composer-installer": "*",
        "extra": {
            "map": [
        "authors": [
                "name": "Blackbird",
                "homepage": "",
                "role": "Developer"


    The dependencies for our extension are listed in the require key.

  2. Commit and push this file to your repository.

  3. Update the main Magento 2 composer.json file by running the following command:

    composer config repositories.blackbird vcs
  4. Install the extension by running the following command:

    composer require blackbird/ticketblaster


    This method is only recommended when you develop private projects, which are not destined to be published. Use registering in other cases!

Discovering packagist is the main and default Composer repository. It aggregates public PHP packages installable with Composer.

When you use the Composer binary to add a new extension, the first thing that Composer will do is read the main composer.json file of Magento. If your required extension isn't listed or documented, it will ask to get more information.

In the case of TicketBlaster, the extension is published in a public Git repository and we want to share it with everyone who needs it, even if they are not familiar with Composer. The simple way for all your clients to install the extension is by runnin

  1. Create an account on

  2. Once logged in, submit your package:


    At this point, Magento 2 hasn't built its package sharing system; it will be launched in a few months.

  3. Now you just have to run the following command to install your extension:

    composer require blackbird/ticketblaster


    Magento 2 uses Composer to package components and product editions. This book cannot look at all the powerful functionalities of Composer, so I recommend you read the detailed explanation on, which explains how Magento and Composer work together.