diff --git a/Block/TrackOrderLink.php b/Block/TrackOrderLink.php new file mode 100644 index 0000000000000000000000000000000000000000..54c3c6f75c93639c08856f0c31169bfdff15df6a --- /dev/null +++ b/Block/TrackOrderLink.php @@ -0,0 +1,39 @@ +<?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 + } +} + + + diff --git a/Controller/Tracking/Index.php b/Controller/Tracking/Index.php index 0fc445bd64f66f3fadd8261ea53ccc2e3330fe37..c3a01eeb9e6c21b99e03dccd97cb457da6f47dc6 100644 --- a/Controller/Tracking/Index.php +++ b/Controller/Tracking/Index.php @@ -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'); diff --git a/view/frontend/layout/bobgo_tracking_index.xml b/view/frontend/layout/bobgo_tracking_index.xml index 6e842d75ba98d244c64397babcc8c6055e504b09..e36faa5492b864f1f27524486ba0ce148a364b64 100644 --- a/view/frontend/layout/bobgo_tracking_index.xml +++ b/view/frontend/layout/bobgo_tracking_index.xml @@ -3,7 +3,7 @@ <update handle="customer_account"/> <head> <title> - Tracking + Track my order </title> </head> <body> diff --git a/view/frontend/layout/customer_account.xml b/view/frontend/layout/customer_account.xml index be9a72f764165ba9ca0f301f2ac5643cc1b6d850..701335df1dc4d481523171edc19e24bbac950feb 100644 --- a/view/frontend/layout/customer_account.xml +++ b/view/frontend/layout/customer_account.xml @@ -1,14 +1,14 @@ <?xml version="1.0"?> <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"> - <arguments> - <argument name="path" xsi:type="string">bobgo/tracking/index</argument> - <argument name="label" xsi:type="string">Track my order</argument> - </arguments> - </block> - </referenceBlock> -</body> + <body> + <referenceBlock name="customer_account_navigation"> + <!-- 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> + </arguments> + </block> + </referenceBlock> + </body> </page> diff --git a/view/frontend/templates/tracking/index.phtml b/view/frontend/templates/tracking/index.phtml index f6e2b2325e110ceb527bce939e8614dd4120c6ff..b9f8ba09a5b8ffbcb738f9ab839ca8fbb20dee97 100644 --- a/view/frontend/templates/tracking/index.phtml +++ b/view/frontend/templates/tracking/index.phtml @@ -1,3 +1,7 @@ +<?php +$shipmentData = $this->getResponse(); +?> + <style> .track-order-container { max-width: 600px; @@ -28,55 +32,96 @@ </style> <div class="track-order-container"> - <form action="<?php echo $this->getUrl('bobgo/tracking/index'); ?>" method="post"> - <div class="field"> - <label for="order_reference"><?php echo __('Order Number/Tracking Reference:'); ?></label> - <input type="text" id="order_reference" name="order_reference" required> - </div> - <br> - <div class="actions-toolbar"> - <button type="submit" class="action submit primary"><?php echo __('Track Order'); ?></button> + <?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> + </div> + <br> + <div class="actions-toolbar"> + <button type="submit" class="action submit primary"><?php echo __('Track Order'); ?></button> + </div> + </form> + <?php endif; ?> + + <?php if ($shipmentData && is_array($shipmentData)) : ?> + <div class="tracking-details"> + <h2><?php echo __('Shipping Details'); ?></h2> + + <?php if (isset($shipmentData['shipment_tracking_reference'])) : ?> + <p><strong><?php echo __('Shipment:'); ?></strong> <?php echo $shipmentData['shipment_tracking_reference']; ?></p> + <?php endif; ?> + + <?php if (isset($shipmentData['order_number'])) : ?> + <p><strong><?php echo __('Order:'); ?></strong> <?php echo ltrim($shipmentData['order_number'], '0'); ?></p> + <?php endif; ?> + + <?php if (isset($shipmentData['courier_name'])) : ?> + <p><strong><?php echo __('Courier:'); ?></strong> <?php echo $shipmentData['courier_name']; ?></p> + <?php endif; ?> + + <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> - </form> - - <?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>'; - } - - echo '<h2>' . __('Tracking Details') . '</h2>'; - - if (isset($shipmentData['status_friendly'])) { - echo '<p>' . __('Current Status: ') . $shipmentData['status_friendly'] . '</p>'; - } - - 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>'; - } - - echo '</div>'; - } else { - echo '<p>No tracking data available.</p>'; - } - ?> - + <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> diff --git a/view/frontend/web/images/logo.png b/view/frontend/web/images/logo.png deleted file mode 100644 index a1214967803c946558511b30e91ac9600543a707..0000000000000000000000000000000000000000 Binary files a/view/frontend/web/images/logo.png and /dev/null differ