【问题标题】:Getting the customer email address to success.tpl in OpenCart将客户电子邮件地址获取到 OpenCart 中的 success.tpl
【发布时间】:2013-12-03 17:21:58
【问题描述】:

通过在Opencart successful order ID and Total from JavaScript 中应用 Shadyyx 的非常有用的建议(谢谢!),我已经能够在 OpenCart(v.1.5.4)的成功页面上获取 order_id 和总订单价值来处理它们。但是,我无法获取(注册或访客)客户的电子邮件地址,即:

如果我在$this->cart->clear();之前的success.php中插入$this->data['email'] = $this->session->data ['email'];

提交订单时,success.php 中出现未定义索引错误。

如果我插入$this->data['email'] = $this->cart->getEmail();

相反,我避免了未定义索引错误,但电子邮件地址仍然没有通过输入标签加载到 html 表单中(但这确实适用于 order_id 和总数),如下所示:

<?php if(!empty($email)): ?> <input name="email" type="hidden" value="<?php echo $email ?>"> <?php endif; ?>

【问题讨论】:

    标签: email variables opencart


    【解决方案1】:

    要正确执行此操作,您需要打开 /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; ?>
    

    无论您想在哪里查看电子邮件地址

    【讨论】:

      【解决方案2】:

      $this-&gt;customer-&gt;getEmail(); - 这将使您登录客户的电子邮件 ID。

      catalog/controller/checkout/success.php,在

      之间插入以下代码

      if (isset($this-&gt;session-&gt;data['order_id'])) {

      $this-&gt;cart-&gt;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 } ?>
      

      【讨论】:

      • 非常感谢您的快速回复!几乎完美!您的解决方案非常适用于客户电子邮件,但对访客电子邮件没有任何价值。可能是访客电子邮件的变量名称不同吗?在success.php 中处理表单中的电子邮件地址(无论是客人还是客户)的相关3 行是: '' '' ''
      猜你喜欢
      • 2014-12-01
      • 1970-01-01
      • 2016-06-11
      • 2020-10-31
      • 1970-01-01
      • 2021-12-28
      • 2013-06-02
      • 1970-01-01
      • 2012-11-10
      相关资源
      最近更新 更多