Drupento aims to integrate two of the most powerful open source systems available - Drupal and Magento. The goal of this project is to provide an lightweight static caching layer between the two systems. Drupento allows each system to operate independently, letting the developer or themer choose the points of integration.

Drupento consists of 2 parts - the Drupal module, and the Magento extension.
The Magento extension is required if you are using the Drupento Auth add-on module. It is optional otherwise, however, there are some API enhancements included that are useful when using the Drupento cache layer as well.

Drupento is developed and maintained by Context (http://contextllc.com). This project came out of necessity when a client specifically requested Drupal and Magento, and the layout required elements of both systems on many pages.

DRUPENTO POWERED SITES

http://laurazindel.com
http://keystoneballast.com
http://waldensurfboards.com

What it Does

The primary issue that prompted the development of Drupento was that the Magento theme on our client's site needed to share the same menu as the Drupal theme. We also needed to do this WITHOUT bootstrapping Drupal on each page load inside Magento, for obvious performance reasons.

Drupento makes this easy with a single, static method:

Drupento::Output('home', '#primary_nav');

This static method does a lot, making it the primary component of the module. The method and its parameters are explained in detail in the Usage section.

  • Provides an API for use inside of Magento, which allows developers
    to output Drupal content in a Magento template
  • Provides functionality to cache custom queries to the Magento API (SOAP/XML-RPC)
  • Supports caching of:
    • Paths/Elements
    • Nodes
    • Custom Callbacks

What it DOESN'T

  • By itself, Drupento doesn't provide any integration of the systems outside of the caching mechanism
  • Drupento doesn't do any caching automatically - the developer must invoke Drupento where it is needed

Installation & Requirements

REQUIREMENTS:

NOTE: The server must have a copy of the Simple HTML DOM library somewhere that is accessible by the user account running the site. There is a configuration option for the path to the library. Normally, you will want to put this in /sites/all/libraries, which is the default location Drupento looks for.

http://simplehtmldom.sourceforge.net/

NOTE: These instructions assume your Magento install lives within your Drupal base directory. This is no longer a requirement for usage of the module, but depending on where Magento lives in relationship to where Drupal is installed, you may experience permissions issues.

Typically (for us, at least), a Drupento project's directory layout looks something like:

  • /drupal
    • /index.php
    • /sites
    • /modules
    • ... other stuff ...
    • /store (Magento)

The installation instructions will assume this layout.

TO INSTALL:

  1. Copy the drupento directory to your module directory and then enable on the admin modules page.
  2. Set up the initial permissions:
    • /store (or your Magento install dir) - needs to be writable by the server for the config file. When you save the Drupento configuration options, a configuration file is written to the root of the store. After you have a working setup, you can restrict the permissions on this directory.
    • /path/to/drupento/module - needs to be writable by server (only if you have enabled logging in the code)
  3. Install the Magento extension here: http://www.magentocommerce.com/extension/packages/module/6035/drupento
    There are no configuration options for the Magento module
  4. Configure the drupal module - See next section.

Configuration

Configuration of Drupento is done via the settings page at:
http://domain.tld/admin/settings/drupento

These configuration options are shared between both the Magento and Drupal installations through a config file that gets written upon saving the form.

THE OPTIONS:

*** NOTE: All paths must be ABSOLUTE ***

Main Settings
  • Cache lifetime
    • the number of seconds the cached files will remain fresh. If Drupento tries to include a cache file that is expired, it will re-cache before doing so.
  • Magento Store Code
    • The machine code of the Magento store you are connecting to
  • Callback Configuration File
    • the path to the file which contains custom callbacks for the site. This is explained in the Usage section.
  • Cache directory umask
    • the umask to use for the cache directory and its subdirectories. Defaults to 0777
  • Magento API URL
    • the full url of the Magento API wsdl
  • Magento API username
    • the api username
  • Magento API Password
    • the api password
Path Settings
  • Cache path
    • the cache path is where the cached files will be stored. This should be a directory under the docroot (/path/to/drupal/cache)
  • Path to Magento Base Install
    • the path to the Magento base directory
  • Simplehtmldom Path
    • the path to the Simple HTML DOM library. Defaults to the libraries directory
  • PHP Cli binary path
    • the path to the php binary on the system. This is required, as many hosts have different versions of php for apache and the cli. Drupento requires PHP 5.2 or later, as well as SOAP (this is a Magento API requirement) for both Apache AND CLI. On unix based systems, to the output of "which php"
Cookie Settings
  • Cookie Lifetime
    • This controls the session lifetime of Drupento sessions. This value will ONLY be used for users authenticated using the Drupento Auth module
  • Cookie Domain
    • This setting controls the domain the cookies for Drupento Auth will be created for. IMPORTANT: The value set in the Magento backend MUST match this EXACTLY.

*NOTE: Upon saving the configuration values, a config file is written in the base of the Magento directory.

How it Works

Working with Drupento requires a bit of knowledge about how exactly it accomplishes it's task. From start to finish, here is an example of a 'dom_element' cache request made by Drupento.

Drupento::Output('home', '#primary_nav');

  1. When the above code is executed, Drupento will look for a cache file for the '#primary_nav' element at the path '/home'
  2. If the cache file exists (and is not stale), it is simply included. Otherwise, Drupento will the invoke a cli "bridge" script and request a cache file for that path/element
  3. Before the element can be cached, the path itself must be cached. If it is not cached already, and it is not stale, Drupento will bootstrap Drupal and cache the entire output of the path.
  4. After the path has been cached, the Simple HTML Dom library is used to extract the element from the markup.
  5. The element is cached, and then Drupento includes the cache file. Processing continues.

Usage

As mentioned previously, most of the functionality of Drupento on the Magento side stems from the Drupento::Output method. The output method can cache the following:

  • Path & Element
  • Callback

Drupento::Output( $type_or_target, $selector = null, $options = array() );

This method is overloaded in a sense - for ease of use, we allow Output() to be called with only two parameters, even though the first parameter is sometimes a cache type (e.g. 'callback'), and other times it is a uri path (e.g. 'home').

PATH/ELEMENT CACHING:

Drupento::Output('home', '#primary_nav');

If the first param is not a cache type of either 'callback' or 'node', Drupento will assume you are trying to cache a path/element.

CALLBACK CACHING:

This is useful both on the Magento side AND the Drupal side. Callback caching allows us to generate any markup, and cache it to a file. The primary example of this, and the reason callback caching exists, is for use with the API:

Say you wanted to generate a menu of Magento categories and use it on your Drupal homepage. The Magento API is sometimes a reasonable option for getting data, but the overhead of making a SOAP or XML-RPC call on every load makes this less-than-ideal in our case.

In your callback config file (which is specified in the configuration), you can write functions to generate the required markup.
Additionally, Drupento provides a simple API wrapper to manage the client and session transport.

	function print_product_menu() {
		$html = '';
		$result = Drupento::Api_get('drupento_category.tree', array(CATEGORY_ID), true);

		foreach( $result as $category ) { 	
			// generate the html
			...
		}
	
		return $html;
	}
	

You can then invoke this callback and cache/output the return by calling:
Drupento::Output('callback', 'print_product_menu');

NODE CACHING:

$node = Drupento::Node_load(267);

If the node is not already cached, Drupento will bootstrap Drupal, perform a node_load, and then cache the serialized $node object.
Otherwise, the $node object will be loaded from the cached copy.

You can then work with the node object just as you would inside of Drupal.

Whenever a node is updated in Drupal, Drupento will check to see if there is a cached copy. If one exists, Drupento will re-cache it to keep the Magento side up to date ***

Drupento SSO (drupento_auth)

The Drupento Auth module provided with Drupento allows you to use shared credentials for users on your site. Drupento Auth modifies the login form to use email addresses rather than a username.

The only step needed to enable SSO is to enable the module. Assuming all of your settings are correct, the authentication routines of both systems should then be synced.

NOTES:

  1. Make sure your cookie domain is set properly in the Drupento config, as well as the Magento configuration. The cookie domain should always include the leading '.'.

Comments

meaux’s picture

Thanks for the module. Ive been looking for a way for drupal and magento to work together. Ive downloaded and installed the module but having some issues. I have the latest copy of Simple HTML DOM in my drupal/sites/all/libraries/simplehtmldom directory and set the configuration option to point there. My magento install is at drupal/store. Ive copied drupento to my modules directory and enabled it. /store and /path/to/drupento/module are writable by the server. I set the configuration option as specified. Ive downloaded contextllc-drupento-2814e7a21700 but dont know what to do with the magento folder. Can you please help me out with this.

swiss2011’s picture

Hi,

Thanks for the module. I was able to successfully configure the module with magento. User actions like create/edit/delete are working fine. When a user logs in into magento he is automatically logged in drupal.However the vice versa is not working as expected. When a user try to login it goes to blank page.The error i get is given below

[Tue Sep 13 23:53:50 2011] [error] [client 10.2.1.241] PHP Fatal error: Uncaught SoapFault exception: [Receiver] Unknown error in /opt/drupal_commons/profiles/drupal_commons/modules/contrib/drupento/Drupento.class.php:271\nStack trace:\n#0 [internal function]: SoapClient->__call('call', Array)\n#1 /opt/drupal_commons/profiles/drupal_commons/modules/contrib/drupento/Drupento.class.php(271): SoapClient->call('098994ba93ecd32...', 'drupento_custom...', Array)\n#2 /opt/drupal_commons/profiles/drupal_commons/modules/contrib/drupento/Drupento.class.php(285): Drupento::Api_get('drupento_custom...', Array, false)\n#3 /opt/drupal_commons/profiles/drupal_commons/modules/contrib/drupento/drupento_auth.module(97): Drupento::Call('drupento_custom...', Array)\n#4 /opt/drupal_commons/profiles/drupal_commons/modules/contrib/drupento/drupento_auth.module(447): drupento_customer_login('thayu@domainname....', 'domainname123')\n#5 /opt/drupal_commons/profiles/drupal_commons/modules/contrib/drupento/drupento_auth.module(141): _drupento_auth_external_login('thayu@domainname....', 'domainname123')\n#6 /opt/drupal_comm in /opt/drupal_commons/profiles/drupal_commons/modules/contrib/drupento/Drupento.class.php on line 271, referer: http://xxxxx.domainname.in/user

Have any one come across the same problem? Please help..

mdeltito’s picture

I see you are using Drupal Commons... I have never tested Drupento with Commons, and it is very likely that some included module is interfering with the API call.

Can you PM me the output of:

print_r($args);

in that method? I would need to see what values are being passed to determine what is going on.

Thanks!

ltor’s picture

Hi,

I don't understand why i get this error when i try to create an account from drupal (is use the SSO from drupento) :

user warning: Table 'drupal62.core_store' doesn't exist query: SELECT * from core_store WHERE code = "base" in C:\wamp\www\drupal-6.20\modules\drupento\drupento_auth.module on line 408.

This message is about a table which do not exists on the drupal database but exists on the magento side.

Any ideas ?

Regards

Laurent

mdeltito’s picture

Please post bug reports in the issue queue for this module.

As for your issue, it sounds like you are using separate databases for drupal and magento. In this case, you are required to set the store_id and website_id in the "advanced" options of the module configuration.

Head over to the issue queue and open a ticket if you still have trouble

relevant code in _drupento_auth_register_magento_user:

	$store_id = variable_get('drupento_magento_store_id', null);
	$website_id = variable_get('drupento_magento_website_id', null);

	// THIS WILL ONLY BE CALLED IF THE ADVANCED OPTIONS ARE NOT SET
	// THIS REQUIRES DRUPAL AND MAGENTO TO BE ON THE SAME DB
	if(!$store_id || !$website_id) {
		// this allows a developer to inject a custom store code to create the user against
		$store_code = variable_get('drupento_auth_override_store_code_create', null);
		if( !$store_code ) {
			// no override, get the code set in drupento options, otherwise use 'default'
			$store_code = variable_get('drupento_magento_store_code', 'default');
		}
		
		$store_lookup = db_fetch_object(db_query('SELECT * from {core_store} WHERE code = "%s"', $store_code));				
		$store_id = $store_lookup->store_id;
		$website_id = $store_lookup->website_id;
	}
aritrasaha’s picture

Hi,
I have setup the Drupento module with my drupal folder at htdocs/drupal and magento at htdocs/drupa/store. I am able to migrate users successfully from Drupal to Magento. However, logging into to drupal using any of the ids gives the following error.

Fatal error: Uncaught SoapFault exception: [3] Invalid api path. in C:\xampp\htdocs\abpdrupal\sites\all\modules\drupento\Drupento.class.php:271 Stack trace: #0 C:\xampp\htdocs\abpdrupal\sites\all\modules\drupento\Drupento.class.php(271): SoapClient->__call('call', Array) #1 C:\xampp\htdocs\abpdrupal\sites\all\modules\drupento\Drupento.class.php(271): SoapClient->call('0528f449aaee4ab...', 'drupento_custom...', Array) #2 C:\xampp\htdocs\abpdrupal\sites\all\modules\drupento\Drupento.class.php(285): Drupento::Api_get('drupento_custom...', Array, false) #3 C:\xampp\htdocs\abpdrupal\sites\all\modules\drupento\drupento_auth.module(97): Drupento::Call('drupento_custom...', Array) #4 C:\xampp\htdocs\abpdrupal\sites\all\modules\drupento\drupento_auth.module(447): drupento_customer_login('asdf@yahoo.com', 'admin123') #5 C:\xampp\htdocs\abpdrupal\sites\all\modules\drupento\drupento_auth.module(141): _drupento_auth_external_login('asdf@yahoo.com', 'admin123') #6 C:\xampp\htdocs\abpdrupal\includes\form.inc(781): _drupento_auth_validat in C:\xampp\htdocs\abpdrupal\sites\all\modules\drupento\Drupento.class.php on line 271

Kindly advice.

batigolnguyen’s picture

zzz