xvbIntegration - X-Cart + vBulletin Integration
X-Cart Mods, X-Cart Addons: [url]http://www.websitecm.com/[/url]
--------------------------------------------------------------------------
What this is:
The following is a
guideline for x-cart and vbulletin integration. It works by transferring all user aspects (registration/update/login/lostpass) to x-cart, and then using x-cart to keep the vbulletin database up-to-date. It provides the necessary class file for user functions and instructions for installation of the class file, a script to migrate users from x-cart to vbulletin, and a guideline for integration into your vbulletin templates.
What this is not:
This is not a step-by-step how-to for x-cart and vbulletin integration, rather it is a guideline with reference to our integration, to allow you to more easily understand what is required for your specific integration.
Notes: Integration does not perform user deletions. Admin deletions must be manually performed in both x-cart and vbulletin separately.
Modification requires x-cart and vbulletin to share a database.
------------------------------------------------------------
Upload Provided Files
------------------------------------------------------------
Download the attached files and upload the files provided (except for readme.txt) to the corresponding x-cart directory on your server.
------------------------------------------------------------
User Migration
------------------------------------------------------------
It is necessary to ensure that the same username/email/password is present on both your x-cart and your vbulletin. For the purpose of this integration we assume your x-cart has customers, and you do not yet have any vbulletin non-admin users (i.e. it is a new installation). If you have an existing vbulletin, you will need to synch your databases.
You can either run the following script via your browser, or via SSH. Personally I recommend SSH (with a 'screen' if your savvy) as browsers can sometimes have load issues with larger stores.
In your browser, type: [url]http://www.yourdomain.com/xcart-dir/admin/xvbUsers.php[/url] (change your domain name and xcart directory)
If running via SSH, change into your x-cart admin directory, and type: php ./xvbUsers.php
IMPORTANT: Delete the xvbUsers.php from your admin folder when complete.
If all went well, you will now have the same users in your x-cart database, as in your vbulletin. Do not proceed until this is in place.
We will now make the necessary changes to update vbulletin whenever a change in x-cart takes place.
------------------------------------------------------------
Open include/register.php
------------------------------------------------------------
FIND:
Code:
}
else {
#
# Add new person to customers table
#
BEFORE ADD:
Code:
// xvbIntegration - Update
if (!$anonymous_user && $login_type == "C") {
include $xcart_dir."/modules/xvbIntegration/class.vbreg.php";
$xvb = new xvbIntegration();
$newuser_info = func_userinfo($login, $login_type, true);
unset($vbInsert);
$vbInsert['username'] = $login;
$vbInsert['email'] = $newuser_info['email'];
$vbInsert['password'] = text_decrypt($newuser_info['password']);
$xvb->xvbUpdate($vbInsert);
}
// / xvbIntegration - Update
FIND:
Code:
}
if (!empty($active_modules['SnS_connector']) && $usertype == 'C' && defined("AREA_TYPE") && constant("AREA_TYPE") == 'C') {
BEFORE ADD:
Code:
// xvbIntegration - Register
if (!$anonymous_user && $usertype == "C") {
include $xcart_dir."/modules/xvbIntegration/class.vbreg.php";
$xvb = new xvbIntegration();
unset($vbInsert);
$vbInsert['username'] = $profile_values['login'];
$vbInsert['email'] = $profile_values['email'];
$vbInsert['password'] = text_decrypt($profile_values['password']);
$xvb->xvbRegister($vbInsert);
}
// / xvbIntegration - Register
------------------------------------------------------------
Open include/login.php
------------------------------------------------------------
FIND:
Code:
db_query("UPDATE $sql_tbl[customers] SET last_login='$tm' WHERE login='$login'");
db_query("REPLACE INTO $sql_tbl[login_history] (login, date_time, usertype, action, status, ip) VALUES ('$username','$tm','$usertype','login','success','$REMOTE_ADDR')");
AFTER ADD:
Code:
// xvbIntegration - Login
include $xcart_dir."/modules/xvbIntegration/class.vbreg.php";
$xvb = new xvbIntegration();
$xvb->xvbLogin($login,$remember);
// / xvbIntegration - Login
FIND:
Code:
x_session_register("login_redirect");
$login_redirect = 1;
AFTER ADD:
Code:
// xvbIntegration - Logout
include $xcart_dir."/modules/xvbIntegration/class.vbreg.php";
$xvb = new xvbIntegration();
$xvb->xvbLogout();
// / xvbIntegration - Logout
------------------------------------------------------------
vBulletin Template Changes
------------------------------------------------------------
Your vbulletin users table will now be updating whenever changes in x-cart take place, and logging in and out of x-cart will also log a user in and out of x-cart. It is now necessary to update your vbulletin login/register areas to access x-cart instead of vbulletin. This is a very complex modification that cannot be documented step-by-step as it will vary from store to store.
Here's a guideline of how I performed our integration:
--------------------------------
Login
--------------------------------
I viewed source on our x-cart registration page, and then I cleaned up the code, and pasted it into our vbulletin HEADER template to appear on our side navigation. In the form code, I added this line of code to indicate to our x-cart that we were logging in from the forum:
Code:
<input type="hidden" name="redirect2" value="forum" />
I also added this code from the default vbulletin to pass the current page url:
Code:
<input type="hidden" name="url" value="$scriptpath" />
I updated the following x-cart templates similarily:
STANDARD_ERROR
STANDARD_ERROR_LITE
STANDARD_ERROR_LOGIN
To redirect the user back to the forum on login and/or error, I modified our include/login.php to check for the existence of $redirect2 to determine whether or not to send them to the forum, and checked the existence of $HTTP_POST_VARS['url'] to determine if there was an exact url back to which to send them.
On error, I appended &error=1 to the url and then modified our above mentioned vbulletin templates to display a login error message when $_GET['error'] == 1.
--------------------------------
Register
--------------------------------
This was a difficult process for integration. I contemplated modifying the register.php of the forum to redirect to our main x-cart registration, but this would have taken a user off the forum registration layout, and forced them to fill in billing/shipping information, etc., which I didn't feel was necessary for a simple forum registration. Instead, I opted to customize the register vbulletin template.
I created a new form that contained the necessary/desired fieldnames in x-cart, and had the form post to a new x-cart registration file which I called register_forum.php. To create this register_forum.php file, I took the default x-cart register.php and replaced the include/register.php line in the file with the actual content from include/register.php. I then stripped down the contents of the file to what was necessary (this code is very bloated as it serves many different purposes) and ensured that the file could only be used for new registrations by inserting a redirect at the top of the file when $mode was specified or when the user was already logged in. I also forced this file to not work for anonymous logins, or any user type other than a customer.
Upon successful registration, I used the following code to register the user in vbulletin also, and then log them into the forum:
Code:
// xvbIntegration - Register
include $xcart_dir."/modules/xvbIntegration/class.vbreg.php";
$xvb = new xvbIntegration();
unset($vbInsert);
$vbInsert['username'] = $profile_values['login'];
$vbInsert['email'] = $profile_values['email'];
$vbInsert['password'] = text_decrypt($profile_values['password']);
$xvb->xvbRegister($vbInsert);
// / xvbIntegration - Register
Wanting vbulletin to display messages generated by my internal error checking, I used the following code to pass an error variable back to the forum:
Code:
unset($reg_error);
if (!empty($fillerror)) $reg_error="missing_fields";
if (!empty($uerror)) $reg_error="username_taken";
if (!empty($error)) $reg_error="username_invalid";
if (!empty($emailerror)) $reg_error="email_invalid";
$redirect = "/forum/register.php?do=register&agree=Y&firstname=" . urlencode($firstname) . "&lastname=" . urlencode($lastname) . "&email=" . urlencode($email) . "&uname=" . urlencode($uname) . "&password=" . urlencode($password) . "®_error=$reg_error";
func_header_location($redirect);
The $redirect variable passes the information back to vbulletin in an error string, along with the registration error, and then re-populates the fields and displays a message corresponding with the appropriate error type.
In order to pass the variables from the query string to the vbulletin registration form for re-population, I made this change in my vbulletin register.php:
FIND:
Code:
// Variables that are used in templates
AFTER ADD:
Code:
$uname = $_GET['uname'];
etc. for all form fields that I used.
On successful registration I again checked the existence of $HTTP_POST_VARS['url'] for url redirection, or sent them to the forum homepage.
--------------------------------
Checkout Check
--------------------------------
Since the user is able to register on the forums with minimal information, when the user attempts to checkout of x-cart they will not have a billing/shipping address and similar information entered. To correct this I added the following code to our cart.php which checks for the existence of a billing country, and if not present forces them to update their profile with a provided explanation at the top of the page:
FIND:
Code:
$smarty->assign("partner", $partner);
AFTER ADD:
Code:
// xvb - Forum Registrations must fill out all information to proceed
if ($mode == "checkout" && $login && $userinfo['b_country'] == "") {
$top_message['type'] = "I";
$top_message['content'] = "Please complete the required fields below to proceed with your purchase.";
func_header_location("register.php?mode=update&action=cart&paymentid="); exit;
}
--------------------------------
Lost Pass
--------------------------------
I modified our lostpw vbulletin template to link to our x-cart password retrieval popup.
--------------------------------
Link Updates
--------------------------------
I then searched through our vbulletin templates and made necessary changes to any links to register.php login.php or areas where username, email, or password could be updated. These included:
modifyoptions
modifyprofile
USERCP_SHELL
--------------------------------
Test! Test! Test!
--------------------------------
If, after all your swearing, head-shaking, and blaming the computer for your mistakes, things went well, you will now have an integrated x-cart and vbulletin.
Good luck!