If you are a newcomer to Magento platform, it’s almost sure that you’re highly confused with it! I know it seems so slow and complicated, starting right at the install. I have tried installing it several times and got bunch of error messages. After 6 or more tries, I finally got it installed and, of course, I was thinking to add some kind of information on the front page, such as a list of categories and static page links to main navigation, featured products with their prices somehow highlighted, and… man oh man! It wasn’t simple or intuitive at all. Actually, I didn’t know where to start, where to code, Magento’s file structure was so terrible to me. Serbia Magento community is not very large, but it’s growing daily.
I am quite good at developing sites, even online stores with good ol’ WordPress and Woo Commerce and I really love it because of its simplicity to use. To my regret, I needed to forget it and get used to Magento because Implementek’s clients almost always want their shop to be driven by probably the best open-source e-commerce solution called Magento. Yes, I just said Magento is probably the best e-commerce platform and don’t be surprised – in the last two months I reduced sleeping and fully dedicated myself to learn the platform and I am so happy I can finally say that Magento has come to make a lot of sense to me now. Honestly, it will take a long time to discover all of its beutiful concepts, but even though I think Magento is a fantastic framework that does a lot of work for you. And really cool thing is that you don’t have to be an expert, it’s enough to be familiar with its modular structure, basic concepts, request flow and you’ll find at least starting (often whole) idea for solving concrete problem on Google. Of course, you need strong OOP knowledge in PHP, and everything will be a lot easier if you understand MVC pattern.
Let’s talk about stuff that makes Magento unique
Okay, we should all know that Magento is a system that requires a lot of reading and practising. That’s why I am not going to write tutorial – it will not change the world. Instead, I’ll point out to you some interesting facts I came up with while learning.
#1 Unique filesystem and MVC
File structure is the first thing you’ll notice when you open Magento filesystem. It contains folders like /app, /lib, / skin, /media, /var etc. I will not cover them at all because there are a lot of tutorials out there, but pay a special attention to /app if you are a developer or /skin if you are a designer. These two folders are where big stuff happens.
I’d rather discuss how MVC is implemented in Magento, because it’s funny, unique (and strange) part for those developers coming from some other MVC frameworks. In a typical PHP Model-View-Controller (MVC) application, all the controllers will be in one folder, all the models in another, etc. In Magento, files are grouped together based on functionality, which are called modules.
All Magento’s modules are stored in app/code/core, but if you developed your custom module, the convention is to put its files in app/code/local/your-module-name. When you want to add custom functionality to core Magento modules, it is highly recommended to make a local copy of that core module and paste it in app/code/local/core-module-name and then start to make changes (safe overriding). It’s really a bad idea to edit module files directly in their core folder because when you upgrade Magento, it can override your changes by its updates, and your work will disappear. There is one more folder in app/code called community and this one was designed for modules developed by third parties that are very common in the community.
#2 Misunderstood meaning of Magento layout
So this was probably the thing that frustrated me the most because I simply didn’t understand what it was doing and why it even existed. Even now I am not 100% sure that I understand every concept behind layout, because I haven’t covered all of them yet, but it’s far better than it was at the beginning. Layout is nothing but HTML container which defines structure on a website for almost every system EXCEPT Magento. Actually, it defines site structure, but in a different way.
Big difference from the other systems is that you do not have html layout, but xml layout. You are maybe wondering now – how it is possible to create site structure in XML, but yep – it’s true. In
Magento, layout xml files contains Block nodes in it, and what’s interesting – every Block method can be called directly from the layout (passing parameters to these methods is dead easy too)! Each Block will render a specific bit of HTML. Block objects do this through a combination of PHP code, and including PHP .phtml template files.
I know that you are confused know because I’ve just mention three similar terms (layout, block and template), and if so, be happy – your Magento trip is ready to start! Indeed, block objects are meant to interact with the Magento system to retrieve data from Models, while the phtml template files will produce the HTML needed for a page. Once again, it’s okay if it is far from clear to you, but at least I think I forced you to start Googling and researching. For the end, let this graph (Magento rendering flow) always be somewhere in your mind while developing.
#3 Really complex database: entity-attribute-value pattern
Until now, we were discussing Magento code. The next thing why the whole system is unique is its database organization. Here is a little comparation, just for fun: WordPress CMS by default has 11
tables in its database. Magento comes with 350+ tables. That’s one reason why I was installing Magento system several times – the server couldn’t execute all that database stuff, so I needed to increase max_execution_time and some other parameters I don’t remember right now.
If you are wondering why Magento needs 350+ tables, it’s because some parts of the database (not all) are developed according EAV (Entity-Attribute-Value) pattern. I don’t know too much about how it’s implemented, but basically instead of a table consisting of a number of columns, the attributes are stored in one column of a separate table which allows us to easily manage adding new attributes to most parts of the system, while keeping the database schema consistent. Did you create attributes and their sets for particular products or product groups? This feature directly takes advatage of EAV pattern.
Every system has its pros and cons. The good part of Magento database is, as we said, its flexibility. But the down side is its complexity. The consequence is that it is very hard for us, developers, to write simple SQL queries (we need a lot of JOINS).
#4 Template path hints
The last thing that I simply have to mention is my favourite Magento feature designed specially for developers, called “Template path hints”. I’ve tried almost every open-source CMS, but I haven’t found something similar to this – it’ so unique to Magento. Because Magento is very complex system and any page viewed in the browser consists of a lot of templates generated by their blocks (as we mention above). In order to find out what templates are being called to a page you’d like to modify, you can turn on the Template Path hints. In order to enable it:
1. Go to the admin and navigate to System -> Configuration
2. Select your store in the top left website/store selector
3. When the page reloads, select the ‘Developer’ tab and select ‘Yes’ for Template Path Hints.
When you’re done, go back to the store front, reload your page and you will see the path to all the templates listed according to the block. In order to modify the markup, all you have to do is follow the path written out for you and modify the according template(s).
Milan Stojanov – Junior Web developer @Implementek