Multiple sites, zen cart, etc. Can I make the same login work on all the sites?
-
Here’s what I need to do:
I need to move the website “/public_html/forum”
into the folder “/public_html/zenpress/”
I have multiple sites within this directory that all need to be accessed with the same login/cookie tracking as the wordpress site at “/public_html/forum”.
The main reason for this is that I have a zen-cart installation in “/public_html/zenpress/cart” that is very important. I want people to be able to browse the whole site, and not lose their shopping cart contents when they leave “/public_html/zenpress/cart”
(I realize that the cart’s cookie keeps records for 24 minutes, but I was thinking it would be best to have the same cookie/login throughout the site.
*Note- I don’t want it to be necessary for someone to login at all, but if I choose to add that function for any reason, I want to only have to add it in the wordpress @ /public_html/forum and it will give access to all sites within that directory.Also important- but less urgent: I also need to update the search bar so that it includes all the sites and add a cart image to the header so I can link it to a cart.
Thank you!
PS:
I’ve been using information from:
https://michaelwender.com/blog/2010/10/28/integrating-wordpress-and-zencart/
So far everything works fairly well, but I’m not sure what to do about the part titled:
Zen Cart? Compatibility Functions for your WordPress Theme’s functions.php
–the author says to add the following code but I’m not sure where to add it:
define(‘ZENCART_DIRECTORY’,’products’); // name of the directory in which ZenCart is installed
// START ZenCart Functions
/*
* updateShoppingCart() – inserts/updates a WPDB copy of the ZenCart shopping cart
*/
function updateShoppingCart(){
global $wpdb;
$cart = $_SESSION[‘cart’];
$qty = 0;
foreach($cart->contents as $item){
$qty = $qty + $item[‘qty’];
}
if($wpdb->get_var(‘SHOW TABLES LIKE “‘ .$wpdb->prefix. ‘zen_cart”‘) != $wpdb->prefix.’zen_cart’) {
$sql = “CREATE TABLE ” .$wpdb->prefix. “zen_cart (
id INT( 11 ) UNSIGNED NOT NULL ,
qty INT( 11 ) UNSIGNED NOT NULL ,
total DECIMAL( 10, 2 ) NOT NULL ,
zenid VARCHAR (64) NOT NULL ,
time timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY ( id )
) ENGINE = MYISAM”;
$wpdb->query($sql);
}
if(!empty($cart->cartID)){
$cart_id = $wpdb->get_var(‘SELECT id FROM ‘ .$wpdb->prefix. ‘zen_cart WHERE id=’ .$cart->cartID);
if($cart_id != $cart->cartID){
$sql = ‘INSERT INTO ‘ .$wpdb->prefix. ‘zen_cart VALUES (‘.$cart->cartID.’,’.$qty.’,”‘.sprintf(‘%.2f’,$cart->total).'”,”‘.$_COOKIE[‘zenid’].'”,”‘ .current_time(‘mysql’).'”)’;
} else {
$sql = ‘UPDATE ‘ .$wpdb->prefix. ‘zen_cart
SET qty=’.$qty.’,total=”‘.sprintf(‘%.2f’,$cart->total).'”,zenid=”‘.$_COOKIE[‘zenid’].'”,time=”‘ .current_time(‘mysql’).'” WHERE id=’.$cart->cartID;
}
$wpdb->query($sql);
}
}/*
* getShoppingCart() – retrieves the WPDB copy of the user’s ZenCart shopping cart
*/
function getShoppingCart(){
global $wpdb;
cleanShoppingCarts();
if(isset($_COOKIE[‘zenid’])){
$cart_row = $wpdb->get_row(‘SELECT qty,total FROM ‘.$wpdb->prefix.’zen_cart WHERE zenid=”‘.$_COOKIE[‘zenid’].'” ORDER BY time DESC’, ARRAY_A);
if($cart_row){
return $cart_row;
} else {
return false;
}
} else {
return false;
}
}/*
* cleanShoppingCarts() – deletes WPDB copies of ZenCart shopping carts older than 900s
*/
function cleanShoppingCarts(){
global $wpdb;
$calculation = ‘TIMESTAMPDIFF(SECOND,time,”‘ .current_time(‘mysql’).'”)’;
$comparison = $calculation. ‘ > 900’;
$sql = ‘SELECT id FROM ‘.$wpdb->prefix.’zen_cart WHERE (‘ .$comparison. ‘)’;
$old_carts = $wpdb->get_results($sql);
foreach($old_carts as $old_cart){
$wpdb->query(‘DELETE FROM ‘.$wpdb->prefix.’zen_cart WHERE id=’ .$old_cart->id);
}
}/*
* empty_wp_zencart() – deletes a WPDB copy of a ZenCart shopping cart
*/
function empty_wp_zencart($zenid){
global $wpdb;
$wpdb->query(‘DELETE FROM ‘.$wpdb->prefix.’zen_cart WHERE zenid=”‘.$wpdb->escape($zenid).'”‘);
}
// END ZenCart Functions
- The topic ‘Multiple sites, zen cart, etc. Can I make the same login work on all the sites?’ is closed to new replies.