The Best Way to Learn Magento 2

The very best way that I have found to figure out how to develop with Magento 2 is to write unit tests for a module. It not only requires you to figure out how to work with phpunit, but to also look at the existing codebase for examples of how the Magento 2 team works with the same objects and handles the same kinds of tasks. Once I wrote a full set of unit tests for my first Magento 2 module, I felt that I had a much better grasp of the workings of Magento 2 than I did before I started writing the unit tests.

When learning how to develop with Magento 1, it seemed that there weren’t that many publicly available resources for the experienced developer new to Magento development. In the end, I learned the most from going through Alan Storm’s (@alanstorm) excellent series on Magento 1.

However, when it comes to Magento 2, it definitely seems that there is an abundance of information available for how to do the extremely simple stuff, but not a lot available when it comes to some of the newer technologies that Magento 2 works with or some of the more obscure customizations that some stores require. Hearing that Magento 2’s architecture was completely different than what Magento 1 employed, and that the Mage object, that had been the core of everything you do as a Magento 1 developer, was gone, a good source for re-training seemed important for a team of Magento 1 developers. With the newness of Magento 2, the first training material I checked out was Magento’s own training videos. While they explained a lot of the dependency injection newness and reading of the very slides that were visible in the video portion, the most memorable part of the training was listening to the instructor repeat multiple file paths that were not reproduced directly in the video, and seemed to appear only in the accompanying notes.

Having a slight grasp of the high-level changes in Magento 2, it was time to find a resource that went a bit more in-depth with some real-world examples of customizations that you might make on your own Magento 2 store. That brought me back to Alan Storm’s Magento 2 series, but I still didn’t have a thorough understanding of how the intricacies of the PHP framework worked. While there was some familiarity with the system, it was not perfect, but it was time to start development with Magento 2.

Working on the first real module in Magento 2, based upon the Magento 2 Sample Module was slow and required lots of research to try to figure out how to load data and parse it, and all the other things that had become so natural with Magento 1. Once I finally got it working the way I wanted it to, I started writing unit tests to make sure that others working on the same code in the future would have some idea as to whether the changes they were making made things better or worse. At this point, it became evident that you have to know quite a bit about how all the factory objects work, and what they return when you call $this->collectionFactory->create(); so that you can not only create mock objects for the factory, but also the objects that are created by the factory. The best way that I found to figure out what these objects were and what to mock was to look at other tests that shipped with Magento 2 and see how they handled the exact same objects. When I started working on the next module after finishing the unit tests for the first one, the time to complete development was greatly reduced, with much less need to look outside the existing Magento 2 codebase for examples of how to accomplish tasks.

After this experience, you can be sure that I will make sure to write as many unit tests as possible, as they have already saved me from shipping some obscure bugs in my code that I would not have found until much further down the line.

Related Posts

May 2, 2014
2 minutes

Magento Version 2, is it just Microsoft Windows Longhorn AKA Vista?

Magento version 2 was first introduced in 2010. It is now almost halfway through 2014, and the public has not seen any alpha or beta release of Magento version 2 as of yet. The new version of Magento promised to replace PrototypeJS and Scriptaculus with jQuery as well as reorganize the database schema to remove the slow EAV tables and migrate to a bit of a flatter table structure. However, it seems that the latest updates on the direction for Magento 2 show that the database schema will not be changed much after all.

Mar 12, 2015
3 minutes

The Number 1 Cause of the Not Invented Here Syndrome

One of the quickest ways to get a new internal tool bootstrapped is to utilize an existing design, making slight adjustments to ensure the design matches the requirements of the current project. Instead of using another internal tool as the basis for the new design, I used a design that was purchased specifically for this project.

This particular design was unique in that there were multiple working examples using AJAX, pure HTML, and AngularJS. While it was nice having supposed working examples, when you start to look at the readme file for how to get this functionality working on your own hosting setup, thats when the niceties disappear. Specifically when lookng at the readme file for AngularJS, it effectively says: “Because this is a well-known JavaScript framework, we are not including any documentation for how it works or how to get started with our design”. Granted, the inner workings of AngularJS need not be covered in the readme, but a simple walkthrough of what to expect this design to do would make things much more user/developer friendly.

Apr 17, 2014
2 minutes

MySQL Deadlocks with Magento

One of the things that Magento, and specifically the Zend Framework provide developers is the ability to not have to think about database details as it should just handle all that for you. When it becomes obvious that there is a problem somehow with the production database getting some sort of SQL errors, its time for the developers to start caring about the implementation and architecture details of the database.