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 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题