在Opencart 2上的header.tpl中显示客户ID

时间:2016-06-15 11:35:47

标签: opencart opencart2.x opencart-module

如何在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
    }

不起作用。

1 个答案:

答案 0 :(得分:3)

在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上测试