Jump to content

How do I get the current users email address?


Recommended Posts

Hi everybody, long time lurker here. Wanted to say thanks for all the help you have all provided with problems in the past.


I'm currently having an issue with getting the email address of a logged in user. Basically, what i'm wanting to do is get the email address of a logged in user, and if that email address matches a specific email address then display a hidden category. This is due to our biggest customer not wanting their products easily accessible by other customers, and i'm trying to keep them happy by only showing the category with their products to them.


I have had some success by putting the following code in the box.navigation.php file:


 {if $USER.email == '[email protected]'}
<li class="li-nav"><a href="www.page.co.uk/category.html" title="Customer Name">Customer Name</a></li>
However, this only displays the extra link when I am on the "index.php?_a=profile" page, which is where I got the variable "$USER.email" from, so I assume this variable is only available to that page.
What i'm looking for is some way of getting the current user email address reliably so my website knows when to display the category, or an alternate way of only displaying this category to a single customer.
Thanks for reading, I look forward to your responses.
Link to comment
Share on other sites

We can start by looking into CubeCart's ability to assign customers to Customer Groups. Currently, CubeCart only associates customer groups with custom pricing schedules of products. That is, a "Wholesale" customer might see "wholesale" prices and no taxes.


Also, CubeCart can "hide" categories. So, when the "Customer-A Doodads" category is created, it is enabled, but hidden.


What's missing, and we would need to create a mod fo, is the glue table that associates a customer group to assigned categories. That's not hard to implement.


And it offers much more flexibility and scope in its implementation.

Link to comment
Share on other sites

Hi Bsmither, thanks for your quick response.

So if I would be better tieing it all together as a mod, where would I look for documentation on how to go about it? I have experience working with PHP but very little with the smarty system, so if you know of any tutorials that would help me get started I would be very greatful.

Alternatively, are there any similar mods you know of that I could use as a starting point to work from?



Link to comment
Share on other sites

Not so much a 'mod' as is in a pre-packaged, drop-in functionality (although that could be developed), rather as modifying some of the core code and modifying the database by adding a new table.


There is (was) a mod that tied customers to categories, but the publisher is no longer supporting CubeCart.


There is no comprehensive documentation (such as a Software Developer's Kit - SDK) that will help you.


I will gladly get you started and help you along the way.

Link to comment
Share on other sites

Hi bsmither,


Thank you for offering your help and giving me a starting point to work from. After a morning of reading up on the documentation for smarty tags, I have solved the problem. Basically, I created a new function to check the customer id against the customer membership table and if they are a member of the group with group_id 1, it will return the html for the extra category.


I'm sure there are better ways of executing this, but for anyone else stuck with a problem like this, here is the code I used (You would need to fill in the blanks for MySQL and your website address):

 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.getcustid.php
 * Type:     function
 * Name:     getcustid
 * Purpose:  outputs an extra category based on customer id
 * -------------------------------------------------------------
function smarty_function_getcustid($params, Smarty_Internal_Template $template)

$sessionid = $_COOKIE['PHPSESSID'];
	 $sqlq = "SELECT * FROM `CubeCart_sessions` WHERE `session_id` = "".$sessionid.""";
	 $mysqli = $mysqli = mysqli_connect('host', 'username', 'password', 'database');
     $res = mysqli_query($mysqli, $sqlq);

             if ($res) {
                    while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
			            $custid = $newArray['customer_id'];
			            $returnhtml = '';
			            $newsqlq = "SELECT * FROM `CubeCart_customer_membership` WHERE `membership_id` = 1";
                        $newres = mysqli_query($mysqli, $newsqlq);
			            if ($newres) {
                                while ($secArray = mysqli_fetch_array($newres, MYSQLI_ASSOC)) {
                                        $custid2 = $secArray['customer_id'];
                                        if ($custid == $custid2) { $returnhtml = '<li class="li-nav"><a href="http://www.mywebsite.com/hidden-category.html" title="Extra Category">Extra Category</a></li>'; }
return $returnhtml;

I saved this in a file called "function.getcustid.php", dropped it in the /lib/smarty/plugins folder and added a the following tag into my box.navigation.php file, located inside the skins/yourskinname/templates folder:

<div id="nav">
	<div class="navContainer">
		<ul class="dropdown">
			<li><a href="//www.stockmonkey.co.uk/index.php" title="{$LANG.navigation.homepage}">{$LANG.navigation.homepage}</a></li>
			<li class="li-nav"><a href="{$URL.certificates}" title="{$LANG.navigation.giftcerts}">{$LANG.navigation.giftcerts}</a></li>
			 {/if} {if $CTRL_SALE}
			<li class="li-nav"><a href="{$URL.saleitems}" title="{$LANG.navigation.saleitems}">{$LANG.navigation.saleitems}</a></li>
	        {getcustid}         //<-- This is the extra tag <--
<div class="clear">

I have combined this with making the category hidden to get the desired result.


Should anyone consider using this, I wouldn't recommend just throwing this code into your website unless you are used to working with PHP and MySQL. There are parts of it that would need to be changed to fit your website.


Once again, thanks for offering your help, bsmither, and thanks for pointing me in the right direction. If you have any thoughts on how I could improve my code, please let me know. I have only been working with PHP for a few months, so I am not accustomed to best practices.




Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...