Beginning Magento

02 Dec 2012
Posted by jcfiala

A month and a half ago I switched to a new job at SpireMedia as the 'Director of PHP Development', which so far has largely meant 'Drupal Guru', a position that I'm quite enjoying.

However, an interesting addition to Drupal is that we're starting up on Magento projects, starting with a website for a company that sells items with legal restrictions on how items are sold and shipped, and which already has a computer system for fulfillment of orders. This means that we need to not only set up a Magento site, but we need to add new rules for these legal restrictions and we're going to need to be able to talk to the existing system to pass data back and forth.

Magento development is interesting. The system is built on the Zend framework, a collection of classes and the like for PHP development which I'd played with a little before via the ubiquitous blog tutorial, but which I'd never gotten too deep into. Along with that it's MVC based, with a lot of XML for configuration. In addition to the normal models, they also have 'Entity Attribute Value' models, which are CCK-like agglomerations of fields - called attributes - on entities like customers, products, and the like. This allows for adding new attributes on products - like sizes for tshirts - without having to modify the existing tables.

Happily, there's a very good Magento tutorial out there which takes you through and introduces you to a bunch of the basic concepts. It's written by Alan Storm, who is one of those bloggers who you should pay attention to when his articles come up in searches for Magento, because he knows what he's talking about and will probably describe things better for you. If you want to learn Magento, this is where you want to start.

Another useful link that I've already used once is a Magento Module Creator - just plug in what you want your module to do, name things, and hit 'go', and it generates the basic code and xml for you. This can be really helpful, especially for your first or second real module, and it's probably helpful just to try to create stuff for practice. For instance, my first module involved a config screen on the admin back end, and this tool generated the correct config xml so that the new menu and menu items appeared for me.

Beyond that, it's generally up to you to pick and choose your way across the minefield of Magento documentation. Due to the way that the project has changed over the versions, there's a real sort of drift in how things work between earlier versions (Pre 1.4), more current versions (around 1.6) and the latest, 1.7. Documentation or code for earlier versions can seriously hose your site if you're not careful about backing up your database. The documentation links on the front page of the wiki don't even go to real pages anymore, and when you're talking with someone in a forum or the irc channel (#magento on freenode, if you hadn't guessed), the usual answer is "The code is the documentation". Which is a shame, because the code is rarely documented well, and due to the class-oriented nature you can find yourself searching back through previous ancestors of a class to get to where something actually happens. It's very frustrating.

Also frustrating is how little example code there is. Most of the existing modules for Magento are for-pay, and even the ones that aren't for-pay have to be automatically downloaded and turned on by magento before you can look at the code, and if there's a mismatch in code between the extension's version and the version of Magento you're running, it can brick your site. And if you decide to plunk down the money for an extension, it's very hard to tell what exactly the extension does before you buy it, so if you get a shipping module because you want to extend the shipping charges, you may find you have something that's more about shipping out completed orders instead.

However, on the up side it is a very powerful eCommerce framework, and I can see that once I do have my feet under me and am able to write extensions and use the software better, it's going to allow me to make pretty good money on this in the future. I just find myself spoiled about how unlike an open source project it feels, and how much it makes me miss Drupal.

Tags: