0

I cant understand Opencart event system. For example, I want to push order to external CRM, which have own API. I wrote in file /admin/controller/extension/module/mykmykpet_bitrix24.php next code:

class ControllerExtensionModuleMykmykpetBitrix24 extends Controller{
    public function install(){
        $this->load->model('extension/event');
        $this->model_extension_event->addEvent('Bitrix24','catalog/model/checkout/order/addOrder/after','extension/module/mykmykpet_bitrix24/newOrderToCRM');
    }

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

Next, for training I wrote in /catalog/controller/extension/module/mykmykpet_bitrix24.php next code:

class ControllerExtensionModuleMykmykpetBitrix24 extends Controller{
    public function newOrderToCRM($orderID){
        mail("mykmykpet@mykmykpet.xyz","Hello from OpenCart Event",$orderID);
    }    
}

Next, I place test order and got this e-mail: E-mail content

But why I got that? I wait an order identificator, but not path to method I used. Where is my mistake? Help me, please.

DigitCart
  • 2,980
  • 2
  • 18
  • 28
Mykola Petiukh
  • 319
  • 1
  • 10

2 Answers2

0

You will have to look in $this->request for order_id, but I'm sure it will be in there somewhere. It won't be passed as a parameter by the event system.

Scott C Wilson
  • 19,102
  • 10
  • 61
  • 83
0

OpenCart 2.3.0.2

In your example order_id is in the third parameter. you can test it with your log:

public function newOrderToCRM($route = false, $order_info = false, $order_id = false){
    $this->log->write('Route: ' . $route);
    $this->log->write('Order Info: ');
    $this->log->write($order_info);
    $this->log->write('Order ID: ' . $order_id);
}

Place an order and then check your error log, This is the result for me:

2018-01-05 17:04:17 - Route: checkout/order/addOrder

2018-01-05 17:04:17 - Order Info: 2018-01-05 17:04:17 - Array(Order information inside array)

2018-01-05 17:04:17 - Order ID: 130

DigitCart
  • 2,980
  • 2
  • 18
  • 28