Magento 2 Development Quick Start Guide - Branko Ajzele - E-Book

Magento 2 Development Quick Start Guide E-Book

Branko Ajzele

0,0
25,33 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Create an interactive online store and customize it further using Magento

Key Features



  • A straightforward guide to developing with Magento
  • Examples of different types of extension
  • Customize the Magento storefront and admin areas

Book Description



Magento is an open-source, enterprise-level e-commerce platform with unlimited scope for customization. This makes it a great choice not only for vendors but for developers as well.

This book guides you through Magento development, teaching you how to develop modules that extend or change its functionality, leading to more ?exible and profitable Magento stores. You start with a structural overview of the key Magento development components.

You will learn where things such as plugins, events, models, controllers, layouts, and UI components ft into the development landscape. You will go through examples of using these components to extend Magento. As you progress, you will be building a diverse series of small but practical Magento modules.

By the end of this book, you will not only have a solid foundation in the Magento development architecture; but you will also have practical experience in developing modules to customize and extend Magento stores.

What you will learn



  • Develop a simple shipping module
  • Build admin interfaces with the built-in form and listing UI components
  • Implement JavaScript components for improved customer experience
  • Accommodate vendor needs by adding new catalog-related features
  • Develop your way to a better checkout
  • Improve customer interaction with new customer-related extensions
  • Create new web APIs to make your modules more extensible

Who this book is for



This book is for competent PHP developers, with only basic knowledge of the Magento platform required.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 174

Veröffentlichungsjahr: 2018

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Magento 2 Development Quick Start Guide

 

 

 

 

 

Build better stores by extending Magento

 

 

 

 

 

 

 

 

 

 

 

Branko Ajzele

 

 

 

 

 

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

Magento 2 Development Quick Start Guide

Copyright © 2018 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 or its dealers and distributors, will be held liable for any damages caused or alleged to have been 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.

Commissioning Editor: Amarabha BanerjeeAcquisition Editor: Reshma RamanContent Development Editor: Kirk DsouzaTechnical Editor: Vaibhav DwivediCopy Editor: Safis EditingProject Coordinator: Hardik BhindeProofreader: Safis EditingIndexer: Aishwarya GangawaneGraphics: Alishon MendonsaProduction Coordinator: Deepika Naik

First published: September 2018

Production reference: 1180918

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-78934-344-1

www.packtpub.com

 
mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Mapt is fully searchable

Copy and paste, print, and bookmark content

Packt.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.packt.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.packt.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. 

Contributors

About the author

Branko Ajzele is a respected and highly accomplished software developer, book author, solution specialist, consultant, and team leader. He currently works for Interactive Web Solutions Ltd (iWeb), where he holds the role of senior developer and is the director of iWeb's Croatia office.

Branko holds several respected IT certifications, including Zend Certified PHP Engineer, Magento Certified Developer, Magento Certified Developer Plus, Magento Certified Solution Specialist, Magento 2 Certified Solution Specialist, Magento 2 Certified Professional Developer, to mention just a few.

He was crowned the e-commerce Developer of the Year by the Digital Entrepreneur Awards in October 2014 for his excellent knowledge and expertise in e-commerce development.

Special thanks to my supportive wife, Ivana, for her understanding when I took quite a bit of our family time for this endeavor.

 

About the reviewer

 

Andrew "Pembo" Pemberton is a Certified Magento Developer with over 20 years' experience building websites. He is based in Stoke-on-Trent, UK and started building websites from the young age of 13. He has a degree in computer science from Staffordshire University.

Andrew is now the development director at iWeb (based in Stafford, UK), which, for over 20 years, has created industry-leading websites and now specializes in large scale Magento solutions and PIM-based projects for a wide range of clients.

Outside of his digital life, Andrew enjoys spending time with his family of pets, traveling with his wife, and being an avid gamer.

 

 

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents

Title Page

Copyright and Credits

Magento 2 Development Quick Start Guide

Packt Upsell

Why subscribe?

Packt.com

Contributors

About the author

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Code in Action

Conventions used

Get in touch

Reviews

Understanding the Magento Architecture

Technical requirements

Installing Magento

Modes

Areas

Request flow processing

Modules

Creating the minimal module

Cache

Dependency injection

Argument injection

Virtual types

Proxies

Factories

Plugins

The before plugin

The around plugin

The after plugin

Events and observers

Console commands

Cron jobs

Summary

Working with Entities

Technical requirements

Understanding types of models

Creating a simple model

Methods worth memorizing

Working with setup scripts

The InstallSchema script

The UpgradeSchema script

The Recurring script

The InstallData script

The UpgradeData script

The RecurringData script

Extending entities

Creating extension attributes

Summary

Understanding Web APIs

Technical requirements

Types of users

Types of authentication

Types of APIs

Using existing web APIs

Creating custom web APIs

Understanding search criteria

Summary

Building and Distributing Extensions

Technical requirements

Building a shipping extension

Distributing via GitHub

Distributing via Packagist

Summary

Developing for Admin

Technical requirements

Using the listing component

Using the form component

Summary

Developing for Storefront

Technical requirements

Setting up the playground

Calling and initializing JS components

Meet RequireJS

Replacing jQuery widget components

Extending jQuery widget components

Creating jQuery widgets components

Creating UI/KnockoutJS components

Extending UI/KnockoutJS components

Summary

Customizing Catalog Behavior

Technical requirements

Creating the size guide

Creating the same day delivery

Flagging new products

Summary

Customizing Checkout Experiences

Technical requirements

Passing data to the checkout

Adding order notes to the checkout

Summary

Customizing Customer Interactions

Technical requirements

Understanding the section mechanism

Adding contact preferences to customer accounts

Adding contact preferences to the checkout

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

Magento is a popular open source e-commerce platform written in PHP. It is used primarily for building web shops, though it can easily be used for other types of websites as well. With the help of its powerful web API, we can build robust solutions that satisfy modern-day application requirements.

By the end of this book, the reader should be familiar with configuration files, models, collections, blocks, controllers, events, observers, plugins, UI components and other building elements of Magento.

Who this book is for

This book is intended for PHP developers getting started with Magento v2.x development. Though compact in terms of page numbers, the book covers a wide range of functionality, allowing the reader to master day-to-day Magento skills in a clear and concise way. No previous Magento knowledge is required.

What this book covers

Chapter 1, Understanding the Magento Architecture, takes a look at some of the key Magento components. We will go through plugins and event observers and learn how they provide a powerful way of extending Magento, either by changing the behavior of existing functions or by running some follow-up code in response to certain events.

Chapter 2, Working with Entities, demonstrates how to differentiate between the three types of Magento models: non-persistable, persistable simple, and persistable EAV. We will take a look at the six different setup scripts and how they allow us a great deal of flexibility for schema and data management.

Chapter 3, Understanding Web API, shows the reader how to differentiate between types of web API users, authentication, and methods it provides. We will also take a look at how easy it is to create our own APIs with just a few lines of XML. We will see how the route definition allows for easy binding between what arrives via HTTP requests and what is executed in code, respecting the access list permissions in the process.

Chapter 4, Building and Distributing Extensions, discusses how to create a simple shipping module. We shall take a look at how easy it is to add specific shipping calculations as part of offline shipping methods. We will then package this module and distribute it via Packagist. This makes it easy for the end consumer to use our module with just a few simple console commands.

Chapter 5, Developing for Admin, walks the reader through building two very different screens in the Magento admin area. One utilizes the listing component, whereas the other utilizes the form component.

Chapter 6, Developing for Storefront, covers the bits and pieces involved in storefront development, which JS components make the most challenging part of. We will understand how to write new components, as well as how to override or bypass existing ones – an essential skill for any Magento developer, be it backend or frontend.

Chapter 7, Customizing Catalog Behavior, demonstrates building three distinctive functionalities, all of which relate to the catalog part of Magento. They demonstrate how easily Magento can be extended with new features without really overriding any of the core files. Using plugins and JS components are just some of the approaches we might take.

Chapter 8, Customizing Checkout Experience, demonstrates writing a small but functional order notes module. This will allow us to familiarize ourselves with an important aspect of customizing the checkout experience, the gist of which lies in understanding the checkout_index_index layout handle, the JavaScript window.checkoutConfig object, and uiComponent.

Chapter 9, Customizing Customer Interactions, walks the reader through building a small module that allows us to get a greater insight into Magento's customer data and sections mechanism. We will learn how to manage and build a single component, which will get used both on the customer's My Account page, as well as at the checkout.

To get the most out of this book

To get the most out of the book, the reader is expected to have:

 

A degree of PHP

object

-

oriented programming

(

OOP

) knowledge

A basic understanding of JavaScript and XML

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

Log in or register at

www.packtpub.com

.

Select the

SUPPORT

tab.

Click on

Code Downloads & Errata

.

Enter the name of the book in the

Search

box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR/7-Zip for Windows

Zipeg/iZip/UnRarX for Mac

7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Magento-2-Quick-Start-Guide. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing. Check them out!

Code in Action

Visit the following link to check out videos of the code being run:

http://bit.ly/2D98D8q

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.

Understanding the Magento Architecture

Building web shops is a challenging and tedious job, and even more so if a platform you are working on is limited via features, extensibility, and the overall ecosystem it provides. Choosing the right platform can often make the difference between a project's success or failure. The abundance of available e-commerce software, from SaaS to self-hosted solutions, does not really make it an easy choice.

The Magento e-commerce platform has been around for over 10 years now. With its first stable release dating back to March 2008, it immediately caught the attention of developers as an extensible and feature-rich open source platform. Over time, Magento established itself as not just a stunning technical and feature-rich platform, but as a robust ecosystem as well. By allowing developers to validate their real-world skills through the Magento certification program, certain standards have been put into effect, making it easier for merchants to better recognize their solution partners. Training courses have been further provided for other roles in e-commerce business as well, such as merchants, marketers, system administrators, and business analysts.

In this chapter, we will take a look at some of the key must-knows about Magento:

Installing Magento

Modes

Areas

Request flow processing

Modules

Cache

Dependency injection

Plugins

Events and observers

Console commands

Cron jobs

To keep things compact as we move forward, let's assume the following throughout this book:

We are working on the

magelicious.loc

project

We are referring to our project root directory as

<PROJECT_DIR>

We are referring to the

<PROJECT_DIR>/app/code/Magelicious

directory as

<MAGELICIOUS_DIR>

We are referring to Magento's

vendor/magento

directory as

<MAGENTO_DIR>

We have a running LAMP/

MAMP/

WAMP stack (Apache, MySQL, PHP) that is compliant with Magento's requirements

We have a Composer package manager installed

We have access to crontab (Linux, MacOS) or Task Scheduler (Windows)

AMPPS is an easy to use, all in one LAMP/MAMP/WAMP software stack from Softaculous, which enables Apache, MySQL, and PHP. With AMPPS, you can even install Magento 2.x by the click of a button, which means it comes loaded with all the right PHP extensions. While it isn't suited for production purposes, it comes in handy for quickly kicking the development environment. See http://www.ampps.com/ for more information. Consult the devdocs (https://devdocs.magento.com) for Magento technology stack requirements.

Technical requirements

You will need to have basic knowledge of PHP, OOP, JavaScript, and XML. You will also need Apache, MySQL, and AMPPS installed on your system to execute the codes.

The code files of this chapter can be found on GitHub:https://github.com/PacktPublishing/Magento-2-Quick-Start-Guide.

Check out the following video to see the Code in Action:

http://bit.ly/2D8kOlF.

Installing Magento

The Magento platform comes in two flavors:

Magento

Open Source

: The free version, targeting small businesses

Magento

Commerce

: The commercial version, targeting small, medium, or enterprise businesses

The difference between the two comes mainly in the form of extra modules that were added to the Commerce version, whereas all the coding concepts and core features remain the same. It goes to say that any knowledge we obtain through following Magento Open Source examples is fully applicable to anyone working on Magento Commerce.

There are several ways that we can obtain source files for Magento Open Source:

Source file archive (

.zip

,

.tar.gz

,

.tar.bz2

), available at

https://magento.com

Git repository, available at

https://github.com/magento/magento2

Composer repository, available at

https://repo.magento.com

Obtaining source files via a CLI from the composer repository is our preferred method. Assuming we are within the empty <PROJECT_DIR> directory, we can kick off this process via the following command:

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition .

The dot (.) at the end of this command this tells the composer to pull the files into a current directory.

Once the Composer process is finished, we can start installing Magento. There are two ways we can install Magento:

Via the Web Setup Wizard

: The graphical, browser-based process

Via the

command line

: T

he command-line-based process

Knowing how to install Magento via the command line is an essential skill in day-to-day development, as the majority of development requires the developer to tackle various bin/magento commands—not to mention the command line approach is somewhat faster and easily scripted.

Let's install Magento with the built-in php bin/magento setup:install command and a few of the required installation options as follows:

php bin/magento setup:install \

--db-host="/Applications/MAMP/tmp/mysql/mysql.sock" \

--db-name=magelicious \

--db-user=root

--db-password=root \

--admin-firstname=John \

--admin-lastname=Doe \

[email protected] \

--admin-user=john \

--admin-password=jrdJ%0i9a69n

After the preceding command has been executed, we should begin to see console progress, starting with something like the following:

Starting Magento installation:

File permissions check...

[Progress: 1 / 513]

Required extensions check...

[Progress: 2 / 513]

Enabling Maintenance Mode...

[Progress: 3 / 513]

Installing deployment configuration...

[Progress: 4 / 513]

Installing database schema:

Schema creation/updates:

Module 'Magento_Store':

[Progress: 5 / 513]

While it might take up to a few minutes, a successful installation should end with a message that's similar to the following:

[Progress: 508 / 513]

Installing admin user...

[Progress: 509 / 513]

Caches clearing:

Cache cleared successfully

[Progress: 510 / 513]

Disabling Maintenance Mode:

[Progress: 511 / 513]

Post installation file permissions check...

For security, remove write permissions from these directories: '/Users/branko/Projects/magelicious/app/etc'

[Progress: 512 / 513]

Write installation date...

[Progress: 513 / 513]

[SUCCESS]: Magento installation complete.

[SUCCESS]: Magento Admin URI: /admin_mxq00c

Nothing to import.

Right after installation, our first step should be to set Magento to developer mode by using the following command:

php bin/magento deploy:mode:set developer

We will take a closer look at Magento modes soon; for now, this is to be taken as is.