2017-09-29 2 views
0

私はopencartのカスタム支払い方法に取り組んでいます。私が必要とするのは、管理者から管理者に変更された注文履歴の変更を聞くことです。それは大丈夫でしたが、私が何をしていても、opencartのイベントトリガを働かせることができませんでした。ここでOpenCart addOrderHistoryイベントが動作しません

は、それが今のように見えるものです:

public function install() { 
    $this->load->model('extension/event'); 

    $this->model_extension_event->addEvent('delayed_payment_oh_add', 'catalog/model/checkout/order/addOrderHistory/after', 'admin/controller/extension/payment/delayed_payment/send_instructions'); 
    $this->model_extension_event->addEvent('delayed_payment_oh_api', 'catalog/controller/api/order/history/after', 'admin/controller/extension/payment/delayed_payment/send_instructions'); 
} 

public function uninstall() { 
    $this->load->model('extension/event'); 

    $this->model_extension_event->deleteEvent('delayed_payment_oh_add'); 
    $this->model_extension_event->deleteEvent('delayed_payment_oh_api'); 
} 

そして、リスナー自身:

public function send_instructions($route, $output, $order_id, $order_status_id) { 
    $this->load->model('checkout/order'); 

    $this->log->write(var_dump($output)); 
    echo var_dump($output); 

    $order_info = $this->model_checkout_order->getOrder($order_id); 

    if ($order_status_id == $this->config->get('delayed_payment_confirmed_order_status')) 
     $this->model_checkout_order->addOrderHistory(
      $order_id, 
      $this->config->get('delayed_payment_waiting_order_status'), 
      $this->config->get('delayed_payment_order_comment'), 
      true 
     ); 
} 

それは、ログまたは出力の両方には何も印刷されていません。 どのように動作させることができますか? (Opencart 2.3)

+0

send_instructions関数を含むファイルはどこですか?どのディレクトリに? – DigitCart

+0

@Mojtaba私はadmin(admin/controller/extension/payment/delayed_pa​​yment.php)とカタログコントローラ(catalog/controller/extension/payment/delayed_pa​​yment.php)の両方で、 –

答えて

0

私は間違いなくそれを作った! Opencart 2.3でイベントをデバッグする方法です。

まず、ファイル'system/engine/event.php'をご覧ください。このようなトリガー関数を変更するには、正確なイベントが呼び出されたことを記録する必要があります。それは私が見た最初の事は、そのイベント名はokですし

public function trigger($event, array $args = array()) { 
    // echo 'Event fired: '.var_dump($event); 
    $log = new Log('events.log'); 
    $log->write('Event fired: '.$event); 

    foreach ($this->data as $trigger => $actions) { 
     if (preg_match('/^' . str_replace(array('\*', '\?'), array('.*', '.'), preg_quote($trigger, '/')) . '/', $event)) { 
      foreach ($actions as $action) { 
       $result = $action->execute($this->registry, $args); 
       $log->write('Action executed: '.$action->getId()); 
       $log->write('Action result: '.$result); 

       if (!is_null($result) && !($result instanceof Exception)) { 
        return $result; 
       } 
      } 
     } 
    } 
} 

「システム/ストレージ/ログ/ events.log」を提出し、その結果をすべてのイベントとアクションを記録しますが、私は読むことができませんでした行動経路(経路)。だから私は、私のメソッドをインストール変更:

public function install() { 
    $this->load->model('extension/event'); 

    $this->model_extension_event->addEvent('delayed_payment_oh_add', 'catalog/model/checkout/order/addOrderHistory/after', 'extension/payment/delayed_payment/send_instructions'); 
} 

私は、パスを変更し、その私が、とにかく必要なものを達成するために必要ではない「の後/ API /オーダー/歴史」の行を削除...

を次に最も興味深いです

public function send($route, $output, $order_id, $order_status_id) 

それはcompletly間違ってはいけないが、一例として、それを使用します:一部では、バウチャー/総イベントコールバックに行く場合は、そのメソッド宣言が表示されますアップ ています!それを有効にすると、ログに「could not call ...」のような例外が表示されます。なぜなら、イベントメソッドは3つの引数をすべて受け取るためです。そして今私の機能は次のようになります(私の支払い方法のために):

public function send_instructions(&$route, &$data, &$output) 

$ルートと呼ばれる名前のルートです。 $ dataはイベント引数の配列です(0 => order_ir、2 => order_state_id e t.c)。必要に応じてafterメソッドの$ outputを削除することができます。通常はNULLです。個人的に私はそれを削除しました...

ここにあります!すべてうまく動作します。私はそれが誰かを助けて欲しいと思う:) event.phpのログを削除することを忘れないでください...

関連する問題