Hi
I know allot of people have been asking how to mainly access $_SESSION['customer_id'] from outside zen cart.
I also have posted a few times asking until it dawned on me, perhaps i could use SOAP to get the session data i need. I finally got the system working and would like to share my code with you guys and perhaps get some feedback??
Ok first off we need to download "NuSOAP" and extract the files into the following folder structure:
ZEN_CART_ROOT/nusoap/lib/FILES_HERE
Create the following file:
ZEN_CAR_ROOT/session_get.php
Within session_get.php the following code:
Code:
<?php
// Include application top
include_once ( "includes/application_top.php" );
function get_session( $var ){
return ( settype ( $_SESSION['customer_id'], "string" ) );
}
// Load up nusoap library
require_once('nusoap/lib/nusoap.php');
// Create soap object
$Soap_Obj = new soap_server();
// COnfigure WSDL
$Soap_Obj->configureWSDL ( "session_get", "urn:session_get" );
// Register callback function
$Soap_Obj->register('get_session',
array ( "var" => 'xsd:string'),
array ( "return" => 'xsd:string'),
'urn:session_get',
'urn:session_get#get_session',
'rpc',
'encoded',
'Returns Zen Cart Session Var'
);
// Wait for response
$Soap_Obj->service($HTTP_RAW_POST_DATA);
?>
Now from the script you want to get the data to , for example the "customer_id" you use the following code:
Code:
<?php
// Load up nu_soap
require_once('ZEN_CART_ROOT/nusoap/lib/nusoap.php');
//now we must create a soapclient object
$soapclient = new nusoap_client('http://YOURDOMAIN.COM/ZEN_CART_ROOT/session_get.php?wsdl',true);
// Call get session variable function from server
$result = $soapclient->call ( "get_session", array ( "var" => "customer_id" ) );
if ( $client->fault ) {
echo "<h2>Fault</h2><pre>";
print_r ( $result );
echo "</pre>";
} else {
// trap error
$err = $soapclient->getError();
if ( $err ) {
echo "<h2>Error</h2><pre>" . $err . "</pre>";
print_r ( $result );
echo "</pre>";
} else {
echo "<h2>Result</h2><pre>";
echo $result;
echo "</pre>";
}
}
?>
This piece of code is where we choose what variables to return:
Code:
// Call get session variable function from server
$result = $soapclient->call ( "get_session", array ( "var" => "customer_id" ) );
Hope this helps people!
Bookmarks