Tutorial: Integrating 3rd Party CMS Content Within Magento

Integrating 3rd party CMS content into Magento has been a popular request by the Community. Outlined below is a technique using Expression Engine with the idea of managing content pages with EE, and displaying the content within Magento, using Magento’s 404 event handler. We will fetch this content using Varien_Http_Client.

Please note that Expression Engine is used for demonstration purposes only and other CMS platforms (Wordpress, Modx, Joomla, Drupal) can be used if desired.

image

Getting Started

For this example, we’ll assume Expresion Engine is installed inside the Magento directory in a folder called ‘ee’, so our store’s URL will be http://www.example.com and our EE’s URL will be http://www.example.com/ee/.

Note: Both Magento and EE must be installed with the Apache URL rewrite feature.

The .htaccess file for EE:

RewriteEngine on

RewriteCond 
%{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d
RewriteCond 
%{REQUEST_FILENAME} !-l
RewriteRule 
^(.*)$ index.php?/$1 [QSA,L]

The home page of your installed EE must be the same as your Magento store home page (http://www.example.com)

Create a Local Code Pool Module

We will create a module in the local code pool as follows:

- create a new directory called “Project” under “app/code/local/Mage”
- create a new directory called “Block” under “Project”
- create a new file called Noroute.php under “Block” and copy the following code into the script.

class Mage_Project_Block_Noroute extends Mage_Core_Block_Abstract
{
    
protected function _toHtml()
    
{
      
/**
       * This logic should be in the controller, model, but let's make 
       * this quickly without lots of files :)
       */

        
$uri Mage::getBaseUrl() . 'ee' $this->getRequest()->getRequestString();
        
$post $this->getRequest()->getPost();
        
$method = ( count($post) == ) ? 'GET' 'POST';

      
/**
       * You can add additional
       * headers like cookies, redirects and so on
       * if you need it here.
       */

        
$client = new Varien_Http_Client($uri);
        
$client->setParameterPost($post);
        
$response $client->request($method);

        
$body $response->getRawBody();
        return 
$body;
    
}
}

To enable the Project module from local pool, create a file called “Magento_Project.xml” under “app/etc/modules” and copy the following code:

<?xml version="1.0"?>
<config>
    <
modules>
        <
Mage_Project>
            <
active>true</active>
            <
codePool>local</codePool>
        </
Mage_Project>
    </
modules>
</
config>

Create a Layout

Now we need to add this block to the layout. Let’s edit the app/design/frontend/YOUR_DESIGN_PACKAGE/default/layout/cms.xml and modify ‘cms_index_defaultnoroute’ section:

<cms_index_defaultnoroute>
        <
remove name="left"/>

        <
reference name="root">
            <
action method="setTemplate"><template>page/1column.phtml</template></action>
        </
reference>
        <
reference name="content">
            <
block type="project/noroute" name="no_route" />
        </
reference>
    </
cms_index_defaultnoroute>

Next, we’ll disable the 404 page (identifier: ‘no-route’) in the Magento administration (CMS->Manage Pages).

Finally, refresh Magento’s Cache and edit the templates within EE removing all headers, footers. Visiting pages like http://www.example.com/sample will now include the content from http://www.example.com/ee/sample with Magento’s header, footer and other components.

Extending the Technique

In order not to redirect all invalid requests to EE, a regex expression can be added to limit the requests that are redirected to EE and such requests will be processed by the Magento’s noroute handler.

This post is also available on the Magento Wiki

RSS: New Article posts

Explore the Knowledge Base