39,59 €
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.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 290
Veröffentlichungsjahr: 2015
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: December 2015
Production reference: 1171215
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-219-7
www.packtpub.com
Authors
Bart Delvaux
Reviewers
Karen Kilroy
Pankaj Pareek
David Parloir
Marius Strajeru
Commissioning Editor
Veena Pagare
Acquisition Editor
Prachi Bisht
Content Development Editor
Aparna Mitra
Technical Editor
Abhishek R. Kotian
Copy Editor
Pranjali Chury
Project Coordinator
Izzat Contractor
Proofreader
Safis Editing
Indexer
Mariammal Chettiyar
Graphics
Disha Haria
Production Coordinator
Conidon Miranda
Cover Work
Conidon Miranda
Bart Delvaux is an experienced web developer with several years of experience in the PHP world. He has worked with the most important frameworks in PHP, such as Drupal and Zend Framework, but Magento is his specialization.
Bart has obtained all the Magento developer certifications: Front End Developer, Developer, as well as Developer Plus. He currently works for ISAAC Software Solutions, a company that specializes in software solutions such as web shops, apps, system integrations, and more.
Bart finished a large variety of Magento projects in his Magento career that started in 2010 with the principle "quality above quantity". Having gone from handling a basic shop to shipping modules and large, complex Magento stores, Magento holds no secrets from him.
Bart has also worked on Magento 1.8 Development Cookbook, Packt Publishing. Now that Magento 2 is out, it is time for the next one!
I want to thank everyone who made it possible for me to complete this book. I would like to extend thanks to the people at Packt Publishing for the support and to my colleagues for their vision and support.
Lastly, I want to thank the people who contributed to Magento 2. They did a good job creating a new version of the popular Magento system, which is future-proof!
Karen Kilroy is a highly experienced developer, administrator, and instructor. She is a Magento-certified Front End Developer. As a hands-on developer and systems administrator with more than 25 years of experience in IT, which includes 20 years in web development, Karen has focused primarily on Magento for the past 7 years. Currently, she is employed at Amplifi as a Magento technical lead and works on several well-known commerce sites.
Karen got her start in Magento at a direct marketing company selling EdenPURE Heaters (edenpure.com), a site that generates millions of dollars in sales. Additionally, she was a courseware author and instructor for Magento's official training arm, Magento U, between 2010 and 2014. Karen is also a reviewer of Mastering Magento, 2nd Edition, Packt Publishing.
Prior to becoming involved with Magento, she customized LAMP content management systems, such as Joomla, Drupal, and WordPress. In the early days of web development, Karen led her own company, where she employed 20 developers doing Java and Lotus Notes/Domino work for large clients.
In her spare time, she is also a professional dragon boat coach and steersperson.
Pankaj Pareek is a certified software professional who has expertise in Magento, PHP, and other frameworks. He has provided his professional services in this field for more than 7 years.
A true professional, Pankaj works with the motto that knowledge increases when you share it with others. He is a person who has explored different aspects of the software field suo moto. Pankaj is a quick, curious learner who received various recognized certifications in the IT field in a very short span of time, namely Magento Developer (2013), Magento Solution Specialist (2015), and Zend Certified Engineer (2014).
I would like to express my gratitude toward my loving grandmother, family, colleagues, and the almighty god.
David Parloir has been a freelance Magento developer since the first version was released in 2008, and through this, he has also been the lead developer for several large global projects. Prior to this, David worked for several companies that focused on the development of e-commerce websites and even worked as a teacher of Magento for a short period. He is a self-taught developer who sees web development as more than a job—he sees it as a passion. David considers himself a craftsman, keeping up to date with the latest trends in this area while balancing the new skills he develops, with a desire for his code to be efficient, simple, and elegant.
Marius Strajeru is 32 years old and finished as a faculty of computer science in Iasi, Romania, in 2006. Since then, he has worked as a PHP developer for various software companies.
Marius' area of expertise is Magento; he has been working with Magento since version 1.0 came out in 2008. He started looking at Magento 2 as soon as he heard that the source code is available in a dev version.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
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.
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.
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.
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:
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.
This section contains the steps required to follow the recipe.
This section usually consists of a detailed explanation of what happened in the previous section.
This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.
This section provides helpful links to other useful information for the recipe.
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:
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."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
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 <[email protected]>, 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.
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.
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.
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.
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 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 <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
In this chapter, we will cover:
Magento is one of the most complete e-commerce platforms on the open source market. With a default Magento installation, all the common e-commerce features, such as catalog navigation, promotion rules, tax settings, online payments, and so on are available.
The first version of Magento was released in 2008 after one year of development. Magento was initially designed as an e-commerce system that could be used for a wide range of uses. In later years, Magento became very popular as an out-of-the-box e-commerce system and a lot of minor versions of the 1.x series have been released in the last few years.
To be future proof, Magento started the development of a major upgrade of the system, also known as Magento 2. Magento 2 is a big improvement on every part of Magento. Every aspect is analyzed and rewritten with up-to-date technologies to be ready for the future. Everything, including the developer experience, maintainability, performance, and technologies will be improved.
In this chapter, we will upgrade the data of a Magento 1 installation to a Magento 2 installation. We will also prepare some tools that we can use in the following chapters of this book.
To start a Magento 2 upgrade, we need a Magento 1 webshop with some data. In this recipe, we will install the latest Magento version, 1.9, with the sample data for the new responsive theme.
To install a Magento 1 website, we need the following stuff:
The Magento 1.9 codebase and sample data can be downloaded from the Magento site at http://www.magentocommerce.com/download.
The following stuff is recommended for the installation:
We recommend that you use a test server that is on your development machine. If you use a Linux or a Mac operating system, you can install the webserver on your local machine. If you have a Windows machine, you can use a virtual Linux server for your development.
To avoid permission problems, ensure that all files and folders have the right permissions. For security reasons, it is recommended that all files have just enough permissions so that only the right users can access the right files. When you give all the rights (777), you don't have permission problems because each user can read, write and, execute each file of your application. More information about file permissions can be found at http://devdocs.magento.com/guides/m1x/install/installer-privileges_after.html.
We have just created a fully functional Magento 1 store. The webshop is fully configured and filled with data about products, customers, and orders, just the data we need to migrate to Magento 2 (in the upcoming recipes).
When installing a new shop, you have to follow the installer. This interface creates a configuration file app/etc/local.xml. If the file doesn't exist, Magento will launch the installer wizard. If the file is there, Magento will run the shop.
With a valid local.xml file, it is technically possible to install a new Magento shop, but this is not recommended because some settings such as a backend user, time zone, and currency are not set. These are actions that you have to do manually when choosing for this method.
In the previous recipe, we created a Magento 1 website with sample data that we will use for an upgrade. In this recipe, we will do the same, but we will create a Magento 2 website with the sample data for Magento 2.
To install Magento 2, we need the newest tools to run that application. Make sure your webserver has the following stuff installed:
We can install Magento 2 in different ways. In this recipe, we will install Magento 2 using Composer. The advantage of this is that we can use GIT to add version control to our custom development.
Check that the user and group of these files are the same as your Apache user. One recommendation is to execute all the commands as your apache user.
Make sure that the mod_rewrite option is enabled for the apache server. When not enabled, the URL rewrites will not work correctly.
We have now installed a Magento 2 website. Like we did in the previous recipe for Magento 1.9, we downloaded the codebase (using composer), created a database, and installed Magento.
For Magento 2, we used composer to download the codebase. Composer is a PHP dependency manager. All the dependencies are set in the composer.json file. For this recipe, there are the Magento and the magento-sample-data dependencies in the composer.json file. There is also a composer.lock file generated. In that file, the versions of the installed dependencies are stored.
