This week I have been busy with a typical setup out there: integrated website that runs on both WordPress and Magento. Theoretically the best of both worlds: CMS and eCommerce/Shopping Cart. Yes, essentially you run your home page and any content pages off of WordPress and then all category pages and product pages will be powered by Magento. This is fairly easy to accomplish by installing one of the two under a specific folder usually, Magento goes under /shop/ or /store/. The only thing left is similar themes and ready to go, right?
Yes, but… What happens if you want to integrate the menu between the systems. I have seen many variations on how to resolve this issue, some very creative like simply handling the entire menu manually in a file that is not part of any system and simply including the file in both themes. This is great as long as you want to manually manage your file. What if you want something more dynamic? anyway, you get the point. It can easily get challenging.
One thing to avoid is coupling. So, what you really want is to integrate two systems but keep them decoupled. Let’s review for a second what decoupled means in the Software Development world (skip the next paragraph if you know it):
This is streight from Wikipedia. Decoupling:
In software development, the term “decoupling” is used to identify the separation of software blocks that shouldn’t depend on each other. Some building blocks are generic and shouldn’t know details of others. Special design techniques allow software designers to have as little dependencies as possible. This typically reduces the risk of malfunction in one part of a system when the other part changed. It also forces the developer to focus on one thing at a time.
Notice that I highlighted the important part: if you apply decoupling practices when integrating between systems you reduce the risk of malfunctioning in one part when the other one changes. I know when a developer is deep in the trenches it is hard to believe that something may break, but this is just the nature of software development. In fact, it is more likely that it will break then not.
Anyway, the specific system that I have been working on had been using the menu system from WordPress ver 3.0.1 (which by the way, they have done a great job redoing the menu admin interface, kudos WP people!). The menu is then including some files from Magento which then added a few subitems into the menu depending on categories and products that exist in the Magento DB. This is great and should work fine, but the issue is when something goes wrong, like for example the wordpress was including cached versions of some files which may or may not be in use – and depending on what you are hitting first (Magento or WordPress) if there is no cache, Magento gets an empty inclusion file and as you know, it outputs the usual Exception Report and crashes.
Here is where decoupling comes handy: instead we have selected one main system that will be our control for the menu, that would be WordPress. Then we have decided that we will feed a JSON service from Magento into the WordPress files. The JSON Web Service essentially replaces a hard inclusion which may break. Then we will add a small piece of logic to actually check what comes through the JSON web service from Magento and decide what to do with it. Hence, the system is now integrated, decoupled, and has a nice fail safe mechanism.
I hope this helps someone out there who is trying to build an integrated website with WordPress and Magento… if you need more details, hit me up with some questions.