Book Image

Magento 2 Development Cookbook

Book Image

Magento 2 Development Cookbook

Overview of this book

With the challenges of growing an online business, Magento 2 is an open source e-commerce platform with innumerable functionalities that gives you the freedom to make on-the-fly decisions. It allows you to customize multiple levels of security permissions and enhance the look and feel of your website, and thus gives you a personalized experience in promoting your business.
Table of Contents (18 chapters)
Magento 2 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Magento is one of the most popular e-commerce platforms on the market. It contains a lot of e-commerce functionality, it is stable, and it is free. This means that a lot of people choose Magento for their online business.

The first stable version of Magento was released in 2008. The later releases were based on the first version of Magento. Technology changes quickly and Magento needed a big update—a big release Magento 2 is now ready.

Developing in Magento is not as easy as you would expect. Even if you have knowledge of Magento 1, a good guide with practical examples that shows you the best practice is a must have, and this is exactly what this book will do.

With Magento 2 Development Cookbook, we will cover the most important topics that will help you become a good Magento 2 developer. We will start with the basics and we will end with the more advanced topics.

This book is divided into several recipes, which show you which steps to take to complete a specific action. In each recipe, we have a section that explains how everything works.

We will start this book with the creation of a good development environment. For a good development environment, we need the right tools. We will install Magento and we will discuss how we can migrate data from a Magento 1 to a Magento 2 shop. Next, we will see some functional stuff. You will learn how the catalog system works, which product types are available, and a lot more.

After this, you will learn how we can create a Magento theme to change the look and feel of the Magento shop. But the main focus of this book will be the development part. We will create a custom module that we will extend with a lot of common features that are used in Magento projects, such as extra controller pages, database integrations, custom shipping methods, and extra backend interfaces.

At the end of this book, we will see how we can improve the performance of a Magento shop. Finally, we will see some debugging techniques, such as Xdebug and creating unit tests using the Magento test framework.

What this book covers

Chapter 1, Upgrading from Magento 1, provides an introduction to how you can install and migrate the data from a Magento 1 to a Magento 2 shop. We will also prepare our development environment in this chapter.

Chapter 2, Working with Products, gives you a more functional information about the possibilities of displaying products in your Magento shop.

Chapter 3, Theming, explains how you can customize the look and feel of your webshop using a custom Magento theme.

Chapter 4, Creating a Module, describes how to create a basic Magento module; how to extend that module with custom configurations, such as a custom page, translations, and blocks; and how to change behavior of standard Magento classes.

Chapter 5, Databases and Modules, demonstrates how you can extend a Magento module with database interactions, such as install and upgrade scripts, a custom entity that represents a database table.

Chapter 6, Magento Backend, shows you how to integrate a Magento module with the backend, such as adding configuration pages, creating overview pages, and extending the admin menu.

Chapter 7, Event Handlers and Cronjobs, describes how the event-driven architecture is implemented in Magento and how to integrate this in your module. Later in this chapter, you will learn how to create cronjobs and how to test them.

Chapter 8, Creating a Shipping Module, shows you how to create a module with the configurations that are required for a new shipping method.

Chapter 9, Creating a Product Slider Widget, will cover how to create a module with a custom widget, how to build the backend interface, and how to provide a good UI in the frontend of that widget.

Chapter 10, Performance Optimization, describes how to benchmark a site to explore the limits and how to improve the performance using different techniques such as Redis and Memcached.

Chapter 11, Debugging and Unit Testing, shows you how to use the PHP debugger Xdebug and how we can create automated tests using the Magento 2 testing framework.

What you need for this book

  • Magento 2 source code

  • A virtual Linux server (Ubuntu 15.10 or higher)

  • On that virtual server, you need the following:

    • Apache 2.4

    • PHP 5.5 or higher

    • MySQL Server 5.6 or higher

    • SSH access

  • NetBeans IDE (or any other good PHP editor like PhpStorm)

  • A database client (such a phpMyAdmin)

  • A standard web browser

  • Xdebug

  • Git SCM

Who this book is for

This book is for web programmers who are familiar with PHP and want to start with Magento 2. This book is also for Magento 1 developers who want to know how everything works in Magento 2.

This book will start with the basics of Magento 2 development and will end with the more advanced topics. Even if you knowledge about Magento development, this book is a good reference if you want to more about a particular topic in Magento.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The widget.xml file is used to define widgets in the Magento installation."

A block of code is set as follows:

<?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 id="helloworld" frontName="helloworld">
            <module name="Packt_HelloWorld" />
        </route>
    </router>
</config>

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Clicking the Next button moves you to the next screen."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/1234OT_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.