Skip to content

Commit b8fa468

Browse files
Merge pull request #5 from picqer/dont-break-shop
Do not break webshop when Picqer is not reachable
2 parents 00df7ba + 1d19eb1 commit b8fa468

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Observer/SendWebhook.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ class SendWebhook implements ObserverInterface
88
{
99
protected $_scopeConfig;
1010
protected $_curl;
11+
protected $_logger;
1112

1213
public function __construct(
1314
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
14-
\Magento\Framework\HTTP\Client\Curl $curl
15+
\Magento\Framework\HTTP\Client\Curl $curl,
16+
\Psr\Log\LoggerInterface $logger
1517
) {
1618
$this->_scopeConfig = $scopeConfig;
1719
$this->_curl = $curl;
20+
$this->_logger = $logger;
1821
}
1922

2023
public function execute(\Magento\Framework\Event\Observer $observer)
@@ -38,6 +41,11 @@ public function execute(\Magento\Framework\Event\Observer $observer)
3841
$orderData['picqer_magento_key'] = $magentoKey;
3942

4043
$this->_curl->addHeader("Content-Type", "application/json");
41-
$this->_curl->post('https://' . $subDomain . '.picqer.com/webshops/magento2/orderPush/' . $magentoKey, json_encode($orderData));
44+
$this->_curl->setTimeout(2); // in seconds
45+
try {
46+
$this->_curl->post(sprintf('https://%s.picqer.com/webshops/magento2/orderPush/%s', trim($subDomain), trim($magentoKey)), json_encode($orderData));
47+
} catch (\Exception $e) {
48+
$this->_logger->debug(sprintf('Exception occurred with Picqer: %s', $e->getMessage()));
49+
}
4250
}
4351
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "picqer/magento2-plugin",
33
"description": "Picqer Extended Integration for Magento 2",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"type": "magento2-module",
66
"keywords": [
77
"picqer",

etc/module.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Picqer_Integration" setup_version="1.0.1">
3+
<module name="Picqer_Integration" setup_version="1.0.2">
44
<sequence>
55
<module name="Magento_Webapi" />
66
</sequence>
77
</module>
8-
</config>
8+
</config>

0 commit comments

Comments
 (0)