Skip to content

Commit

Permalink
Merge pull request #5 from picqer/dont-break-shop
Browse files Browse the repository at this point in the history
Do not break webshop when Picqer is not reachable
  • Loading branch information
annajeanine authored Jul 20, 2021
2 parents 00df7ba + 1d19eb1 commit b8fa468
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions Observer/SendWebhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ class SendWebhook implements ObserverInterface
{
protected $_scopeConfig;
protected $_curl;
protected $_logger;

public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\HTTP\Client\Curl $curl
\Magento\Framework\HTTP\Client\Curl $curl,
\Psr\Log\LoggerInterface $logger
) {
$this->_scopeConfig = $scopeConfig;
$this->_curl = $curl;
$this->_logger = $logger;
}

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

$this->_curl->addHeader("Content-Type", "application/json");
$this->_curl->post('https://' . $subDomain . '.picqer.com/webshops/magento2/orderPush/' . $magentoKey, json_encode($orderData));
$this->_curl->setTimeout(2); // 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) {
$this->_logger->debug(sprintf('Exception occurred with Picqer: %s', $e->getMessage()));
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "picqer/magento2-plugin",
"description": "Picqer Extended Integration for Magento 2",
"version": "1.0.1",
"version": "1.0.2",
"type": "magento2-module",
"keywords": [
"picqer",
Expand Down
4 changes: 2 additions & 2 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Picqer_Integration" setup_version="1.0.1">
<module name="Picqer_Integration" setup_version="1.0.2">
<sequence>
<module name="Magento_Webapi" />
</sequence>
</module>
</config>
</config>

0 comments on commit b8fa468

Please sign in to comment.