how to put opencart 2.0 customer first name and last name on header?

坚强是说给别人听的谎言 提交于 2019-12-08 10:08:12

问题


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 :



来源:https://stackoverflow.com/questions/27430280/how-to-put-opencart-2-0-customer-first-name-and-last-name-on-header

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!