谁能告诉我如何将客户的名字和姓氏放入 OpenCart 2.0 的标题中?
我已经将此代码用于 OpenCart 1.5.6:
<?php echo $this->customer->getFirstName(); ?>
<?php echo $this->customer->getLastName(); ?>
但此代码不适用于 OC 2.0
我收到此错误:Undefined property: Loader::$customer in header.tpl
请任何人帮助我。
谁能告诉我如何将客户的名字和姓氏放入 OpenCart 2.0 的标题中?
我已经将此代码用于 OpenCart 1.5.6:
<?php echo $this->customer->getFirstName(); ?>
<?php echo $this->customer->getLastName(); ?>
但此代码不适用于 OC 2.0
我收到此错误:Undefined property: Loader::$customer in header.tpl
请任何人帮助我。
要修复此错误,您需要在控制器而不是模板中调用它们。
在 catalog/controller/common/header.php 的 index() 函数中添加以下代码:
$data['customer_firstname'] = $this->customer->getFirstName();
$data['customer_lastname'] = $this->customer->getLastName();
在 catalog/view/theme/your-theme/template/common/header.tpl 你可以回显名字和姓氏:
echo $customer_firstname;
echo $customer_lastname;
请注意,最好不要编辑 Opencart 核心文件。相反,您可以使用 VQMod 来实现标头控制器中的更改。
嘿,我有一个解决方案来添加登录用户的名字姓氏:1.转到:catalog/controller/common/header.php
然后找到 public function index() {....
然后添加以下代码:
if ($this->customer->isLogged()) { $data['welcome_message'] = sprintf("Welcome %s %s,祝您住宿愉快!", $this->customer->getFirstName(), $this ->客户->getLastName()); }
现在转到:目录/视图/主题/YOURTHEME/template/common/header.tpl
然后把它放在你想要的地方: