There are numerous ways to integrate Magento with Drupal. Here I will share my experiences while working on that with very smart people at Optaros. I don’t take credit for all the points in this post, because they are the product of the whole team.
The motivation for this kind of integration is the innovative look into where e-commerce is moving. To get a grasp of it look at OCentric. To keep it short, content is free advertisement for products. It allows customers to get more input about products and provides the meat for search engines to index.
Briefly, there are several main approaches to integrate Drupal and Magento:
- let Magento be the main component, while leaving Drupal just as a subcomponent
- let Drupal be the main component, and have Magento as an e-commerce module
- let both Magento and Drupal be main components
These are general approaches and each of them have different pros and cons. They will be further detailed by usecases, complexity, technicalities, etc. in the following sections.
Moreover, we will release much of the code as open source, so it’s not only a theoretical discussion here:)
Magento as the Main Component
The straightforward solution is to integrate on the service layer. Meaning that whenever we are on the e-shop product page we have to call a Drupal service to bring related content, for instance blog posts. The same holds for category pages. How to do that:
- Create a Drupal module that allows you assigning categories and products to a content node in Drupal
- Implement XML-RPC client on Magento side and use it to talk to services on Drupal in order to pull the content (e.g. using view.get or node.get funuctions)
- Rewrite the category and product controllers on Magento to take the content from Drupal into account
There are some challenges in taking this way. They are mainly for those who want to implement features in a generic way. Specifically, whenever you add a CCK field or a feature like rating to a content type, you have some work to do on the Magento side. Namely, you need to modify layout and write templates to handle this additional data coming from Drupal. Hence it’s pretty cumbersome to use Drupal community contributed modules as you need to do some coding on Magento side for every new Drupal feature. This is quite easy when the content from Drupal is read-only, but as soon as you want commenting, rating, flagging, etc. it becomes an issue, because you need to not only redo rendering on Magento but also map the functionality.
A more complex path to take is to integrate the whole Drupal rendering engine into Magento, however, this means a very tightly coupled architecture… Still, if you plan to use many many many of the Drupal features it may make sense. This will require writing a Drupal module for Magento that will adapt every Drupal core function to Magento. Could end up as a very complicated solution.
We chose the XML-RPC because of the given time frame and specific requirements. Normally a product or a category will be associated with a very specific set of content types, and therefore the fully generic solution may not pay off.
By the way there is already a CMS module for Magento as part of the core. And the question is why would one want to struggle integrating Drupal instead of using that CMS module? Moreover, with enterprise 1.6 version of Magento the module offers quite cool features. Some things from the top of my head to consider:
- Drupal has a solid community, and it is more stable and feature-rich than the Magento CMS module will ever be (of course it’s good as soon as you make the Drupal-Magento integration reasonably flexible)
- There is the CCK module that allows to very quickly add additional fields to a content type and make it available to the content producing team
- Content versioning, workflow, etc. is easy in Drupal
- …more ?
Drupal as the Main Component
This approach has been already taken by others and you can start digging for it here. We’ve tried out the available modules but didn’t stick with them… Basically there the implementation is based on the notion of synchronizing Magento products, categories, orders, etc. into Drupal using a cron job.
In general, although Drupal-as-the-main-component approach in the end may give a lot of flexibility, it may be too complex to implement. Imagine that the whole Magento frontend functionality needs to be rewritten for Drupal. Magento would then only be an e-commerce backend (the admin part) accessible via Web services. Of course you’d be able to use plenty of Drupal modules as well as flexible templating without any hassle, have better performance, and many other goodies but it just looks too expensive to implement.
Still, bringing only a part of Magento into Drupal makes a lot of sense (as in that module that synchronizes products and orders into Drupal using cron job). In this case it’s a decision to make whether the site is more about content or about commerce. When it’s about content, then you don’t really care about SEO for products, fancy business logic, etc.
Both Mangento and Drupal as the main Components
This is reasonable when the content will be displayed on the Drupal site and e-shop on the Magento site. Meaning that no proxying for content happens behind the scenes. So if a product has a blog post attached, then on the product page you’ll have a link (maybe even the post itself loaded using Ajax call) and clicking it will open a Drupal page with that blog post.
One of the challenges here is to maintain two different themes in order not to harm user experience. So that when the customer clicks on the blog link inside the product page the blog is displayed with the same look and feel as the shop. For that you can’t avoid coding on two different frameworks. Apart from theming SEO will have to be also maintained on both components.
Another challenge would be the ability to mix content with product information on the same page. Some kind of communication on the service layer will be necessary for that, which means that it’s not really reasonable to use this dual approach with such a usecase present.
It may make sense, however, to take this path when there are only some of the things to be shared between both components, e.g. users, and everything else is completely separate. For example, when a company has an e-commerce site, a customer community site, and a corporate site.
Additional Points for Integration
The end user display is only one part of the story. When you integrate this kind of monster systems to work seamlessly you get trapped with other things besides templating.
One of them is single sign on. A good thing to do here is to use CAS. Drupal already has the CAS module. Magento, however, needs one (we’ve been writing one). The good news that all the low level protocol implementation is available for PHP as open source.
Another thing is search. Independently of the integration approach chosen eventually you want to search for products and content in the same search box. This may become pretty challenging but it’s not impossible. We’ve got a proof of concept for the store front in Magento, where we leverage Solr search. It performs really well for our suggest box functionality.