From aa96af66a4850c0b1608bbb8e1977e8147cc1208 Mon Sep 17 00:00:00 2001 From: Sander Lissenburg Date: Tue, 3 May 2022 08:16:32 +0200 Subject: [PATCH 1/3] To prevent using headers and options from a previous request override all headers and options --- Observer/SendWebhook.php | 10 ++++++++-- composer.json | 2 +- etc/module.xml | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Observer/SendWebhook.php b/Observer/SendWebhook.php index 94f9e84..750be0c 100644 --- a/Observer/SendWebhook.php +++ b/Observer/SendWebhook.php @@ -40,8 +40,14 @@ public function execute(\Magento\Framework\Event\Observer $observer) $orderData['increment_id'] = $order->getIncrementId(); $orderData['picqer_magento_key'] = $magentoKey; - $this->_curl->addHeader("Content-Type", "application/json"); - $this->_curl->setTimeout(2); // in seconds + $this->_curl->setHeaders( + 'Content-Type', 'application/json' + ); + + $this->_curl->setOptions([ + CURLOPT_TIMEOUT => 30 // in seconds + ]); + try { $this->_curl->post(sprintf('https://%s.picqer.com/webshops/magento2/orderPush/%s', trim($subDomain), trim($magentoKey)), json_encode($orderData)); } catch (\Exception $e) { diff --git a/composer.json b/composer.json index 8491269..1070e77 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "picqer/magento2-plugin", "description": "Picqer Extended Integration for Magento 2", - "version": "1.0.2", + "version": "1.0.3", "type": "magento2-module", "keywords": [ "picqer", diff --git a/etc/module.xml b/etc/module.xml index 42f4e5d..296850c 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - + From 02c92e82219f9a9e40f731e31c9199e535484cbc Mon Sep 17 00:00:00 2001 From: Sander Lissenburg Date: Tue, 3 May 2022 08:29:07 +0200 Subject: [PATCH 2/3] Set timeout to 2 seconds --- Observer/SendWebhook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Observer/SendWebhook.php b/Observer/SendWebhook.php index 750be0c..1c19d8f 100644 --- a/Observer/SendWebhook.php +++ b/Observer/SendWebhook.php @@ -45,7 +45,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) ); $this->_curl->setOptions([ - CURLOPT_TIMEOUT => 30 // in seconds + CURLOPT_TIMEOUT => 2 // in seconds ]); try { From 25c2ae1de7b36d10cf84d98b4f0ca278ec5ea62f Mon Sep 17 00:00:00 2001 From: Sander Lissenburg Date: Tue, 3 May 2022 09:10:11 +0200 Subject: [PATCH 3/3] Array instead of params to setHeaders --- Observer/SendWebhook.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Observer/SendWebhook.php b/Observer/SendWebhook.php index 1c19d8f..df56001 100644 --- a/Observer/SendWebhook.php +++ b/Observer/SendWebhook.php @@ -40,9 +40,9 @@ public function execute(\Magento\Framework\Event\Observer $observer) $orderData['increment_id'] = $order->getIncrementId(); $orderData['picqer_magento_key'] = $magentoKey; - $this->_curl->setHeaders( - 'Content-Type', 'application/json' - ); + $this->_curl->setHeaders([ + 'Content-Type' => 'application/json' + ]); $this->_curl->setOptions([ CURLOPT_TIMEOUT => 2 // in seconds