how to put opencart 2.0 customer first name and la

2019-06-14 04:39发布

问题:

Can anyone please tell me how to put customer's first and last name into the header in OpenCart 2.0?

I am already using this code for OpenCart 1.5.6:

<?php echo $this->customer->getFirstName(); ?>
<?php echo $this->customer->getLastName(); ?>

But this code is not working for OC 2.0

I am getting this error : Undefined property: Loader::$customer in header.tpl

Please help me anyone.

回答1:

To fix this error you need to call them in the controller instead of in the template.

In catalog/controller/common/header.php add the following code inside the index() function:

$data['customer_firstname'] = $this->customer->getFirstName();
$data['customer_lastname'] = $this->customer->getLastName();

In catalog/view/theme/your-theme/template/common/header.tpl you can echo the first and last name:

echo $customer_firstname;
echo $customer_lastname;

Note that it is better not to edit Opencart core files. Instead you can use VQMod to implement the changes in the header controller.



回答2:

Hey I had a solution to add first name last name of logged in user : 1.Go To: catalog/controller/common/header.php

  1. Then find public function index () {....

  2. Then add the following code:

if ($this->customer->isLogged()) { $data['welcome_message'] = sprintf("Welcome %s %s, Enjoy your stay!", $this->customer->getFirstName(), $this->customer->getLastName()); }

  1. Now go to : catalog/view/theme/YOURTHEME/template/common/header.tpl

  2. then put this where you want :



标签: opencart2.x