From 8b3701b5d1cc3ca8eddc61b7c9bed9262b16edac Mon Sep 17 00:00:00 2001
From: Gundo Sifhufhi <sifhufhisg@gmail.com>
Date: Tue, 20 Dec 2022 19:22:12 +0200
Subject: [PATCH] Allow user(customer) and admin to click on "Track Order" and
 pop a modal with order tracking information

---
 .idea/csv-editor.xml                          | 16 ++++++++++
 .../Model/Carrier/Customshipping.php          | 16 +++++++++-
 .../DataProviders/Tracking/ChangeTitle.php    | 32 +++++++++++++++++++
 3 files changed, 63 insertions(+), 1 deletion(-)
 create mode 100644 .idea/csv-editor.xml
 create mode 100644 uafrica/Customshipping/Plugin/Block/DataProviders/Tracking/ChangeTitle.php

diff --git a/.idea/csv-editor.xml b/.idea/csv-editor.xml
new file mode 100644
index 0000000..24b6446
--- /dev/null
+++ b/.idea/csv-editor.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="CsvFileAttributes">
+    <option name="attributeMap">
+      <map>
+        <entry key="$PROJECT_DIR$/uafrica/Customshipping/i18n/en_US.csv">
+          <value>
+            <Attribute>
+              <option name="separator" value="," />
+            </Attribute>
+          </value>
+        </entry>
+      </map>
+    </option>
+  </component>
+</project>
\ No newline at end of file
diff --git a/uafrica/Customshipping/Model/Carrier/Customshipping.php b/uafrica/Customshipping/Model/Carrier/Customshipping.php
index b761996..90d3481 100644
--- a/uafrica/Customshipping/Model/Carrier/Customshipping.php
+++ b/uafrica/Customshipping/Model/Carrier/Customshipping.php
@@ -55,7 +55,7 @@ class Customshipping extends AbstractCarrier implements CarrierInterface
 
 
 
-    //TODO: REFACTO THIS
+    //TODO: REFACTOR THIS
     /**
      * @var \Magento\Framework\Controller\Result\JsonFactory
      */
@@ -114,6 +114,20 @@ class Customshipping extends AbstractCarrier implements CarrierInterface
     {
         return true;
     }
+    //Make getracking available with  fake data
+    /**
+     * @param string $tracking
+     * @return DataObject
+     */
+    public function getTrackingInfo($tracking): DataObject
+    {   
+         //  $result = $this->_trackFactory->create();
+        $result = new DataObject();
+        $result->setUrl('https://api.dev.ship.uafrica.com/tracking?channel=localhost&tracking_reference=UADPCTGF');
+        $result->setTracking($tracking);
+        $result->setCarrierTitle($this->getConfigData('title'));
+        return $result;
+    }
 
     /**
      * Collect and get rates for storefront
diff --git a/uafrica/Customshipping/Plugin/Block/DataProviders/Tracking/ChangeTitle.php b/uafrica/Customshipping/Plugin/Block/DataProviders/Tracking/ChangeTitle.php
new file mode 100644
index 0000000..854d227
--- /dev/null
+++ b/uafrica/Customshipping/Plugin/Block/DataProviders/Tracking/ChangeTitle.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace uafrica\Customshipping\Plugin\Block\DataProviders\Tracking;
+
+use uafrica\Customshipping\Model\Carrier;
+use Magento\Shipping\Model\Tracking\Result\Status;
+use Magento\Shipping\Block\DataProviders\Tracking\DeliveryDateTitle as Subject;
+
+
+/**
+ * Plugin to change delivery date title with UAfrica customized value
+ */
+
+class ChangeTitle
+{
+    /**
+     * Title modification in case if UAfrica used as carrier
+     *
+     * @param Subject $subject
+     * @param \Magento\Framework\Phrase|string $result
+     * @param Status $trackingStatus
+     * @return \Magento\Framework\Phrase|string
+     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+     */
+    public function afterGetTitle(Subject $subject, $result, Status $trackingStatus)
+    {
+        if ($trackingStatus->getCarrier() === Carrier::CODE) {
+            $result = __('Expected Delivery:');
+        }
+        return $result;
+    }
+}
-- 
GitLab