A
A
Akmal Islamov2020-03-02 10:59:40
opencart
Akmal Islamov, 2020-03-02 10:59:40

How to display the buyer's name on the header in Opencart?

Good afternoon, gentlemen,
I was given the task to display the name and surname of an authorized user in a certain place on the header. I googled and many times. Found different ways, tried them and nothing worked.
I in one of the solutions it was said like this:
In the header.php in the folder along the path opencart/catalog/controller/common/ and add the lines:

$data['firstname'] = $this->customer->getFirstName();
      $data['lastname'] = $this->customer->getLastName();

And in header.tpl along the path opencart/catalog/view/theme/mytheme/template/common/
<?php echo $firstname; ?>
      <?php echo $lastname; ?>

That's exactly what I did. The server responds that the variables are undefined. Maybe these lines need to be written somewhere else.
Please advise gentlemen.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
liza2019, 2020-03-03
@liza2019

check first in the controller whether the variables are defined or not
above this line
$data['firstname'] = $this->customer->getFirstName();
to be sure, check also $this->customer->getId()
write down

echo $this->customer->isLogged()."-".$this->customer->getId()."-".$this->customer->getFirstName()."-".$this->customer->getLastName(); exit;

more than sure that it will give out emptiness, most likely you are checking without logging in as a buyer.
I would write in the controller like this to be sure
if ($this->customer->isLogged()) {
$data['firstname'] = $this->customer->getFirstName();
$data['lastname'] = $this->customer->getLastName();
} else {
$data['firstname'] = '';
$data['lastname'] = '';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question