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
Branches
Tags 1.0.16
1 merge request!6Rates at checkout
Pipeline #65201 passed
......@@ -1309,7 +1309,7 @@ class BobGo extends AbstractCarrierOnline implements CarrierInterface
{
return [$this->_code => $this->getConfigData('name')];
}
}
......
......@@ -6,18 +6,22 @@ use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\HTTP\Client\Curl;
use Psr\Log\LoggerInterface;
class ConfigChangeObserver implements ObserverInterface
{
protected $scopeConfig;
protected $curl;
protected $logger;
public function __construct(
ScopeConfigInterface $scopeConfig,
Curl $curl
Curl $curl,
LoggerInterface $logger
) {
$this->scopeConfig = $scopeConfig;
$this->curl = $curl;
$this->logger = $logger;
}
public function execute(Observer $observer)
......@@ -93,22 +97,27 @@ class ConfigChangeObserver implements ObserverInterface
]
]);
// Set headers
$this->curl->addHeader("Accept", "*/*");
$this->curl->addHeader("Accept-Encoding", "deflate, gzip, br");
$this->curl->addHeader("Content-Type", "application/json; charset=utf-8");
$this->curl->addHeader("Host", "api.dev.bobgo.co.za");
$this->curl->addHeader("User-Agent", "Magento/2.x");
try {
// Set headers
$this->curl->addHeader("Accept", "*/*");
$this->curl->addHeader("Accept-Encoding", "deflate, gzip, br");
$this->curl->addHeader("Content-Type", "application/json; charset=utf-8");
$this->curl->addHeader("Host", "api.dev.bobgo.co.za");
$this->curl->addHeader("User-Agent", "Magento/2.x");
// Send the request
$this->curl->post($url, $payload);
// Send the request
$this->curl->post($url, $payload);
// Check response status
if ($this->curl->getStatus() == 200) {
$response = $this->curl->getBody();
// Log response or take further actions
} else {
// Handle error response
// Check response status
if ($this->curl->getStatus() == 200) {
$response = $this->curl->getBody();
$this->logger->info('Bob Go API response:', ['response' => $response]);
} else {
$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"?>
<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 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">
<type name="BobGroup\BobGo\Observer\ConfigChangeObserver">
<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="logger" xsi:type="object">Psr\Log\LoggerInterface</argument>
</arguments>
</type>
</config>
<?php
return [
'backend' => [
'frontName' => 'admin'
],
'install' => [
'date' => 'Wed, 15 Jan 2020 00:00:00 +0000'
],
'system' => [
'default' => [
'dev' => [
'log' => [
'active' => '1'
]
]
]
],
// Other configurations...
];
//return [
// 'backend' => [
// 'frontName' => 'admin'
// ],
// 'install' => [
// 'date' => 'Wed, 15 Jan 2020 00:00:00 +0000'
// ],
// 'system' => [
// 'default' => [
// 'dev' => [
// 'log' => [
// 'active' => '1'
// ]
// ]
// ]
// ],
// // Other configurations...
//];
......@@ -18,12 +18,15 @@
<!-- </sequence>-->
<!-- </module>-->
<!--</config>-->
<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">
<sequence>
<module name="Magento_Shipping"/>
</sequence>
</module>
<module name="BobGroup_BobGo" setup_version="1.0.0">
<sequence>
<module name="Magento_Config"/>
<module name="Magento_Shipping"/>
</sequence>
</module>
</config>
......@@ -4,5 +4,3 @@
'BobGroup_BobGo',
__DIR__
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment