Skip to content
Snippets Groups Projects
Commit 4e64cf1a authored by Christel Loftus's avatar Christel Loftus
Browse files

test logging and rates endpoint on activation

parent 7b0e34e8
No related branches found
No related tags found
1 merge request!6Rates at checkout
Pipeline #65201 passed
...@@ -6,18 +6,22 @@ use Magento\Framework\Event\Observer; ...@@ -6,18 +6,22 @@ use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface; use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\HTTP\Client\Curl; use Magento\Framework\HTTP\Client\Curl;
use Psr\Log\LoggerInterface;
class ConfigChangeObserver implements ObserverInterface class ConfigChangeObserver implements ObserverInterface
{ {
protected $scopeConfig; protected $scopeConfig;
protected $curl; protected $curl;
protected $logger;
public function __construct( public function __construct(
ScopeConfigInterface $scopeConfig, ScopeConfigInterface $scopeConfig,
Curl $curl Curl $curl,
LoggerInterface $logger
) { ) {
$this->scopeConfig = $scopeConfig; $this->scopeConfig = $scopeConfig;
$this->curl = $curl; $this->curl = $curl;
$this->logger = $logger;
} }
public function execute(Observer $observer) public function execute(Observer $observer)
...@@ -93,6 +97,7 @@ class ConfigChangeObserver implements ObserverInterface ...@@ -93,6 +97,7 @@ class ConfigChangeObserver implements ObserverInterface
] ]
]); ]);
try {
// Set headers // Set headers
$this->curl->addHeader("Accept", "*/*"); $this->curl->addHeader("Accept", "*/*");
$this->curl->addHeader("Accept-Encoding", "deflate, gzip, br"); $this->curl->addHeader("Accept-Encoding", "deflate, gzip, br");
...@@ -106,9 +111,13 @@ class ConfigChangeObserver implements ObserverInterface ...@@ -106,9 +111,13 @@ class ConfigChangeObserver implements ObserverInterface
// Check response status // Check response status
if ($this->curl->getStatus() == 200) { if ($this->curl->getStatus() == 200) {
$response = $this->curl->getBody(); $response = $this->curl->getBody();
// Log response or take further actions $this->logger->info('Bob Go API response:', ['response' => $response]);
} else { } else {
// Handle error response $status = $this->curl->getStatus();
$this->logger->error('Bob Go API request failed.', ['status' => $status, 'url' => $url]);
}
} catch (\Exception $e) {
$this->logger->error('Bob Go API request error:', ['exception' => $e->getMessage()]);
} }
} }
} }
......
<?xml version="1.0"?> <?xml version="1.0"?>
<!--<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">-->
<!-- <type name="BobGroup\BobGo\Logger\Logger">-->
<!-- <arguments>-->
<!-- <argument name="name" xsi:type="string">bobgo</argument>-->
<!-- <argument name="handlers" xsi:type="array">-->
<!-- <item name="stream" xsi:type="object">BobGroup\BobGo\Logger\Handler</item>-->
<!-- </argument>-->
<!-- </arguments>-->
<!-- </type>-->
<!-- <type name="BobGroup\BobGo\Observer\ConfigChangeObserver">-->
<!-- <arguments>-->
<!-- <argument name="curl" xsi:type="object">Magento\Framework\HTTP\Client\Curl</argument>-->
<!-- </arguments>-->
<!-- </type>-->
<!--</config>-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="BobGroup\BobGo\Logger\Logger">
<arguments>
<argument name="name" xsi:type="string">bobgo</argument>
<argument name="handlers" xsi:type="array">
<item name="stream" xsi:type="object">BobGroup\BobGo\Logger\Handler</item>
</argument>
</arguments>
</type>
<type name="BobGroup\BobGo\Observer\ConfigChangeObserver"> <type name="BobGroup\BobGo\Observer\ConfigChangeObserver">
<arguments> <arguments>
<argument name="scopeConfig" xsi:type="object">Magento\Framework\App\Config\ScopeConfigInterface</argument>
<argument name="curl" xsi:type="object">Magento\Framework\HTTP\Client\Curl</argument> <argument name="curl" xsi:type="object">Magento\Framework\HTTP\Client\Curl</argument>
<argument name="logger" xsi:type="object">Psr\Log\LoggerInterface</argument>
</arguments> </arguments>
</type> </type>
</config> </config>
<?php <?php
return [ //return [
'backend' => [ // 'backend' => [
'frontName' => 'admin' // 'frontName' => 'admin'
], // ],
'install' => [ // 'install' => [
'date' => 'Wed, 15 Jan 2020 00:00:00 +0000' // 'date' => 'Wed, 15 Jan 2020 00:00:00 +0000'
], // ],
'system' => [ // 'system' => [
'default' => [ // 'default' => [
'dev' => [ // 'dev' => [
'log' => [ // 'log' => [
'active' => '1' // 'active' => '1'
] // ]
] // ]
] // ]
], // ],
// Other configurations... // // Other configurations...
]; //];
...@@ -18,12 +18,15 @@ ...@@ -18,12 +18,15 @@
<!-- </sequence>--> <!-- </sequence>-->
<!-- </module>--> <!-- </module>-->
<!--</config>--> <!--</config>-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="BobGroup_BobGo" setup_version="1.0.0"> <module name="BobGroup_BobGo" setup_version="1.0.0">
<sequence> <sequence>
<module name="Magento_Config"/>
<module name="Magento_Shipping"/> <module name="Magento_Shipping"/>
</sequence> </sequence>
</module> </module>
</config> </config>
...@@ -4,5 +4,3 @@ ...@@ -4,5 +4,3 @@
'BobGroup_BobGo', 'BobGroup_BobGo',
__DIR__ __DIR__
); );
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment