我已经能够通过在{{3}中应用Shadyyx的非常有用的建议(谢谢!)来获取order_id和总订单值以在OpenCart(v.1.5.4)的成功页面上处理它们}。但是,我无法获得(注册或客户)客户的电子邮件地址,即:
如果我在$this->data['email'] = $this->session->data ['email'];
$this->cart->clear();
我在提交订单时在success.php中收到未定义的索引错误。
如果我插入$this->data['email'] = $this->cart->getEmail();
相反,我避免了未定义的索引错误,但仍然没有通过输入标记在html表单中加载电子邮件地址(但这适用于order_id和total),如下所示:
<?php if(!empty($email)): ?
&GT;
<input name="email" type="hidden" value="<?php echo $email ?>">
<?php endif; ?>
答案 0 :(得分:3)
要正确执行此操作,您需要打开/catalog/controller/checkout/success.php
并找到此行代码
if (isset($this->session->data['order_id'])) {
之后,添加以下
$this->load->model('account/order');
$order = $this->model_account_order->getOrder($this->session->data['order_id']);
if($order) {
$this->data['email'] = $order['email'];
}
在您的模板/catalog/view/theme/your-theme-name/template/common/success.tpl
中,您需要输入
<?php if(!empty($email)) echo $email; ?>
您想要查看电子邮件地址的地方
答案 1 :(得分:0)
$this->customer->getEmail();
- 这会让您登录客户的电子邮件ID。
在catalog/controller/checkout/success.php
中,在
if (isset($this->session->data['order_id'])) {
和
$this->cart->clear();
要添加的代码:
if (isset($this->session->data['guest'])) {
$this->data['customer_email'] = $this->session->data['guest']['email']; // Guest user's email
} elseif($this->customer->isLogged()) {
$this->data['customer_email'] = $this->customer->getEmail(); // Customer's email
}
然后在success.tpl中添加:
<?php if(isset($customer_email)){ ?>
<input name="email" type="hidden" value="<?php echo $customer_email ?>">
<?php } ?>