Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Magento 2 Development Quick Start Guide
Magento 2 Development Quick Start Guide

Magento 2 Development Quick Start Guide: Build better stores by extending Magento

eBook
€8.99 €17.99
Paperback
€21.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Magento 2 Development Quick Start Guide

Working with Entities

Every Magento module hosts its models within the Models directory. Some of these models are persistable, while others are non-persistable. A great deal of custom, third-party, and core Magento modules persist data to the database. Data persistence is one of the key functionalities that platforms like Magento need to deal with. Terminology-wise, Magento uses terms such as model, resource model, and collection for a group of three classes that deal with data persistence, that is, create, read, update, and delete (CRUD) operations.

To better understand the overall mechanism of entities, we are going to take a closer look at the following:

  • 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...

Technical requirements

Understanding types of models

There are two types of persistence models in Magento: simple and Entityattributevalue (EAV). The term entity is tossed around interchangeably between the two types of models. We can think of an entity as any persistable model.

The Subscriber entity of the Magento_Newsletter module is an example of a simple model. We can see that it's comprised of the following:

  • A model of type Magento\Newsletter\Model\Subscriber extends Magento\Framework\Model\AbstractModel
  • A resource model of type Magento\Newsletter\Model\ResourceModel\Subscriber extends Magento\Framework\Model\ResourceModel\Db\AbstractDb
  • A collection of type Magento\Newsletter\Model\ResourceModel\Subscriber\Collection extends Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection

The Customer entity of the Magento_Customer module is an example of an EAV model...

Working with setup scripts

Every time a module is installed via a php bin/magento module:enable command, Magento shows the following message: To make sure that the enabled modules are properly registered, run 'setup:upgrade'. The php bin/magento setup:upgrade command upgrades the Magento application, database data, and schema. Once triggered, the upgrade command instantiates Magento\Setup\Model\Installer, which then goes through a series of methods. Its getSchemaDataHandler method reveals the types of available setup scripts:

  • InstallSchema.php
  • UpgradeSchema.php
  • Recurring.php
  • InstallData.php
  • UpgradeData.php
  • RecurringData.php

These scripts live under the <VendorName>/<ModuleName>/Setup directory.

Once successfully finished, the setup:upgrade command makes a new entry, or updates an existing one, in the setup_module table. There, we can see the schema_version...

Extending entities

We extend entities by adding additional attributes to them. Referring back to the magical getter and setter methods mentioned in the context of Magento\Framework\DataObject, the logical thinking might be: what's the big deal; can't we just add new database columns via UpgradeSchema and use magical getter and setter methods to go around it? The answer is both yes and no, but mainly leaning toward no – we will soon learn why.

To better explain this, let's take a look at Magento\Sales\Model\Order, the entity model. This model implements the Magento\Sales\Api\Data\OrderInterface interface, which further extends Magento\Framework\Api\ExtensibleDataInterface. Here, we can see a constant defining a key for the extension attributes object. This is somewhat of a starting point for extending entities. Suffice to say, there is an extra abstraction...

Summary

Throughout this chapter, we learned how to differentiate the three types of Magento models: non-persistable, persistable simple, and persistable EAV. The inners of EAV models are left out of scope due to their inherently complex nature. We then took a look through six different setup scripts. These give us a great deal of flexibility over schema and data management. Combined with extension attributes, we get a powerful mechanism for extending built-in entities. Though somewhat tedious, the extension attributes mechanism use of interfaces ensures that integrators can extend this built-in functionality with complex data types.

Moving forward, we are going to take a look at the powerful web API that's implemented in Magento.

Left arrow icon Right arrow icon

Key benefits

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

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.

Who is this book for?

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

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

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 21, 2018
Length: 218 pages
Edition : 1st
Language : English
ISBN-13 : 9781789345469
Vendor :
Magento
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Sep 21, 2018
Length: 218 pages
Edition : 1st
Language : English
ISBN-13 : 9781789345469
Vendor :
Magento
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 88.97
Magento 2 Theme Design
€29.99
Magento 2 Beginners Guide
€36.99
Magento 2 Development Quick Start Guide
€21.99
Total 88.97 Stars icon
Banner background image

Table of Contents

10 Chapters
Understanding the Magento Architecture Chevron down icon Chevron up icon
Working with Entities Chevron down icon Chevron up icon
Understanding Web APIs Chevron down icon Chevron up icon
Building and Distributing Extensions Chevron down icon Chevron up icon
Developing for Admin Chevron down icon Chevron up icon
Developing for Storefront Chevron down icon Chevron up icon
Customizing Catalog Behavior Chevron down icon Chevron up icon
Customizing Checkout Experiences Chevron down icon Chevron up icon
Customizing Customer Interactions Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(2 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
cru Dec 27, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
da leggere con attenzione
Amazon Verified review Amazon
Danny Z Jan 26, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good stuff, relevant even until this year (2021 as of this writing) I like the layout of the chapters and progression as you read the book front-to-back. Picked up the other author's book on Magento 2 since I enjoyed this one so much.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.