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.

comments powered by Disqus

Related Posts

Magento 2.1.3 Upgrade Static Files Not Loading

Magento just released an update to the latest version of their ecommerce platform to up the version from 2.1.2 to 2.1.3. There are a few differences between the versions, and one of those differences relates to the handling of the static files and what method is used to bust the cache of browsers to ensure users get the latest code whenever changes are deployed. Unfortunately, this upgrade by default breaks sites that aren’t aware of the changes needed to make this work properly.

Read More

Avoid 'Persistent storage maximum size reached' in Firefox

One of the nice tools out there for tracking down issues that your website’s visitors are having is TrackJS. We started noticing the other day that we were getting overwhelmed by errors with the text Persistent storage maximum size reached for our Magento site. When we looked further into the issue, it quickly became obvious that all of the errors originated from a single user that was running Firefox. It quickly became obvious that there was a single user that had exhausted their localStorage resources on their browser, but why was it only one user?

Read More

Orphaned Attribute Data in Magento

Its always entertaining to look at the source of an application that originates from outside your organization. It frequently highlights ways of using technology I was not familiar with beforehand, and sometimes leaves me shaking my head in disgust. I initially started looking at a relatively new third-party module thinking that I would find some sort of major bug that was causing the issues the site was experiencing, but was surprised to find that was not the case.

Read More