Magento events and observers are a good old way of extending Magento. They came from Magento 1, but an approach is well-known beyond the Magento community and platform. It follows an observer design pattern and has different implementation and variations in different frameworks. This article covers how Event Framework was implemented in Magento and how it’s suggested to be using by Magento Development Team.
Starting from Magento 2.3 the Registry class that is (or was) used by a lot of developers and extension vendors is declared to be deprecated. In class comments it’s told to use service classes or data providers, but no examples provided. This article aims to show how you can get needed data using best practices and service classes.
You already know how to create a simple CLI script. The CLI scripts are initialized with a different area – basically, with a separate CLI area\aplication, which lacks the standard frontend\admin localizations functionality. We faced that when developing a script for sending order emails via CLI – the emails were missing translations of the origin of the order. Let’s try to figure out “why?” and “how to fix?”.
It is always good when you can test your features fast. But sometimes it’s literally hard and takes a lot of time to test something in Magento. When you make one little change in code and want to test it, it can take much more time to test it rather than make the change itself. Nevertheless it’s a common situation taking into account the complexity of Magento.
Every unit test ninja faces troubles whenever he wants to test some real class functionality. Have you ever invoked toHtml() method of some block or beforeLoad() method of any collection? If you want to do it, you will need to mock a lot of classes that depend on other classes and so on. You would need to mock all of them, which would take a lot of time and effort. In a long run, you may blow up deadlines and it would really suck. Yes, you can try to change your testing strategy to avoid invoking such methods. But what if you still need to test them? I’m going to show you how I handled this problem.
Before running your store in production mode it’s very important to check as many performance aspects as possible, since even a minor performance issue might cost time and money in the future. Formally, a web application’s performance can be classified using two parts: frontend performance and backend performance.
During our work with Rich Snippets extension we’ve noticed that the product list page has numerous errors if switched to the list mode. The errors were generated by the standard Magento 2 Luma theme, when attempting to aggregate rating markup rendering for each product in the product list. This blog post describes a configurable fix for the issue. We will have an opportunity to disable this fix for any custom theme which doesn’t have this error or in case the next Magento 2 version has a fix for this included.
When we talk about checking bottlenecks in Magento backend implementations we often mention the built in profiler that allows to see loading time of particular backend functional elements. There are two general factors of such bottlenecks: heavy (or repetitive) database calls or slow PHP operations such as loops and similar cases.
Scheduled background processes are important in any large system. Clean ups and keeping cache and indexes up to date allow to keep your system healthy, while some processes are simply need to be stretched in time in order to avoid high system load, memory leaks or certain services overload (massive emails sending). Setting up a cron job for such processes and for the processes that should be repeated from time to time is always a good idea. In this blog post we will describe how to set a certain part of code as a cron job in Magento 2.
One of Magento 2 goals is to enable performance for all and scalability for Enterprise customers. Page Cache plays an important role in Magento 2. Starting from Magento 2.0.0 release Page Cache functionality (it is also known as Magento Full Page Cache) is available for Magento 2 Community Edition.