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

Cleanup logging

parent 6c0616b7
No related branches found
No related tags found
1 merge request!6Rates at checkout
......@@ -827,7 +827,6 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car
$result->append($error);
} else {
$this->_logger->info('Rates are not empty.');
foreach ($rates['rates'] as $rate) {
......@@ -837,18 +836,12 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car
// Set the carrier code
$method->setCarrier(self::CODE);
// Log the original service code
$this->_logger->info('Original service code: ' . $rate['service_code']);
// Strip out the redundant 'bobgo_' prefix if present
$serviceCode = $rate['service_code'];
if (strpos($serviceCode, 'bobgo_') === 0) {
$serviceCode = substr($serviceCode, strlen('bobgo_'));
}
// Log the modified service code
$this->_logger->info('Modified service code: ' . $serviceCode);
// Set the method with the modified service code
$method->setMethod($serviceCode);
......@@ -868,20 +861,12 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car
$method->setPrice($price);
$method->setCost($cost);
// Log the values
$this->_logger->info('Price: ' . $price);
$this->_logger->info('Cost: ' . $cost);
$result->append($method);
}
}
}
}
/**
* Prepare received checkpoints and activity from Bob Go Shipment Tracking API
* @param $response
......@@ -1120,9 +1105,6 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car
$statusCode = $this->curl->getStatus();
$responseBody = $this->curl->getBody();
// Log the response for debugging purposes
$this->_logger->info('BobGo Rates API Test Response: ' . $responseBody);
// Decode the response
$response = json_decode($responseBody, true);
......@@ -1135,7 +1117,6 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car
if (isset($response['rates']) && is_array($response['rates']) && !empty($response['rates'])) {
foreach ($response['rates'] as $rate) {
if (isset($rate['id']) && $rate['id'] !== null) {
$this->_logger->info('Rates received successfully with a valid id.');
return $response; // Successful response with a valid id
}
}
......@@ -1144,13 +1125,9 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car
throw new \Exception('Received response but no valid rates were found.');
}
} catch (\Exception $e) {
$this->_logger->error('Error in triggerRatesTest: ' . $e->getMessage());
return false;
}
}
return false;
}
}
......@@ -26,28 +26,19 @@ class ConfigChangeObserver implements ObserverInterface
public function execute(Observer $observer)
{
$this->logger->info('ConfigChangeObserver triggered.');
$changedPaths = $observer->getEvent()->getData('changed_paths');
if (is_array($changedPaths) && in_array('carriers/bobgo/active', $changedPaths)) {
$this->logger->info('BobGo configuration change detected.');
if ($this->bobGo->isActive()) {
$result = $this->bobGo->triggerRatesTest();
if ($result !== false) {
$this->logger->info('Rates test triggered successfully with a valid response.');
$this->messageManager->addSuccessMessage(__('BobGo rates test triggered successfully.'));
$this->messageManager->addSuccessMessage(__('BobGo rates at checkout test is successful.'));
} else {
$this->logger->error('Error in BobGo rates test.');
$this->messageManager->addErrorMessage(__('BobGo rates test failed. Please check visit https://www.bobgo.co.za/ and enable this channel for rates at checkout.'));
$this->messageManager->addErrorMessage(__('BobGo rates at checkout test failed. Please visit https://www.bobgo.co.za/ and enable this channel for rates at checkout.'));
}
} else {
$this->logger->info('BobGo is not active.');
}
} else {
$this->logger->info('No relevant configuration changes detected.');
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment