Book Image

Magento 2 Developer's Guide

Book Image

Magento 2 Developer's Guide

Overview of this book

Magento is one of the most exciting, flexible, and customizable e-commerce systems. It offers you an extensive suite of powerful tools for creating and managing an online store. After years of development, Magento 2 introduces itself with a strong emphasis on modularity, Web API's, automated testing and overall new technology stack platform.The long-awaited Magento 2 release introduces a whole new e-commerce platform to develop online stores. The all new Magento 2 architecture, Web APIs, and a host of other features are equally challenging to master as much as they are exciting to use. Tshis book will ease the learning curve by offering step-by-step guidance on how to extend the core functionality of your Magento 2 store. This book is your one-stop guide to build and customize a quality e-commerce website from the latest version of one of the largest, fastest growing, and most popular e-commerce platforms—Magento 2. We start off with an introduction to the fundamental concepts of Magento to give you a foundation to work from. We then move on to configure the development and basic production environment for Magento. After this, you’ll get to grips with the major concepts and conventions that are new to the Magento 2 platform. We then delve deeper to get to the core of automated deployments, persisting data, writing data fixture scripts and applying various backend and frontend modifications. As we near the end of the book, you will learn to make API calls and write automated tests. Finally, you will be guided through building a full-blown helpdesk module from scratch. By the end of this book, you will have learned a wide range of techniques to extend and customize your Magento 2 store to fit the requirements of your business.
Table of Contents (19 chapters)
Magento 2 Developer's Guide
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

The top-level filesystem structure


The following list depicts the root Magento filesystem structure:

  • .htaccess

  • .htaccess.sample

  • .php_cs

  • .travis.yml

  • CHANGELOG.md

  • CONTRIBUTING.md

  • CONTRIBUTOR_LICENSE_AGREEMENT.html

  • COPYING.txt

  • Gruntfile.js

  • LICENSE.txt

  • LICENSE_AFL.txt

  • app

  • bin

  • composer.json

  • composer.lock

  • dev

  • index.php

  • lib

  • nginx.conf.sample

  • package.json

  • php.ini.sample

  • phpserver

  • pub

  • setup

  • update

  • var

  • vendor

The app/etc/di.xml file is one of the most important files that we might often look into during development. It contains various class mappings or preferences for individual interfaces.

The var/magento/language-* directories is where the registered languages reside. Though each module can declare its own translations under app/code/{VendorName}/{ModuleName}/i18n/, Magento will eventually fall back to its own individual module named i18n in case translations are not found in the custom module or within the theme directory.

The bin directory is where we can find the magento file. The magento file is a script that is intended to be run from a console. Once triggered via the php bin/magento command, it runs an instance of the Magento\Framework\Console\Cli application, presenting us with quite a number of console options. We can use the magento script to enable/disable cache, enable/disable modules, run an indexer, and do many other things.

The dev directory is where we can find the Magento test scripts. We will have a look at more of those in later chapters.

The lib directory comprises two major subdirectories, namely the server-side PHP library code and fonts found under lib/internal and the client-side JavaScript libraries found in lib/web.

The pub directory is where the publicly exposed files are located. This is the directory that we should set as root when setting up Apache or Nginx. The pub/index.php file is what gets triggered when the storefront is opened in a browser.

The var directory is where the dynamically generated group type of files such as cache, log, and a few others get created in. We should be able to delete the content of this folder at any time and have Magento automatically recreate it.

The vendor directory is where most of the code is located. This is where we can find various third-party vendor code, Magento modules, themes, and language packs. Looking further into the vendor directory, you will see the following structure:

  • .htaccess

  • autoload.php

  • bin

  • braintree

  • composer

  • doctrine

  • fabpot

  • justinrainbow

  • league

  • lusitanian

  • magento

  • monolog

  • oyejorge

  • pdepend

  • pelago

  • phpmd

  • phpseclib

  • phpunit

  • psr

  • sebastian

  • seld

  • sjparkinson

  • squizlabs

  • symfony

  • tedivm

  • tubalmartin

  • zendframework

Within the vendor directory, we can find code from various vendors, such as phpunit, phpseclib, monolog, symfony, and so on. Magento itself can be found here. The Magento code is located under vendor/magento directory, listed (partially) as follows:

  • composer

  • framework

  • language-en_us

  • magento-composer-installer

  • magento2-base

  • module-authorization

  • module-backend

  • module-catalog

  • module-customer

  • module-theme

  • module-translation

  • module-ui

  • module-url-rewrite

  • module-user

  • module-version

  • module-webapi

  • module-widget

  • theme-adminhtml-backend

  • theme-frontend-blank

  • theme-frontend-luma

You will see that the further structuring of directories follows a certain naming schema, whereas the theme-* directory stores themes, the module-* directory stores modules, and the language-* directory stores registered languages.