Magento 1 and Magento 2: Shared Code for Extensions

I am currently porting our IntegerNet_Solr extension to Magento 2. This extension integrates Solr as a product search in your Magento frontend, providing an extensive autosuggest function and fuzzy search results, which are a lot faster and better than Magento’s standard product search. It’s a complex module, tightly coupled with the Magento core: like indexer, search, layered navigation or category view. So the first step was to reduce this coupling and make most of the code independent of Magento. My goal is to reuse it in the Magento 2 module and have as little Magento specific code as possible.

I already worked with this framework independent (aka framework agnostic) approach before, and presented it at Meet Magento DE 2015 (see presentation slides – German) in the context of unit testing. Implementing business logic independent of the framework enables Test Driven Development and clean, performant unit tests.

This article series introduces useful design patterns for decoupled Magento extensions, which are divided in two parts: the Magento module and a framework independent library, that is reusable for Magento 1 and Magento 2.

It will not cover the refactoring process, that’s a different topic and I am going to talk about it at Developers Paradise 2016 in Croatia. Stay tuned!

All Parts:

Start reading

Glossary (or: “What?”)

In case I lost you with the technical terms, find some definitions below:

Coupling: A term to describe interdependency between software components. Accordingly, decoupling describes the act of making components independent from each other.

A term to describe interdependency between software components. Accordingly, describes the act of making components independent from each other. Framework independent code: In our case, the framework is Magento, and all code that is not directly using features of Magento (does not make any calls to Magento classes), is framework independent.

In our case, the framework is Magento, and all code that is not directly using features of Magento (does not make any calls to Magento classes), is framework independent. Business logic: Simply stated, the code that constitutes features (business needs), isolated from technical details like database operations and the user interface.

Simply stated, the code that constitutes features (business needs), isolated from technical details like database operations and the user interface. Module and Library: When I am talking about modules, I refer to the Magento module, which is the part of the extension in /app that interacts with Magento, whereas the library is the independent component which will be used by the module and lives in /lib or /vendor .

and When I am talking about modules, I refer to the Magento module, which is the part of the extension in that interacts with Magento, whereas the library is the independent component which will be used by the module and lives in or . Design Patterns: Solutions for recurring problems in software development. Most importantly, patterns define a common language between developers.

Solutions for recurring problems in software development. Most importantly, patterns define a common language between developers. Refactoring: Rewriting code to improve code quality characteristics (like maintainability and extensibility) without changing its behavior.

Start reading