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

cleanup

parent 62c32bf0
No related branches found
No related tags found
2 merge requests!201.0.41,!15Tracking page
...@@ -12,11 +12,11 @@ class TrackOrderLink extends Current ...@@ -12,11 +12,11 @@ class TrackOrderLink extends Current
public function __construct( public function __construct(
\Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\View\Element\Template\Context $context,
ScopeConfigInterface $scopeConfig, ScopeConfigInterface $scopeConfig,
\Magento\Framework\App\DefaultPathInterface $defaultPath, // Add this dependency \Magento\Framework\App\DefaultPathInterface $defaultPath,
array $data = [] array $data = []
) { ) {
$this->scopeConfig = $scopeConfig; $this->scopeConfig = $scopeConfig;
parent::__construct($context, $defaultPath, $data); // Pass it to the parent constructor parent::__construct($context, $defaultPath, $data);
} }
protected function _toHtml() protected function _toHtml()
...@@ -27,11 +27,13 @@ class TrackOrderLink extends Current ...@@ -27,11 +27,13 @@ class TrackOrderLink extends Current
\Magento\Store\Model\ScopeInterface::SCOPE_STORE \Magento\Store\Model\ScopeInterface::SCOPE_STORE
); );
// Return an empty string if the feature is disabled
if (!$isEnabled) { if (!$isEnabled) {
return ''; // Return an empty string if the feature is disabled return '';
} }
return parent::_toHtml(); // Use the parent class's rendering method // Use the parent class's rendering method
return parent::_toHtml();
} }
} }
......
...@@ -32,7 +32,7 @@ class Index extends \Magento\Framework\App\Action\Action ...@@ -32,7 +32,7 @@ class Index extends \Magento\Framework\App\Action\Action
RedirectFactory $redirectFactory, RedirectFactory $redirectFactory,
StoreManagerInterface $storeManager, StoreManagerInterface $storeManager,
Curl $curl, Curl $curl,
Registry $registry // Add Registry Registry $registry
) { ) {
$this->resultPageFactory = $resultPageFactory; $this->resultPageFactory = $resultPageFactory;
$this->jsonFactory = $jsonFactory; $this->jsonFactory = $jsonFactory;
...@@ -41,12 +41,13 @@ class Index extends \Magento\Framework\App\Action\Action ...@@ -41,12 +41,13 @@ class Index extends \Magento\Framework\App\Action\Action
$this->redirectFactory = $redirectFactory; $this->redirectFactory = $redirectFactory;
$this->storeManager = $storeManager; $this->storeManager = $storeManager;
$this->curl = $curl; $this->curl = $curl;
$this->registry = $registry; // Assign Registry $this->registry = $registry;
parent::__construct($context); parent::__construct($context);
} }
public function execute() public function execute()
{ {
// This is only an extra check after the TrackOrderLink block
// Check if the "Track My Order" feature is enabled // Check if the "Track My Order" feature is enabled
$isEnabled = $this->scopeConfig->isSetFlag( $isEnabled = $this->scopeConfig->isSetFlag(
'carriers/bobgo/enable_track_order', 'carriers/bobgo/enable_track_order',
...@@ -58,48 +59,32 @@ class Index extends \Magento\Framework\App\Action\Action ...@@ -58,48 +59,32 @@ class Index extends \Magento\Framework\App\Action\Action
return $this->redirectFactory->create()->setPath('noroute'); return $this->redirectFactory->create()->setPath('noroute');
} }
$this->logger->info('Page Controller is executed.');
$trackingReference = $this->getRequest()->getParam('order_reference'); $trackingReference = $this->getRequest()->getParam('order_reference');
$this->logger->info('Tracking reference:', [$trackingReference]);
$channel = $this->getStoreUrl(); $channel = $this->getStoreUrl();
$this->logger->info('Channel:', [$channel]);
if ($trackingReference) { if ($trackingReference) {
$trackingUrl = sprintf(UData::TRACKING, $channel, $trackingReference); $trackingUrl = sprintf(UData::TRACKING, $channel, $trackingReference);
try {
$this->curl->get($trackingUrl); $this->curl->get($trackingUrl);
$response = $this->curl->getBody(); $response = $this->curl->getBody();
$this->logger->info('Response:', [$response]);
$decodedResponse = json_decode($response, true); $decodedResponse = json_decode($response, true);
$this->logger->info('Decoded Response:', [$decodedResponse]);
if (is_array($decodedResponse) && isset($decodedResponse[0])) { if (is_array($decodedResponse) && isset($decodedResponse[0])) {
$shipmentData = $decodedResponse[0]; $shipmentData = $decodedResponse[0];
// Save data to the registry // Save data to the registry
$this->registry->register('shipment_data', $shipmentData); $this->registry->register('shipment_data', $shipmentData);
$this->logger->info('Shipment data registered in the registry.');
} else { } else {
$this->logger->info('Unexpected response format.'); // Return early the response is not valid
} return $this->resultPageFactory->create();
} catch (\Exception $e) {
$this->logger->info('Track error: ' . $e->getMessage());
$this->messageManager->addErrorMessage(__('Unable to track the order.'));
} }
} }
return $this->resultPageFactory->create(); return $this->resultPageFactory->create();
} }
private function getStoreUrl(): string private function getStoreUrl(): string
{ {
$url = $this->storeManager->getStore()->getBaseUrl(); $url = $this->storeManager->getStore()->getBaseUrl();
......
...@@ -13,9 +13,4 @@ ...@@ -13,9 +13,4 @@
<argument name="logger" xsi:type="object">Psr\Log\LoggerInterface</argument> <argument name="logger" xsi:type="object">Psr\Log\LoggerInterface</argument>
</arguments> </arguments>
</type> </type>
<type name="Magento\Framework\View\Layout">
<arguments>
<argument name="debug" xsi:type="boolean">true</argument>
</arguments>
</type>
</config> </config>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment