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

link the setting to the tracking page

parent abe3e0eb
No related branches found
No related tags found
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.
<?php
namespace BobGroup\BobGo\Block;
use Magento\Framework\View\Element\Html\Link\Current;
use Magento\Framework\App\Config\ScopeConfigInterface;
class TrackOrderLink extends Current
{
protected $scopeConfig;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
ScopeConfigInterface $scopeConfig,
\Magento\Framework\App\DefaultPathInterface $defaultPath, // Add this dependency
array $data = []
) {
$this->scopeConfig = $scopeConfig;
parent::__construct($context, $defaultPath, $data); // Pass it to the parent constructor
}
protected function _toHtml()
{
// Check if the Track My Order feature is enabled
$isEnabled = $this->scopeConfig->isSetFlag(
'carriers/bobgo/enable_track_order',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
if (!$isEnabled) {
return ''; // Return an empty string if the feature is disabled
}
return parent::_toHtml(); // Use the parent class's rendering method
}
}
......@@ -5,6 +5,8 @@ use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\Registry;
use Psr\Log\LoggerInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\HTTP\Client\Curl;
use Magento\Store\Model\StoreManagerInterface;
......@@ -16,6 +18,8 @@ class Index extends \Magento\Framework\App\Action\Action
protected $jsonFactory;
protected $curl;
protected $logger;
protected $scopeConfig;
protected $redirectFactory;
protected $registry;
protected StoreManagerInterface $storeManager;
......@@ -24,6 +28,8 @@ class Index extends \Magento\Framework\App\Action\Action
PageFactory $resultPageFactory,
JsonFactory $jsonFactory,
LoggerInterface $logger,
ScopeConfigInterface $scopeConfig,
RedirectFactory $redirectFactory,
StoreManagerInterface $storeManager,
Curl $curl,
Registry $registry // Add Registry
......@@ -31,6 +37,8 @@ class Index extends \Magento\Framework\App\Action\Action
$this->resultPageFactory = $resultPageFactory;
$this->jsonFactory = $jsonFactory;
$this->logger = $logger;
$this->scopeConfig = $scopeConfig;
$this->redirectFactory = $redirectFactory;
$this->storeManager = $storeManager;
$this->curl = $curl;
$this->registry = $registry; // Assign Registry
......@@ -39,6 +47,17 @@ class Index extends \Magento\Framework\App\Action\Action
public function execute()
{
// Check if the "Track My Order" feature is enabled
$isEnabled = $this->scopeConfig->isSetFlag(
'carriers/bobgo/enable_track_order',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
if (!$isEnabled) {
// If the feature is disabled, redirect to home page or show a 404 error
return $this->redirectFactory->create()->setPath('noroute');
}
$this->logger->info('Page Controller is executed.');
$trackingReference = $this->getRequest()->getParam('order_reference');
......
......@@ -3,7 +3,7 @@
<update handle="customer_account"/>
<head>
<title>
Tracking
Track my order
</title>
</head>
<body>
......
......@@ -2,8 +2,8 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="customer_account_navigation">
<!-- Add menu to the end of the sidebar -->
<block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-tracking">
<!-- Add conditional menu to the end of the sidebar -->
<block class="BobGroup\BobGo\Block\TrackOrderLink" name="customer-account-navigation-tracking">
<arguments>
<argument name="path" xsi:type="string">bobgo/tracking/index</argument>
<argument name="label" xsi:type="string">Track my order</argument>
......
<?php
$shipmentData = $this->getResponse();
?>
<style>
.track-order-container {
max-width: 600px;
......@@ -28,7 +32,8 @@
</style>
<div class="track-order-container">
<form action="<?php echo $this->getUrl('bobgo/tracking/index'); ?>" method="post">
<?php if (empty($shipmentData)) : ?>
<form action="<?php echo $this->getUrl('bobgo/tracking/index'); ?>" method="post" class="track-order-form">
<div class="field">
<label for="order_reference"><?php echo __('Order Number/Tracking Reference:'); ?></label>
<input type="text" id="order_reference" name="order_reference" required>
......@@ -38,45 +43,85 @@
<button type="submit" class="action submit primary"><?php echo __('Track Order'); ?></button>
</div>
</form>
<?php endif; ?>
<?php
$shipmentData = $this->getResponse();
if ($shipmentData && is_array($shipmentData)) {
echo '<div class="tracking-details">';
echo '<h2>' . __('Shipping Details') . '</h2>';
// Ensure each accessed array key exists and contains an array where expected
if (isset($shipmentData['shipment_tracking_reference'])) {
echo '<p>' . __('Shipment: ') . $shipmentData['shipment_tracking_reference'] . '</p>';
}
if (isset($shipmentData['order_number'])) {
echo '<p>' . __('Order: ') . ltrim($shipmentData['order_number'], '0') . '</p>';
}
if (isset($shipmentData['courier_name'])) {
echo '<p>' . __('Courier: ') . $shipmentData['courier_name'] . '</p>';
}
<?php if ($shipmentData && is_array($shipmentData)) : ?>
<div class="tracking-details">
<h2><?php echo __('Shipping Details'); ?></h2>
echo '<h2>' . __('Tracking Details') . '</h2>';
<?php if (isset($shipmentData['shipment_tracking_reference'])) : ?>
<p><strong><?php echo __('Shipment:'); ?></strong> <?php echo $shipmentData['shipment_tracking_reference']; ?></p>
<?php endif; ?>
if (isset($shipmentData['status_friendly'])) {
echo '<p>' . __('Current Status: ') . $shipmentData['status_friendly'] . '</p>';
}
<?php if (isset($shipmentData['order_number'])) : ?>
<p><strong><?php echo __('Order:'); ?></strong> <?php echo ltrim($shipmentData['order_number'], '0'); ?></p>
<?php endif; ?>
if (isset($shipmentData['courier_logo'])) {
echo '<footer>';
echo '<p>' . __('For additional information, please contact BobGo (support@bobgo.co.za).') . '</p>';
echo '<img src="' . $shipmentData['courier_logo'] . '" alt="Courier Logo" style="width: 100px;"/>';
echo '</footer>';
}
<?php if (isset($shipmentData['courier_name'])) : ?>
<p><strong><?php echo __('Courier:'); ?></strong> <?php echo $shipmentData['courier_name']; ?></p>
<?php endif; ?>
echo '</div>';
} else {
echo '<p>No tracking data available.</p>';
}
<br>
<h2><?php echo __('Tracking Details'); ?></h2>
<?php if (isset($shipmentData['status']) && isset($shipmentData['status_friendly'])) : ?>
<?php if ($shipmentData['status'] == 'pending-collection') : ?>
<p><?php echo 'Your shipment will be collected soon. Please check back later for more information.' ?></p>
<p><strong><?php echo __('Current Status:'); ?></strong> <?php echo $shipmentData['status_friendly']; ?></p>
<?php elseif (in_array($shipmentData['status'], ['cancelled-by-courier', 'cancelled'])) : ?>
<p><?php echo 'The shipment has been cancelled.'; ?></p>
<p><strong><?php echo __('Current Status:'); ?></strong> <?php echo $shipmentData['status_friendly']; ?></p>
<?php else : ?>
<?php if (empty($shipmentData['checkpoints'])) : ?>
<p><?php echo 'Tracking information is not yet available. Please check back later for more information.'; ?></p>
<?php else : ?>
<p><?php echo 'Tracking information is available below:'; ?></p>
<table id="table_checkpoints">
<thead>
<tr>
<th><?php echo __('Date and Time'); ?></th>
<th><?php echo __('Status'); ?></th>
<th><?php echo __('Message'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($shipmentData['checkpoints'] as $checkpoint) : ?>
<tr>
<td>
<?php
$timeDate = new DateTime($checkpoint['time']);
echo $timeDate->format('Y M d, H:i');
?>
</td>
<td><strong><?php echo $checkpoint['status_friendly']; ?></strong></td>
<td><?php echo $checkpoint['message']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
</div>
<br>
<footer>
<p>
<?php
echo sprintf(
__('For additional information, please contact %s (%s) and quote tracking reference %s.'),
$shipmentData['courier_name'],
$shipmentData['courier_phone'],
$shipmentData['id']
);
?>
</p>
<img id="show_branding" class="image"
src="https://img.bob.co.za/bobgo/image/upload/bobgo-logos/bobgo_logo_smart_shipping_black.png?tr=w-400&ts=20231024"
alt="Bob Go logo" style="width: 200px;">
</footer>
<?php else : ?>
<br>
<p><?php echo __('No tracking data available.'); ?></p>
<?php endif; ?>
</div>
view/frontend/web/images/logo.png

57.8 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment