Feb 18

How Magento Won Over My Heart: A Developer's Tale

I've been working on Expression Engine for about a year now and I have been trying to get into the realm of e-Commerce with the highly flexible web application Magento. Coming from a Zend Developers background, and seeing that Magento is built on top of Zend, I came into the world of Magento with a bunch of preconceived notions about how good Zend Applications should look and act. All of which were smashed on my first day of looking through the example Magento Stores.
Here are some of the things I learned:

1. Tightly coupled framework

One big downside to Magento is the lack of leeway for creativity here. The sprawling ad-hoc implementations of the past be damned! There is only one way to do everything here. Let's say I want to create a frontend component using html. In the web developers world, there are many, many ways to achieve the exact same functionality. In the Magento world, the organization of template-layout-theme paradigm is so tightly wound making solutions independent of this framework is a challenge, if not an impossibility. This is a good thing though, Magento has an incredibly powerful an extensible framework capable of tackling any problem you throw at it, with only a  little practice getting used to the organizational structure. This pattern is possible and works great because of the very flexible Zend dispatch process with multiple layers of pre and post-processing.
Also, what I thought was a clever use of Zend's routing functionality to parse XML instead of Web Pages, almost like a compiler.

2. Robust "web hook" style set of observers

This system is already in place. Cut and paste. You don't need to worry about anything because it works and does its job. That is, except when you need the system to do something it wasn't necessarily designed for.
Never fear! The guts of this system are available for all of your programming prerogatives! Web hooks to the rescue. Need some custom functionality to occur every time a particular class of orders is executed? All you need to do is create an observer class and hook it to the correct web hook with a few lines of config code. Unlike other CMS systems that require a whole slew of seemingly unnecessary setup to get your code into the system. All you need to do is inherit one of the base observer classes and presto. The list of observable actions is pretty exhaustive too. Rock and roll.

3. Configuration vs. Convention

There are two ways to make things happen in Magento. Convention and Configuration. They work hand in hand. I tend to believe most software engineers try to make each piece of code they work on a meaningful unit with self contained functionality. This is obviously a dangerous way of thinking about systems. Self contained functionality leads to anti-patterns, god classes and other horrible habits. Magento has a good way of making everything you write completely useless, unless it is supported by either configuration, or convention, or both. Want to create a module at: http://test.com/site/dynamic_content ?  In no particular order you need to :

a) Build the template (convention).

b) Then build a layout to fit that module into the site (configuration).
Without a layout your template is useless and vice versa. This separation requires a special kind of attention to detail that at first I found cumbersome, but as I got used to it, I felt like I was a one-man agile team. Awesome.

4.  But all that complexity is a tad... esoteric.

While having a robust and generalized method of implementing the templating system. The trade off is that Magento is endlessly complex on how the actual data (product) is represented. If you are a small business with a limited technical knowledge you probably don't care about creating complicated multi-tiered group products configurable to your desired attribute specification. If you want to pour over the minutiae of VAT tables and crazy shipping schemes, Magento has your back. Some might say this is needlessly complex and any complexity that codified isn't flexible enough for the real world. The jury is still out for me and I'll let the reader decide for themselves.

5.  Build on and integrate

This is purely a criticism of other e-Commerce platforms. Out of all the "carts" I've come across on the web, I consistently find one significant short fall. Extensibility. The proliferation of "1-click setup" stores leaves a big hole in the department of customization. Most are built to be self contained or integrate into third-party CMS systems. Magento doesn't have this problem. With its own set of CMS tools, Magento provides the back-end bona-fides to build an enterprise class community right in house.

Happy Hunting!
Alec is a Senior Web Developer at DO. He once took a flying leap over the handlebars of an Sbyke.