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

Add logging for rates at checkout

parent 9be7ff11
No related branches found
No related tags found
1 merge request!6Rates at checkout
Pipeline #64959 passed
...@@ -1179,6 +1179,7 @@ ...@@ -1179,6 +1179,7 @@
//} //}
<?php
namespace BobGroup\BobGo\Model\Carrier; namespace BobGroup\BobGo\Model\Carrier;
use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Config\ScopeConfigInterface;
...@@ -1204,8 +1205,7 @@ class BobGo extends AbstractCarrierOnline implements CarrierInterface ...@@ -1204,8 +1205,7 @@ class BobGo extends AbstractCarrierOnline implements CarrierInterface
LoggerInterface $logger, LoggerInterface $logger,
ZendClientFactory $httpClientFactory, ZendClientFactory $httpClientFactory,
array $data = [] array $data = []
) ) {
{
$this->scopeConfig = $scopeConfig; $this->scopeConfig = $scopeConfig;
$this->httpClientFactory = $httpClientFactory; $this->httpClientFactory = $httpClientFactory;
$this->logger = $logger; $this->logger = $logger;
...@@ -1214,10 +1214,15 @@ class BobGo extends AbstractCarrierOnline implements CarrierInterface ...@@ -1214,10 +1214,15 @@ class BobGo extends AbstractCarrierOnline implements CarrierInterface
public function collectRates(RateRequest $request) public function collectRates(RateRequest $request)
{ {
$this->logger->info('BobGo collectRates method called');
if (!$this->getConfigFlag('active')) { if (!$this->getConfigFlag('active')) {
$this->logger->info('BobGo is not active');
return false; return false;
} }
$this->logger->info('BobGo is active, proceeding with rate collection');
$result = $this->_rateFactory->create(); $result = $this->_rateFactory->create();
// Prepare request data for API call // Prepare request data for API call
...@@ -1230,8 +1235,12 @@ class BobGo extends AbstractCarrierOnline implements CarrierInterface ...@@ -1230,8 +1235,12 @@ class BobGo extends AbstractCarrierOnline implements CarrierInterface
'package_qty' => $request->getPackageQty(), 'package_qty' => $request->getPackageQty(),
]; ];
$this->logger->info('Request parameters: ' . json_encode($params));
try { try {
$apiResponse = $this->_fetchRatesFromApi($params); $apiResponse = $this->_fetchRatesFromApi($params);
$this->logger->info('API response: ' . json_encode($apiResponse));
if ($apiResponse && isset($apiResponse['rates']) && !empty($apiResponse['rates'])) { if ($apiResponse && isset($apiResponse['rates']) && !empty($apiResponse['rates'])) {
foreach ($apiResponse['rates'] as $rateData) { foreach ($apiResponse['rates'] as $rateData) {
$rate = $this->_rateMethodFactory->create(); $rate = $this->_rateMethodFactory->create();
...@@ -1244,6 +1253,7 @@ class BobGo extends AbstractCarrierOnline implements CarrierInterface ...@@ -1244,6 +1253,7 @@ class BobGo extends AbstractCarrierOnline implements CarrierInterface
$result->append($rate); $result->append($rate);
} }
} else { } else {
$this->logger->info('No rates returned from API');
$error = $this->_rateErrorFactory->create(); $error = $this->_rateErrorFactory->create();
$error->setCarrier($this->_code); $error->setCarrier($this->_code);
$error->setCarrierTitle($this->getConfigData('title')); $error->setCarrierTitle($this->getConfigData('title'));
...@@ -1251,7 +1261,7 @@ class BobGo extends AbstractCarrierOnline implements CarrierInterface ...@@ -1251,7 +1261,7 @@ class BobGo extends AbstractCarrierOnline implements CarrierInterface
return $error; return $error;
} }
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->error($e->getMessage()); $this->logger->error('Error fetching rates from API: ' . $e->getMessage());
$error = $this->_rateErrorFactory->create(); $error = $this->_rateErrorFactory->create();
$error->setCarrier($this->_code); $error->setCarrier($this->_code);
$error->setCarrierTitle($this->getConfigData('title')); $error->setCarrierTitle($this->getConfigData('title'));
...@@ -1291,3 +1301,4 @@ class BobGo extends AbstractCarrierOnline implements CarrierInterface ...@@ -1291,3 +1301,4 @@ class BobGo extends AbstractCarrierOnline implements CarrierInterface
return [$this->_code => $this->getConfigData('name')]; return [$this->_code => $this->getConfigData('name')];
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment