I've been working with this same issue and thought I would post my solution to the problem. I also could not access any information about the users session or the shopping cart outside of my zencart store directory, so what I did was opened up an invisible page inside an iFrame, and used JavaScript to send the information I needed to the parent page. It looked something like this.
This is the script on the page I created that I placed inside my zencart store directory. I named this "customerInformation.php". It finds out whether the user is logged in or not, what their cart total is, number of items, cart ID, security token and customer first name:
Code:
<script>
<?php if ($_SESSION['customer_id']) { ?>
parent.setValue("isLoggedIn","true");
<?php } else { ?>
parent.setValue("isLoggedIn","false");
<?php } ?>
parent.setValue("total",<?=$_SESSION["cart"]->total;?>);
parent.setValue("totalItems",<?=$_SESSION["cart"]->count_contents();?>);
parent.setValue("cartID","<?=$_SESSION["cart"]->cartID;?>");
parent.setValue("securityToken","<?=$_SESSION["securityToken"];?>");
parent.setValue("customer_first_name","<?=$_SESSION["customer_first_name"];?>");
</script>
Then, On the page of my website where I need to access that information, I opened customerInformation.php in an iFrame with a zero width and height so it cannot be seen, and I added this javascript code:
Code:
function setValue(name,value){
if(name == "isLoggedIn" ){
if(value == "true"){
// show logout button
} else {
// show login button
}
} else if(name == "total"){
// display the cart total
} else if(name == "totalItems"){
//display total items in cart
} else if(name == "securityToken"){
// do what you with with this
} else if(name == "customer_first_name"){
// display the users name
}
}
The JavaScript functions would either show or hide relevant div tags, or populate text into an area using "innerHTML". This unfortunately won't help you if you need to process the information with PHP on the server side, but if it's simply about displaying information to the user, it may be just what you need.
Bookmarks