Home Communication board WiKi Contact us

Basic integration of the X-Cart and Joomla Software

The basic integration of the Joomla and X-Cart software is allow to integrate the layouts the same way as the well know X-Cart - WordPress integration do. With this integration you will replace the central part of X-Cart with the central part of Jomla on all of the Joomla pages.

1. First, you need to make sure your server rewrite engine is enabled, then you need to add the following rules to the .htaccess file (located in X-Cart folder on your server):

RewriteEngine On
RewriteRule ^joomla/(administrator)(.*)$ joomla/$1$2  [QSA,L]
RewriteRule ^joomla/(.*).(css|js|gif|jpg|png|html)$ joomla.php?incl_file=$1.$2 [QSA,L]
RewriteRule ^joomla/.*$ joomla.php?url=$1  [QSA,L]
RewriteRule ^joomla$ joomla.php  [QSA,L]

Do not forget to use RewriteBase if X-Cart is not located in the root of your web server. If the X-cart is located in the shop subdir it can be done this way:

RewriteEngine On
RewriteBase /shop/
...

Please note that these rules imply that Joomla software is installed in a “joomla” sub-directory (e.g. X-Cart store is available at domain.com while Joomla is available at domain.com/joomla).

All of the blog requests are forwarded to a new “joomla.php” file - it needs to be created in X-Cart root directory on the server:

<?
define(XCART_DIR, rtrim(realpath(dirname(__FILE__)), DIRECTORY_SEPARATOR));
$joomla_dir = 'joomla';

if ($_GET['incl_file']) {
    $incl_file = preg_replace('/\.\./', '', $_GET['incl_file']);
    $file = XCART_DIR.'/'.$joomla_dir.'/'.$_GET['incl_file'];
    $path_info = pathinfo($file);

    if (is_file($file)) {
        if ($path_info['extension'] == 'js') {
            header('Content-Type: application/x-javascript');
            echo file_get_contents($file);
        }
        elseif($path_info['extension'] == 'css') {
            header('Content-Type: text/css');
            echo file_get_contents($file);
        }
        elseif($path_info['extension'] == 'gif') {
            header('Content-Type: image/gif');
            echo file_get_contents($file);
        }
        elseif($path_info['extension'] == 'png') {
            header('Content-Type: image/png');
            echo file_get_contents($file);
        }
        elseif($path_info['extension'] == 'jpg') {
            header('Content-Type: image/jpeg');
            echo file_get_contents($file);
        }
        elseif($path_info['extension'] == 'html') {
            header('Content-Type: text/html');
            echo file_get_contents($file);
        }
        die();
    }
    elseif($path_info['extension'] == 'html') { # possible that the clean url has got the html extension
        $url = $_GET['url'] = $_GET['incl_file'];
    }
    else
        die();
}

ob_start();
chdir($joomla_dir.'/');
include_once 'index.php';
$content = ob_get_contents();
chdir(XCART_DIR);
ob_end_clean();
if ($_GET['format'] == 'pdf' || $_GET['print']) {
    die($content);
}

define('CONTENT_VAR', $content);
include "./auth.php";

$content = CONTENT_VAR;
preg_match("/\<head.*\>.*\<title\>(.*)\<\/title\>(.*)\<\/head\>.*\<body.*\>.*(\<div id=\"area\">.*)<div id=\"whitebox_b\">.*\<\/body\>/Uims", $content, $out);
if (!$out) die($content);

preg_match_all("/(<link.*>)/", $out[2], $links);
preg_match_all("/(<style.*<\/style>)/ims", $out[2], $styles);
preg_match_all("/<meta.*name=\"(.*)\".*content=\"(.*)\" \/>/", $out[2], $meta);
preg_match_all("/(<script.*<\/script>)/Uims", $out[2], $jss);
$joomla_content = $out[3];

if(is_array($jss[1]))
foreach($jss[1] as $js)
    $js_content .= $js."\n";
$joomla_content = $js_content."\n".$joomla_content;

if(is_array($links[1]))
foreach($links[1] as $link)
    $css_content .= $link."\n";
if(is_array($styles[1]))
foreach($styles[1] as $css)
    $css_content .= $css."\n";

$joomla_content = $css_content."\n".$joomla_content;

$joomla_title = $out[1];

require $xcart_dir."/include/categories.php";
if ($active_modules["Manufacturers"])
    include $xcart_dir."/modules/Manufacturers/customer_manufacturers.php";
if ($active_modules["Bestsellers"])
    include $xcart_dir."/modules/Bestsellers/bestsellers.php";
if (is_array($meta))
foreach($meta[1] as $ind=>$val) {
    if ($val == 'keywords')
        $_meta_keywords = $meta[2][$ind];
    elseif($val == 'description')
        $_meta_descr = $meta[2][$ind];
}
$smarty->assign('page_data', array('metatitle' => $joomla_title, 'metadescr' => $_meta_descr, 'metakeywords' => $_meta_keywords));
unset($location);
$location[] = array($joomla_title);
$smarty->assign('location', $location);

$smarty->assign('joomla_content', '<div style="position:relative">'.$joomla_content.'</div>');

$smarty->assign('main', 'joomla');
func_display('customer/home.tpl', $smarty);
?>

As you can see the whole idea of the Joomla integration is the same as the X-Cart - WordPress integration. We are getting the content of teh joomla page and cut the title, css and body information.

Now we can use the extracted information in the X-Cart system.

2. As for templates, first we should include a new template for the joomla content into the “skin1/customer/home_main.tpl” file (in X-Cart folder) by adding the following 2 lines:

{elseif $main eq 'joomla'}
{include file='customer/main/joomla.tpl'}

It's better to add the code to the end of the file, e.g. in this way:

{elseif $main eq "view_results"}
{include file="modules/Survey/customer_view_results.tpl"}

{elseif $main eq 'joomla'}
{include file='customer/main/joomla.tpl'}

{else}
{include file="common_templates.tpl"}
{/if}

Also we should create a new template for the Joomla content - “skin1/customer/main/joomla.tpl” - with the following lines:

{capture name=dialog}
{$joomla_content}
{/capture}
{include file="dialog.tpl" title=$_meta_title content=$smarty.capture.dialog extra='width="100%"'}

3. In addition, it is worth showing Joomla meta tags in default X-Cart meta tags.

In the 4.2.x version you need to change the skin1/customer/meta.tpl template and insert the following code:

{if $printable}
  <meta name="ROBOTS" content="NOINDEX,NOFOLLOW" />
{elseif $main eq 'joomla'}
<meta name="description" content="{$page_data.metadescr|truncate:"500":"...":false|escape}" />
<meta name="keywords" content="{$page_data.metakeywords|truncate:"500":"":false|escape}" />
{else}
	{meta type='description' page_type=$meta_page_type page_id=$meta_page_id}
	{meta type='keywords' page_type=$meta_page_type page_id=$meta_page_id}
{/if}

You can see here addiitonal {elseif}…{else} section.

In order to change a page title in previous X-Cart versions it is required to change the “skin1/customer/home.tpl” template in X-Cart by inserting the following lines:

<title>
{if $page_data.metatitle}
{$page_data.metatitle}
{else}
...
{/if}
</title>

where the ”…” value is the default code inside the ”<title>” tag.

For the same purpose the “skin1/meta.tpl” template in X-Cart should be changed in the following way:

{if $page_data.metadescr}
{assign var="_meta_descr" value=$page_data.metadescr}
{/if}
{if $page_data.metakeywords}
{assign var="_meta_keywords" value=$page_data.metakeywords}
{/if}

The code should be added below the following lines:

{assign var="_meta_descr" value=""}
{assign var="_meta_keywords" value=""}

Additional things to check

Please check the following things additionally.

Joomla configuration file

In the joomla/configuration.php file you should check the live_site option. It should be filled with the full Joomla url, which should look like:

    var $live_site = 'http://www.domain.com/joomla/';

It's important, because in other case the joomla css, forms and etc will follow to the wrong base url.

X-Cart home template

Since the Joomla content is pretty wide - it's better to disable the left and right menus of the X-cart. It's possible to do in the skin1/customer/home.tpl by the following condition:

{if $main ne 'joomla'}
...
{/if}

In the X-Cart 4.3.x it should be this way:

{if $main ne 'joomla'}
                <div id="left-bar">
....
          {include file="poweredby.tpl" }

                </div>
{/if}

Possible problems

Problem with styles

The X-Cart styles are crossed with the Joomla styles. Mostly it's related with the #header and #footer classes. All of the duplicates should be removed from the Joomla css files. It can be done without any problem because these styles are not used after the integration, since the header and footer are replaced to the X-Cart ones.

Empty content

Sometimes this script can not parse Joomla pages properly to find meta and body information. Such problem may be related to the WordPress version or design changes performed to the Joomla skin. In this case it will be required to review “joomla.php” file and find suitable preg_match expression.

Should you have any questions, feel free to contact us . We will be glad to help you.

Changelog

27 May 2010 - The code and article is published for the free access

The advanced integration article is prepared now, with this type of integration you will be able to sync the sessions and users in X-Cart and Joomla

 
Home About us Privacy statement Terms & Conditions Refund policy © 2007–2019 ArsCommunity