Post by petabait@gmail.com » Mon Dec 14, 2009 8:01 pm

Hi,
i would like to display the customer email in the header bar when he is logged in.
Something like this:
Logged as: customer@customer.com

I´ve tried to do this but i can´t
Can u help me?
Thank u in advance


Posts

Joined
Mon Dec 14, 2009 7:59 pm

Post by huhitschris » Mon Dec 21, 2009 7:56 am

Open: catalog\controller\common\header.php

Update your file with the following mod:

Code: Select all

class ControllerCommonHeader extends Controller {
	protected function index() {
		$this->language->load('common/header');
	    
		/* Mod (show customer email) */
		if ($this->customer->isLogged()){
			$this->load->model('account/customer');
			$customer_info = $this->model_account_customer->getCustomer($this->customer->getId());
						
			if (isset($customer_info)) {
				$this->data['email'] = $customer_info['email'];
			} else {
				$this->data['email'] = '';
			}
		}
		/* End Mod */
		
		$this->data['store'] = $this->config->get('config_store');
Now open: catalog\view\default\template\common\header.tpl

Add this line wherever you want to display the user's email address:

Code: Select all

<?php echo($email); ?>
Let me know how that works out for you.

-Chris

PM me for custom OpenCart template design and development.


New member

Posts

Joined
Wed Aug 19, 2009 3:12 pm

Post by allenshea » Sun Dec 27, 2009 6:11 pm

huhitschris wrote:Open: catalog\controller\common\header.php

Update your file with the following mod:
It doesn't work if the client didn't log in the account.

I know nothing about PHP and SQL, but I still try my best to understand it.


Active Member

Posts

Joined
Mon Dec 14, 2009 10:01 pm

Post by huhitschris » Sun Dec 27, 2009 6:28 pm

Ahh, good catch!

I forgot to mention that header.tpl uses the $logged variable to determine if a user is logged in, so using an IF statement around this variable can help you display the user's email or display a generic "not logged in" message or whatever you prefer. :)

Something like this should work:

Code: Select all

<?php if (!$logged) { ?> Not Logged In <?php } else { echo $email; } ?>

PM me for custom OpenCart template design and development.


New member

Posts

Joined
Wed Aug 19, 2009 3:12 pm

Post by allenshea » Sun Dec 27, 2009 8:19 pm

It works fine now

I know nothing about PHP and SQL, but I still try my best to understand it.


Active Member

Posts

Joined
Mon Dec 14, 2009 10:01 pm
Who is online

Users browsing this forum: No registered users and 2 guests