All posts of ecommage

Working With Models in Magento 2

What Are Models? Models are a flexible, highly abstract class that represents business logic in your application.  Models in Magento 2 can be anything that is packaged up and labeled.  For instance, database tables are representative of models. Magento’s ORM demands that only models can work with data in the application.  Models in the scope of ORM […]

Magento 2: ORM

Magento 2 works in many ways to the Magento 1 ORM structure.  They still have models, resource models, and collections.  There are a few small differences, but the overall structure remains unchanged. Create a Module Create the following folders: app/code/Ecommage/OrmExample/etc/ app/code/Ecommage/OrmExample/Model/ Let’s register our module. In app/code/Ecommage/OrmExample/etc/module.xml, enter the following: <?xml version="1.0"?> <config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module […]

Magento 2 Object Manager: Plugin System

We’re finally here. After our long path through the object manager, automatic constructor dependency injection, class preferences, argument replacement, virtual types, proxy objects and code generation, we’re finally familiar enough with the object system to discuss the true replacement for Magento 1’s class rewrites — the plugin system. No lollygagging about, let’s get to it. […]

Magento 2 Object Manager: Instance Objects

It’s been a long and winding road, but the end is in sight! In this, the penultimate article in our object manager tutorial, we’re going to discuss working with instance and non-injectable objects in Magento 2. This article assumes a basic familiarity with Magento 2 concepts, and may brush past something complicated. If you’re confused […]

Magento 2 Object Manager: Proxy Objects

With their take on an object manager/container and dependency injection, Magento have created a new way for PHP programmers to work. With that new way of working comes a new set of unanticipated challenges. Put another way, new patterns create new problems. Fortunately, Magento 2’s extended development cycle has given the core team time to […]

Magento 2 Object Manager: Virtual Types

Last time we discussed the argument replacement feature of Magento 2’s object manager, and introduced the <type/> tag in di.xml. This week we’re going to talk about another feature related to argument replacement — Virtual Types. Virtual types allow a module developer (you!) to create “configuration only classes” for the object manager’s argument replacement feature. If that didn’t make sense, […]

Magento 2 Object Manager: Argument Replacement

In the last article of our series, we covered the “class preference” feature of Magento’s object manager. This week we’ll cover a similar, but more selective, class replacement system built into Magento 2. While this article should be accesible as a stand-alone tutorial for programmers familiar with modern object oriented concepts, if you’re having trouble try starting at the […]

Magento 2 Object Manager: Preferences

Today we’re going to explore the “class preference” feature of Magento 2’s object-manager/dependency-injection system. While this feature is a direct descendant of Magento 1’s class rewrite system, it ends up playing a different role in Magento 2. Where Magento 1’s class rewrites were aimed at allowing third party developers to customize system behavior, the class […]

Magento 2’s Automatic Dependency Injection

This week’s article is the second in a series discussing Magento 2’s object system. Last time we covered the basics of Magento’s object manager. This week we’re going explain why you’ll rarely use Magento’s object manager, as well as Magento’s implementation of the popular “dependency injection” pattern. (hint — they’re related) Many popular PHP frameworks implement a dependency […]

Magento 2 Object Manager

Magento 2 brings a slew of changes to the table for an experienced Magento 1 programmer. While you can still see bits and pieces of Magento 1 (EAV, areas, blocks, etc.), the new Magento 2 core team has spent the last few years swapping out the startup fueled internals of Magento 1 with a more mature, […]