dtc9222 2019-01-24 18:09
浏览 202
已采纳

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

I'm trying to change the behavior of a payment module in Prestashop 1.6.x, in order to create a customer receipt from the approval source to the order confirmation page.

I would like a suggestion concerning the best method and some guidance to achieve it a the correct way.

More specifically, when the user completes the transaction using a specific payment module, I need to populate the order confirmation page with POST data from the external banking source which is available in the postProcess() function, in order to use it as a kind of receipt.

As far as I can understand, after payment has been made:

  1. the module validates the order and elaborates the external source's POST data through a PostProcess() function (part of an extended ModuleFrontController class) and found in a controllers/front/validation.php file.

  2. Within PostProcess(), if external data is OK (i.e. transaction approved), it redirects to the order confirmation controller with the following:

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. At some point hookPaymentReturn() is being called (resided in the main module php file), which loads a specific module template file related to the order confirmation page.

  2. In order to show some variables through the tpl file, the only solution i've found is to use a smarty variable just before returning the populated tpl as shown below:

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');
    }

So my question is how can I populate $receipt_display with data from $somePostData as shown in the two above-mentioned code sections?

Is there a different methodology that you could suggest if the above-mentioned is wrong?

Thank you, mmystery

  • 写回答

1条回答 默认 最新

  • dougekui1518 2019-01-24 19:21
    关注

    It depends if $_POST['somePostData'] is just a simple string, if so, add it to Tools::redirect as next param in URL, if this is most complex data you have two options which i see:

    1. create some table with simple mapping: ps_yourpaymentmethod_data: id_order | data and get data by id in hookPaymentReturn

    2. set value in cookie:

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

    read it in hookPaymentReturn:

    if ($this->context->cookie->someVar) {
        $someVar = $this->context->cookie->someVar;
        $this->context->cookie->someVar = null;
        $this->context->cookie->write();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?