2017-02-14 55 views
0

我創造了這個測試功能(可以稱之爲ABtest.php)發送測試消息:是否可以通過鉤子在Prestashop中執行一個函數而不創建模塊?

$host = "http://localhost:8080"; 
$id = "123"; 
$email = "[email protected]"; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_USERPWD, "mine.mail:mypassword"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_HTTPAUTH, TRUE); 

function send($host,$id,$email,$ch){ 
    curl_setopt($ch, CURLOPT_URL, $host . "/c/" . $id . "/your ID/"); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, "to=" . $email . "&subject=Your ID "); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); 

    $output = curl_exec($ch); 

    if (curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200 && curl_getinfo($ch, CURLINFO_HTTP_CODE) != 201) { 
     printf("An error occured (HTTP %d): %sn", curl_getinfo($ch, CURLINFO_HTTP_CODE), $output); 
    } else { 
     printf("Success"); 
    } 
} 

我想這個代碼放到我的鉤hookValidateOrder($params)這樣的:

public function hookValidateOrder($params) 
{ 
    $id = $params['cart']->id; 
    $host = "http://localhost:8080"; 
    $email = "[email protected]"; 

    // + the rest of my PHP function - see the 1st code block above  
} 

問題是我真的不知道在哪裏放置我的代碼。正如你可以看到我沒有創建一個模塊,我只想通過hookValidateOrder($params)掛鉤來執行我的PHP函數。

這是可能的,我在哪裏放置它?

回答

0

我不這麼認爲。不正確的方式。 但是你可以創建一個覆蓋,在覆蓋文件夾PaymentModule.php:

abstract class PaymentModule extends PaymentModuleCore 
{ 
    public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown', $message = null, $extra_vars = array(), $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null) 
    { 
      // do what you need before 

      parent::validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method, $message, $extra_vars, $currency_special, $dont_touch_amount, $secure_key, $shop); 

     // do what you need after 
    } 
} 

您也可以覆蓋任何模塊做,或鉤exec和檢查,如果它試圖執行hookValidateOrder那麼你放置你的代碼。

如果您確實創建了覆蓋,請不要忘記在刪除(或重命名)文件緩存/ class_index.php之後,爲您的新覆蓋編制索引。

相關問題