在 Opencart 2 的 header.tpl 中显示客户 ID
Show customer id in header.tpl on Opencart 2
如何在 Opencart 2 header.tpl 中显示客户 ID?
if ($this->customer->isLogged()) {
$data['customer_id'] = $this->customer->getId(); // customer ID
$data['customer_fname'] = $this->customer->getFirstName(); // customer email
}
不起作用。
在header.php文件中添加这两个变量
if ($this->customer->isLogged()) { // <-- This line is around 52
$this->load->model('account/wishlist');
$data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), $this->model_account_wishlist->getTotalWishlist());
$data['customer_id'] = $this->customer->getId(); // <-- add this variable
$data['customer_fname'] = $this->customer->getFirstName(); // <-- and this variable
} else {
$data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));
}
在 header.tpl 文件中你可以像这样使用变量,必须在 if ($logged)
块中
<?php if ($logged) { ?>
<?php echo $customer_id; ?>
<?php echo $customer_fname; ?>
<?php } ?>
在 OC 2.2.0.0 上测试
如何在 Opencart 2 header.tpl 中显示客户 ID?
if ($this->customer->isLogged()) {
$data['customer_id'] = $this->customer->getId(); // customer ID
$data['customer_fname'] = $this->customer->getFirstName(); // customer email
}
不起作用。
在header.php文件中添加这两个变量
if ($this->customer->isLogged()) { // <-- This line is around 52
$this->load->model('account/wishlist');
$data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), $this->model_account_wishlist->getTotalWishlist());
$data['customer_id'] = $this->customer->getId(); // <-- add this variable
$data['customer_fname'] = $this->customer->getFirstName(); // <-- and this variable
} else {
$data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));
}
在 header.tpl 文件中你可以像这样使用变量,必须在 if ($logged)
块中
<?php if ($logged) { ?>
<?php echo $customer_id; ?>
<?php echo $customer_fname; ?>
<?php } ?>
在 OC 2.2.0.0 上测试