how to put opencart 2.0 customer first name and la

2019-06-14 04:23发布

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.

标签: opencart2.x
2条回答
老娘就宠你
2楼-- · 2019-06-14 04:41

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.

查看更多
\"骚年 ilove
3楼-- · 2019-06-14 04:52

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 :

查看更多
登录 后发表回答