Post by thir13en » Mon May 24, 2010 5:50 pm

Hello,

How can I display the name of a logged in customer in the header?
I want to display something like Hello, John Doe.
Thank you in advance! :)

Newbie

Posts

Joined
Mon May 24, 2010 5:45 pm

Post by thir13en » Fri May 28, 2010 9:16 pm

Anyone? :(

Newbie

Posts

Joined
Mon May 24, 2010 5:45 pm

Post by Qphoria » Fri May 28, 2010 9:21 pm

Add this to the header.tpl file:

Code: Select all

<?php if ($this->customer->isLogged()) { ?>
Welcome <?php echo $this->customer->getFirstName(); ?> <?php echo $this->customer->getLastName(); ?>, Enjoy your stay!
<?php } ?>

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by thir13en » Sat May 29, 2010 12:47 am

it works!
And it's even simpler than my version!

Thanks a lot! :)

Newbie

Posts

Joined
Mon May 24, 2010 5:45 pm

Post by skydrake » Sat Jul 18, 2015 11:33 pm

it don't work in v2, which line should i put in? i tried middle, top n bottom. advice pls. thx

Newbie

Posts

Joined
Fri Jul 17, 2015 11:45 pm

Post by javox » Sun Aug 09, 2015 10:22 am

Anyone has any update on this? Looks as if in V2 doesn't work. Would be welcomed any clue.

Newbie

Posts

Joined
Sun Aug 09, 2015 10:02 am

Post by IP_CAM » Sun Aug 09, 2015 11:08 pm

javox wrote:Anyone has any update on this? Looks as if in V2 doesn't work.
It does not need an update, in this section, because this here is the V.1.5.x - Zone.

OC v.2 is entirely different, it does not even display some WELCOME 'related' Variable, therefore,
any (similar) Welcome Section Content, defined down to the last language File, involved,
would have to be added, to make it work.
Therefore, it must be done another way, to make it work with v.2

Ernie

My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by Qphoria » Thu Aug 20, 2015 2:31 am

2.0 doesn't allow direct calls to libraries from the tpl.
For 2.0 you need to add it to the controller and set a view variable.

1. EDIT: catalog/controller/common/header.php

2. FIND:

Code: Select all

public function index () {
3. AFTER, ADD:

Code: Select all

if ($this->customer->isLogged()) {
    $data['welcome_message'] = sprintf("Welcome %s %s, Enjoy your stay!", $this->customer->getFirstName(), $this->customer->getLastName());
}
4. EDIT: catalog/view/theme/YOURTHEME/template/common/header.tpl

5. PUT THIS WHERE YOU WANT IT:

Code: Select all

<?php if (isset($welcome_message)) { echo $welcome_message; } ?>

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by IP_CAM » Fri Aug 21, 2015 1:02 am

After a few checks, I placed it as shown below, to make it look swell. Since my 'OC v2 like No Shop Software' uses no last name, I removed the lastName Line, and one piece of %s, to make it work:

Code: Select all

public function index() {
if ($this->customer->isLogged()) {
$data['welcome_message'] = sprintf("Welcome %s, Enjoy your stay!", $this->customer->getFirstName());
}
Question:
my public function index() { looks like this, and others look like this: public function index () {
now, wich one is written correctly, anyway !?

just to mention it!
Ernie

My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by IP_CAM » Fri Aug 21, 2015 2:48 am

Just found an OC v.2 Extension for this:
http://www.opencart.com/index.php?route ... n_id=20606
Ernie

My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by raunharman » Wed Sep 30, 2015 2:14 pm

This does not work for my site. I am using Opencart 2.0.1.1 with stowear theme.
Have a look at tacfabfashions.com



Qphoria wrote:2.0 doesn't allow direct calls to libraries from the tpl.
For 2.0 you need to add it to the controller and set a view variable.

1. EDIT: catalog/controller/common/header.php

2. FIND:

Code: Select all

public function index () {
3. AFTER, ADD:

Code: Select all

if ($this->customer->isLogged()) {
    $data['welcome_message'] = sprintf("Welcome %s %s, Enjoy your stay!", $this->customer->getFirstName(), $this->customer->getLastName());
}
4. EDIT: catalog/view/theme/YOURTHEME/template/common/header.tpl

5. PUT THIS WHERE YOU WANT IT:

Code: Select all

<?php if (isset($welcome_message)) { echo $welcome_message; } ?>

Newbie

Posts

Joined
Sat Sep 19, 2015 4:02 pm

Post by raunharman » Mon Oct 12, 2015 1:13 pm

Thanks for your reply.
However I have not been able to get it right.
Could you please specify where exactly in header.tpl to put the last piece of code?

Newbie

Posts

Joined
Sat Sep 19, 2015 4:02 pm

Post by raptorheli » Tue Jun 07, 2016 2:06 am

Done this as described , but it is not working in OC 2.1.0.2
What is wrong here, pls advice

EDIT: catalog/controller/common/header.php

2. FIND:
CODE: SELECT ALL
public function index () {

3. AFTER, ADD:
CODE: SELECT ALL
if ($this->customer->isLogged()) {
$data['welcome_message'] = sprintf("Welcome %s %s, Enjoy your stay!", $this->customer->getFirstName(), $this->customer->getLastName());
}

4. EDIT: catalog/view/theme/YOURTHEME/template/common/header.tpl

5. PUT THIS WHERE YOU WANT IT:
CODE: SELECT ALL
<?php if (isset($welcome_message)) { echo $welcome_message; } ?>

New member

Posts

Joined
Tue Mar 05, 2013 1:35 pm

Post by mephistop » Thu Jun 16, 2016 3:13 pm

raptorheli wrote:Done this as described , but it is not working in OC 2.1.0.2
What is wrong here, pls advice

EDIT: catalog/controller/common/header.php

2. FIND:
CODE: SELECT ALL
public function index () {

3. AFTER, ADD:
CODE: SELECT ALL
if ($this->customer->isLogged()) {
$data['welcome_message'] = sprintf("Welcome %s %s, Enjoy your stay!", $this->customer->getFirstName(), $this->customer->getLastName());
}

4. EDIT: catalog/view/theme/YOURTHEME/template/common/header.tpl

5. PUT THIS WHERE YOU WANT IT:
CODE: SELECT ALL
<?php if (isset($welcome_message)) { echo $welcome_message; } ?>
Hi,

Add this code in catalog/language/english/common/header.php

Code: Select all

            
$_['text_logged']  = 'You are logged in as <b><a href="%s">%s</a></b> <b>(</b> <a href="%s">Logout</a> <b>)</b>';  
$_['text_welcome'] = 'Welcome visitor you can <a href="%s">login</a> or <a href="%s">create an account</a>.'; 
$_['text_welcome'] = 'Welcome!';
 
Then add this code in catalog/controller/common/header.php
after ($data['text_shopping_cart'] = $this->language->get('text_shopping_cart');)

Code: Select all

$data['text_welcome'] = sprintf($this->language->get('text_welcome'), $this->url->link('account/login', '', 'SSL'), $this->url->link('account/register', '', 'SSL'));
And then add this code in catalog/view/theme/YOUR_THEME/template/common/header.tpl

Code: Select all

<?php if ($logged) { ?>
<?php echo $text_logged; ?>
<?php } else { ?>
<?php echo $text_welcome; ?>
<?php } ?>
After all changes update modification.

Enjoy!

Newbie

Posts

Joined
Thu Jun 16, 2016 3:08 pm

Post by v1tr4 » Mon Jul 31, 2017 12:19 pm

It doesn't work on version 2.3.0.1, i've tried with extension or adding manually but still not work.

Newbie

Posts

Joined
Thu Jul 27, 2017 11:06 am

Post by IP_CAM » Fri Aug 11, 2017 8:38 am

http://www.opencart.com/index.php?route ... n_id=20606

In OC 2.3.2.0, the OcMod Extension exactly matches the Code, and would so function,
at least in an OC Default Theme.
Ernie

My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by sunilkumar.25 » Thu Sep 14, 2017 10:57 am

I want to display customer's name in header of custom opencart theme of open cart version3.0

Newbie

Posts

Joined
Mon Sep 04, 2017 2:07 pm

Post by IP_CAM » Thu Sep 14, 2017 12:24 pm

Well, try this OcMod, it's untested, since I don't use this Version, but I cross-checked
the Content with an OC v.3.0.2.0, and it should work with a Default Theme.
Good Luck! ;)
Ernie

My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by askxah » Thu Mar 01, 2018 7:41 pm

Its Very Easy to Display Customer Name in Header. on (OPENCART 2.2.0)
Just add below code in catalog/controller/common/header.php

Code: Select all

 $data['firstname'] = $this->customer->getFirstName();
 $data['lastname'] = $this->customer->getLastName();
And add this code in template/common/header.tpl

Code: Select all

 
 <?php if ( $logged ) { ?>
 <span><?php echo $firstname; ?>&nbsp;<?php echo $lastname; ?></span>
 <?php } else { ?>
    <span>Sign/Register</span>
 <?php } ?>   
  

User avatar
Newbie

Posts

Joined
Sun Feb 04, 2018 4:06 pm
Who is online

Users browsing this forum: No registered users and 22 guests