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

cleanup

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