【问题标题】:Prestashop module payment hook not triggeringPrestashop 模块支付挂钩未触发
【发布时间】:2016-08-10 13:31:21
【问题描述】:

Prestashop 1.6.1.6 需要在支付挂钩中进行一些 API 调用。但是由于某种原因,钩子没有触发并且 hookPayment 方法没有执行。当与也具有 hookPayment 的 Paypal 模块进行比较时,会执行此钩子。我做错了什么?

模块代码尽可能简单

<?php

if (!defined('_PS_VERSION_'))
    exit;

class TestModule extends Module
{

    public function __construct()
    {
        $this->name = 'testmodule';
        $this->tab = 'shipping_logistics';
        $this->version = '1.0.0';
        $this->author = 'Firstname Lastname';
        $this->need_instance = 0;
        $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->l('Test Module');
        $this->description = $this->l('Description of my module.');

        $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
    }

    public function install()
    {
        if (!parent::install() || !$this->registerHook('payment'))
            return false;
        return true;
    }

    public function uninstall()
    {
        if (!parent::uninstall())
            return false;
        return true;
    }

    public function hookPayment($params)
    {
        ddd($params);
    }
}

安装钩子后注册到数据库中

mysql> select * from module where id_module=75;
+-----------+------------+--------+---------+
| id_module | name       | active | version |
+-----------+------------+--------+---------+
|        75 | testmodule |      1 | 1.0.0   |
+-----------+------------+--------+---------+
1 row in set (0,00 sec)

mysql> select * from hook_module where id_module=75;
+-----------+---------+---------+----------+
| id_module | id_shop | id_hook | position |
+-----------+---------+---------+----------+
|        75 |       1 |       1 |        4 |
+-----------+---------+---------+----------+
1 row in set (0,00 sec)

mysql> select * from hook where id_hook=1;
+---------+----------------+---------+-----------------------------------------------------+----------+-----------+
| id_hook | name           | title   | description                                         | position | live_edit |
+---------+----------------+---------+-----------------------------------------------------+----------+-----------+
|       1 | displayPayment | Payment | This hook displays new elements on the payment page |        1 |         1 |
+---------+----------------+---------+-----------------------------------------------------+----------+-----------+
1 row in set (0,00 sec)

【问题讨论】:

    标签: php module prestashop payment prestashop-1.6


    【解决方案1】:

    你的函数名打错了,它是public function hoolPayment($params),但应该是public function hookPayment($params)

    【讨论】:

    • 很好的答案!修正了错字并重置了模块,但仍然没有。我以前玩过也没有错别字
    • 你如何检查它是否进入了钩子? (你是把它记录到一个文件中,还是只是做一个 die() )
    • ddd($params);在 paypal 模块中打印大量变量值。在我的测试模块中它不打印任何东西
    • 你确定你没有任何其他的模块挂在这上面,那就是在你的模块之前死掉?您可以在后端验证这一点(转到模块 -> 职位 -> 搜索付款)。
    • 是的,我确定。经过更多研究和阅读代码后,我找到了答案。我也发帖给别人看。
    【解决方案2】:

    PrestaShop 模块需要在安装期间扩展 PaymentModule 才能触发支付挂钩。仅更改扩展或重置无济于事。

    【讨论】:

      猜你喜欢
      • 2021-06-13
      • 2015-02-12
      • 1970-01-01
      • 1970-01-01
      • 2021-06-29
      • 1970-01-01
      • 1970-01-01
      • 2018-06-29
      • 1970-01-01
      相关资源
      最近更新 更多