2016-08-10 102 views
0

Prestashop 1.6.1.6需要在支付鉤子中進行一些API調用。但是由於某些原因,鉤子沒有觸發,並且hookPayment方法沒有執行。當與具有hookPayment的PayPal模塊比較時,該鉤子被執行。我做錯了什麼?Prestashop模塊支付鉤不觸發

模塊代碼儘可能

<?php 

如果(定義( '_ PS_VERSION_')!) 出口一樣簡單;

類TestModule擴展模塊{

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) 

回答

2

你在你的函數名做了一個錯字被註冊,它說public function hoolPayment($params),而應該是public function hookPayment($params)

+0

很好的回答!修正了錯字並重新設置了模塊,但仍然沒有任何結果。我以前玩過沒有輸入錯誤 –

+0

你是如何檢查它是否進入鉤子? (你記錄它到一個文件,或只是做一個死亡()) –

+0

ddd($ params);在貝寶模塊打印噸的變量值。在我的測試模塊中,它不打印任何東西 –

2

PrestaShop模塊在安裝過程中需要擴展PaymentModule才能觸發支付鉤子。只是改變延伸或重置不會有幫助。