如何通过 hookPaymentReturn 将 POST 数据从 postProcess 填充到 smarty tpl

How to populate POST data from postProcess to smarty tpl via hookPaymentReturn

我正在尝试更改 Prestashop 1 中支付模块的行为。6.x,以便 创建客户收据 从批准源到 订单确认页面.

我想要有关最佳方法的建议和一些以正确方式实现它的指导。

更具体地说,当用户使用特定支付模块完成交易时,我需要使用来自外部银行来源的POST数据填充订单确认页面它在 postProcess() 函数中可用,以便 将其用作一种收据

据我了解,付款后:

  1. 模块通过 PostProcess() 函数(扩展 ModuleFrontController class 的一部分)验证顺序并详细说明外部源的 POST 数据并在 controllers/front/validation.php 文件中找到。

  2. PostProcess()内,如果外部数据正常(即交易已批准),它会重定向到订单确认控制器,内容如下:

public function postProcess() {

(...)

$somePostData = '';

//this is the variable that is populated from POST data and i need to show in the confirmation.tpl
$somePostData = Tools::getValue('postdata'); 

Tools::redirect('index.php?controller=order-confirmation&id_cart=' .
                    $this->context->cart->id . '&id_module=' .
                    $this->module->id . '&id_order=' .
                    $this->module->currentOrder . '&key=' .
                    $customer->secure_key
                );

(...)

}
  1. 在某个时候调用hookPaymentReturn()(驻留在主模块php文件中),它会加载与订单确认页面相关的特定模块模板文件。

  2. 为了通过 tpl 文件显示一些变量,我找到的唯一解决方案是在返回填充的 tpl 之前使用 smarty 变量如下图:

public function hookPaymentReturn()
    {
        if (!$this->active) {
            return;
        }

        //this is the variable that I want to populate from the above-mentioned $somePostData found in postProcess()
        $receipt_display = 'some data';

        $this->context->smarty->assign('receipt_display', $receipt_display);

        return $this->display(__FILE__, 'views/templates/hook/confirmation.tpl');
    }

所以我的问题是如何使用上述两个代码部分中所示的 $somePostData 中的数据填充 $receipt_display?

如果上述方法有误,您是否可以建议其他方法?

谢谢, 谜底

这取决于 $_POST['somePostData'] 是否只是一个简单的字符串,如果是,将其添加到 Tools::redirect 作为 URL 中的下一个参数,如果这是最复杂的数据我看到你有两个选择:

  1. 用简单的映射创建一些 table:ps_yourpaymentmethod_data:id_order |数据并通过id在hookPaymentReturn

  2. 中获取数据
  3. 在 cookie 中设置值:

$this->context->cookie->someVar = Tools::getValue('postData'); $this->context->cookie->write();

阅读 hookPaymentReturn:

if ($this->context->cookie->someVar) {
    $someVar = $this->context->cookie->someVar;
    $this->context->cookie->someVar = null;
    $this->context->cookie->write();
}