问题描述
有人可以告诉我如何在OpenCart 2.0的标题中添加客户的名字和姓氏吗?
Can anyone please tell me how to put customer's first and last name into the header in OpenCart 2.0?
我已经在OpenCart 1.5.6中使用此代码:
I am already using this code for OpenCart 1.5.6:
<?php echo $this->customer->getFirstName(); ?>
<?php echo $this->customer->getLastName(); ?>
但是此代码不适用于OC 2.0
But this code is not working for OC 2.0
我收到此错误:Undefined property: Loader::$customer in header.tpl
请帮助我任何人.
推荐答案
要解决此错误,您需要在控制器中而不是模板中调用它们.
To fix this error you need to call them in the controller instead of in the template.
在catalog/controller/common/header.php中,在index()函数内添加以下代码:
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();
在catalog/view/theme/your-theme/template/common/header.tpl中,您可以呼应名字和姓氏:
In catalog/view/theme/your-theme/template/common/header.tpl you can echo the first and last name:
echo $customer_firstname;
echo $customer_lastname;
请注意,最好不要编辑Opencart核心文件.相反,您可以使用VQMod在标头控制器中实现更改.
Note that it is better not to edit Opencart core files. Instead you can use VQMod to implement the changes in the header controller.
这篇关于如何在标题上放置opencart 2.0客户的名字和姓氏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!