Integrating Joomla and Zencart (Sort Of) Using CURL and Standalone Templates

I’ve developed quite a few Joomla and Zencart sites, some clients taking both together for their website. Joomla being great for the website CMS, and Zencart great for the shopping cart. The problem is, no complete, working integration exists between them. None that I have found anyway. A couple have been written and are work in progress in my mind, but still lacking in fundamental functionality. So the website ends up clearly as two separate systems to the website visitor which is not ideal. So I have spent some time trying to think of a way to integrate the two together and have come up with what looks to be a good solution… CURL.

This blog explains how to set this up in order to show Zencart within your website design. You will need knowledge of PHP, CURL and creating and assigning templates in Joomla and Zencart. Note: this is not integrating the Admin but the front end, to give the impression to the visitor that they are on the same website!

Actually, you don’t even have to use Zencart. It can be any other separate system to your Joomla website that you can change the template for. So you can use this method to add any Joomla module onto any other non-Joomla website.

[Update 6th June 2009] Note: Since going live with a site using this method it has become apparent that occasionally under heavy load the CURL does not function and either shows a “Cannot Connect to Database Error” or a “Flooding”error. Therefore it may not be the best method after all I will keep searching for an alternative.

What we would like to see is the Zencart system inside your main website (inside your header, main navigation and footer) but not as a wrapper (iframe) because this is bad for search engines. The solution is simple… create a new template that only shows the website header, another one for the navigation, and another one for the footer, and use CURL to “pull in” the website header and footer and any other modules.

Step 1 – Create the templates

Create a new template that only shows your header. So in the index.php file only include the necessary Joomla core code and the module. Here is an example that will only output the header code for this template:

defined( '_JEXEC' ) or die( 'Restricted access' );
?>
<div id="header_box">
<div id="header"></div>
</div>
<div id="main_nav_box">
<jdoc:include type="modules" name="nav" style="raw" />
</div>

Thats the entire index.php file. You still need the templateDetails.xml file and upload your new template to the /templates/ folder. mine is just called “header”. I do the same for the footer.

Step 2 – Assign the New Bare Template to a Menu Item So You Can Link to It

Joomla allows you to assign different templates to different menu items. So first create a new menu item you will use to assign the template to. You don’t have to publish this, just create a new Menu that you don’t use. I call mine “Hidden Menu”. Once your menu item is created, go to Extensions -> Template Manager to assign the new template to this new menu item.

Step 3 – Check out the Module Web Page

Now just do a quick test… grab the URL for this new menu item from the Menu Manager and visit it in the browser. You will now see your standalone module on its own in the browser. This module can be dynamic content, your menus, latest news, any dynamic content provided by Joomla. Now we know that works we can add it to the Zencart template….

Step 4 – Add the New Standalone Joomla Modules to Zencart

In your Zencart template you can now remove the Zencart built in Header and Footer to be left with just the main page with your products and left and/or right hand columns. Instead add in the CURL script to call in the above Joomla modules to appear instead!

<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, HTTP_SERVER.'http://www.your_domain.com/index.php?option=com_content&view=article&id=1&Itemid=51');
curl_exec($curl);
curl_close($curl);
?>

Obviosuly just update the above CURL link to your menu link obtained in Step 2 and 3.

Step 5 – Finish

That’s it! Now if you visit your Zencart store you should see the Joomla header and footer appearing above and below your main Zencart shop so it looks like it’s within the same site. Updating Joomla such as adding new links, will automatically update them in the Zencart store. So when you now link from your website to Zencart, it looks to the casual user that they are on the same website.