0

I am new to the Opencart and MVC model, Opencart has an event system that helps to take some action or trigger before or after any function in Opencart like order confirm and order status update.

I want to trigger the external PHP script when the order is confirmed. The external PHP script is located in a different server and different domain. I need any solution or extension.

Link like http:xxxx.xxx/opencart/order_confirm.php

Trigger : catalog/model/checkout/order/addOrderHistory/after
Action : admin/controller/extension/module/test_app.php

Here is my code :

<?php
$url = 'http://xxxxx.com/xxxx/xxx/xx/order_confirm.php';
$curl = curl_init();

curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'OpenCart Two Factor Authentication');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_FORBID_REUSE, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
//curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data));

$response = curl_exec($curl);

1 Answers1

0

If you are serving the external php string on another server as an HTTP callable, you can simply use php curl to send a request to that end point.

        $handler = curl_init(url);
        curl_setopt($handler, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($handler, CURLOPT_POSTFIELDS, array_of_parmameters);
        curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
        $response2 = curl_exec($handler);
        $response2 = json_decode($response2);
Amir Daneshkar
  • 771
  • 3
  • 9