Using OpenCart 2.0. How do I display customers email on a category page?

允我心安 提交于 2019-12-11 19:31:19

问题


I'm using OpenCart 2.0 and I'm trying to show a user email on a category page when a user is logged in. The code below I believe works for it to show a users email on the success.tpl. How can I display it on a category page? Thanks for your time.

IN: /catalog/controller/product/category.php

I HAVE THIS:

 $this->load->model('account/order');
    $order = $this->model_account_order->getOrder($this->session->data['order_id']);
    if($order) {
        $this->data['email'] = $order['email'];
    }

THEN IN:/catalog/view/theme/default/template/category.tpl

I HAVE THIS:

<?php if(!empty($email)) echo $email; ?>

回答1:


This is part of the core library. You don't need to look up an order if they're logged in, you just need to use

$this->customer->getEmail();

Note that in 2.0 you can't just echo this in a template, you need to assign this in the controller to the $data array and then use the value in the template. A quick hack to just add it to the template is to use

<?php
global $customer;
echo $customer->getEmail();
?>

but really isn't recommended



来源:https://stackoverflow.com/questions/27158891/using-opencart-2-0-how-do-i-display-customers-email-on-a-category-page

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