Home Communication board WiKi Get Quote

X-Cart and Joomla user accounts integration

I hope you have read and install the first part of the X-Cart and Joomla integration. This advanced integration will allow to use the same accounts on the X-Cart and Joomla.

The idea of the user integration is pretty easy - we have to disable one software user registration/authentication and make everything with the second software. Since the X-Cart is primary in our basic integration, we will disable the Joomla things.

We are using the joomla.php for all of the Joomla requests, so we will adjust it for the special actions on the registration/authentication. The following code should be inserted to the joomla.php:

if ($_POST['task'] == 'login') {
    chdir(XCART_DIR.'/include/');
    $_POST['password'] = $_POST['passwd'];
    $_POST['mode'] = 'login';
    $_POST['usertype'] = 'C';
    include XCART_DIR."/include/login.php";
}

if ($_GET['view'] == 'register') {
    include XCART_DIR."/auth.php";
    func_header_location('../register.php');
}

if ($_GET['task'] == 'logout') {
    chdir(XCART_DIR.'/include/');
    $_POST['mode'] = 'logout';
    include XCART_DIR."/include/login.php";
}

and the final version of this file will look like the following:

<?
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();
}

if ($_POST['task'] == 'login') {
    chdir(XCART_DIR.'/include/');
    $_POST['password'] = $_POST['passwd'];
    $_POST['mode'] = 'login';
    $_POST['usertype'] = 'C';
    include XCART_DIR."/include/login.php";
}

if ($_GET['view'] == 'register') {
    include XCART_DIR."/auth.php";
    func_header_location('../register.php');
}

if ($_GET['task'] == 'logout') {
    chdir(XCART_DIR.'/include/');
    $_POST['mode'] = 'logout';
    include XCART_DIR."/include/login.php";
}

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);
?>

With this code we will forward the user registration and the log in/log out to the X-Cart shopping cart.

Now when the registration and authentication is overlapped, we have to make the changes in the X-Cart code. The joomla auth/registration can be done with the additional functions we have to insert to the X-Cart shopping cart files below.

include/login.php

The new code should be inserted after the following lines:

#
# Set cookie with username if Greet visitor module enabled
#
            if (!empty($active_modules["Greet_Visitor"]) && $login_type == "C") {
                func_setcookie("GreetingCookie", $user_data['firstname']." ".$user_data['lastname'], time() + 15552000);
            }

The code:

            x_load('joomla');
            joomla_user_login($user_data);

include/login.php

The new code should be inserted after the following lines:

    x_session_unregister("initial_state_show_notif");
    x_session_register("login_redirect");
    $login_redirect = 1;

The code:

    x_load('joomla');
    joomla_user_logout($user_data);

include/register.php

The new code should be inserted before the following code:

        #
        # Set cookie with username if Greet visitor module enabled and the customer was logged
        #
        if (!empty($active_modules["Greet_Visitor"]) && $login_type == "C" && (strlen($newuser_info['first_login'] . $newuser_info['last_login']) > 0 || $auto_login)) {
            func_setcookie("GreetingCookie", $newuser_info['firstname']." ".$newuser_info['lastname'], time() + 15552000);
        }

The new code is:

        x_load('joomla');
        joomla_user_update($newuser_info);
        if($auto_login)
            joomla_user_login($newuser_info);

As you can see the new functions are used there and you have to place the func.joomla.php with these functions to the include/func/ dir of the X-Cart shopping cart. The content of this file is below:



Now the users will be synced by sessions and profiles between the software.

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