File tree 6 files changed +127
-2
lines changed
Block/DataProviders/Tracking
6 files changed +127
-2
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+
7
+ namespace Magento \Fedex \Plugin \Block \DataProviders \Tracking ;
8
+
9
+ use Magento \Fedex \Model \Carrier ;
10
+ use Magento \Shipping \Model \Tracking \Result \Status ;
11
+ use Magento \Shipping \Block \DataProviders \Tracking \DeliveryDateTitle as Subject ;
12
+
13
+ /**
14
+ * Plugin to change delivery date title with FedEx customized value
15
+ */
16
+ class ChangeTitle
17
+ {
18
+ /**
19
+ * Title modification in case if FedEx used as carrier
20
+ *
21
+ * @param Subject $subject
22
+ * @param \Magento\Framework\Phrase|string $result
23
+ * @param Status $trackingStatus
24
+ * @return \Magento\Framework\Phrase|string
25
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
26
+ */
27
+ public function afterGetTitle (Subject $ subject , $ result , Status $ trackingStatus )
28
+ {
29
+ if ($ trackingStatus ->getCarrier () === Carrier::CODE ) {
30
+ $ result = __ ('Expected Delivery: ' );
31
+ }
32
+ return $ result ;
33
+ }
34
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+
7
+ namespace Magento \Fedex \Plugin \Block \Tracking ;
8
+
9
+ use Magento \Shipping \Block \Tracking \Popup ;
10
+ use Magento \Fedex \Model \Carrier ;
11
+ use Magento \Shipping \Model \Tracking \Result \Status ;
12
+
13
+ /**
14
+ * Plugin to update delivery date value in case if Fedex used
15
+ */
16
+ class PopupDeliveryDate
17
+ {
18
+ /**
19
+ * Show only date for expected delivery in case if Fedex is a carrier
20
+ *
21
+ * @param Popup $subject
22
+ * @param string $result
23
+ * @param string $date
24
+ * @param string $time
25
+ * @return string
26
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
27
+ */
28
+ public function afterFormatDeliveryDateTime (Popup $ subject , $ result , $ date , $ time )
29
+ {
30
+ if ($ this ->getCarrier ($ subject ) === Carrier::CODE ) {
31
+ $ result = $ subject ->formatDeliveryDate ($ date );
32
+ }
33
+ return $ result ;
34
+ }
35
+
36
+ /**
37
+ * Retrieve carrier name from tracking info
38
+ *
39
+ * @param Popup $subject
40
+ * @return string
41
+ */
42
+ private function getCarrier (Popup $ subject ): string
43
+ {
44
+ foreach ($ subject ->getTrackingInfo () as $ trackingData ) {
45
+ foreach ($ trackingData as $ trackingInfo ) {
46
+ if ($ trackingInfo instanceof Status) {
47
+ $ carrier = $ trackingInfo ->getCarrier ();
48
+ return $ carrier ;
49
+ }
50
+ }
51
+ }
52
+ return '' ;
53
+ }
54
+ }
Original file line number Diff line number Diff line change 22
22
</argument >
23
23
</arguments >
24
24
</type >
25
+ <type name =" Magento\Shipping\Block\DataProviders\Tracking\DeliveryDateTitle" >
26
+ <plugin name =" update_delivery_date_title" type =" Magento\Fedex\Plugin\Block\DataProviders\Tracking\ChangeTitle" />
27
+ </type >
28
+ <type name =" Magento\Shipping\Block\Tracking\Popup" >
29
+ <plugin name =" update_delivery_date_value" type =" Magento\Fedex\Plugin\Block\Tracking\PopupDeliveryDate" />
30
+ </type >
25
31
</config >
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+
7
+ namespace Magento \Shipping \Block \DataProviders \Tracking ;
8
+
9
+ use Magento \Framework \View \Element \Block \ArgumentInterface ;
10
+ use Magento \Shipping \Model \Tracking \Result \Status ;
11
+
12
+ /**
13
+ * Extension point to provide ability to change tracking details titles
14
+ */
15
+ class DeliveryDateTitle implements ArgumentInterface
16
+ {
17
+ /**
18
+ * Returns Title in case if carrier defined
19
+ *
20
+ * @param Status $trackingStatus
21
+ * @return \Magento\Framework\Phrase|string
22
+ */
23
+ public function getTitle (Status $ trackingStatus )
24
+ {
25
+ return $ trackingStatus ->getCarrier () ? __ ('Delivered on: ' ) : '' ;
26
+ }
27
+ }
Original file line number Diff line number Diff line change 8
8
<page xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" layout =" empty" xsi : noNamespaceSchemaLocation =" urn:magento:framework:View/Layout/etc/page_configuration.xsd" >
9
9
<body >
10
10
<referenceContainer name =" content" >
11
- <block class =" Magento\Shipping\Block\Tracking\Popup" name =" shipping.tracking.popup" template =" Magento_Shipping::tracking/popup.phtml" cacheable =" false" />
11
+ <block class =" Magento\Shipping\Block\Tracking\Popup" name =" shipping.tracking.popup" template =" Magento_Shipping::tracking/popup.phtml" cacheable =" false" >
12
+ <arguments >
13
+ <argument name =" delivery_date_title" xsi : type =" object" >Magento\Shipping\Block\DataProviders\Tracking\DeliveryDateTitle</argument >
14
+ </arguments >
15
+ </block >
12
16
</referenceContainer >
13
17
</body >
14
18
</page >
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ $number = is_object($track) ? $track->getTracking() : $track['number'];
77
77
78
78
<?php if ($ track ->getDeliverydate ()): ?>
79
79
<tr>
80
- <th class="col label" scope="row"><?= $ block ->escapeHtml (__ ( ' Delivered on: ' )) ?> </th>
80
+ <th class="col label" scope="row"><?= $ block ->escapeHtml ($ parentBlock -> getDeliveryDateTitle ()-> getTitle ( $ track )) ?> </th>
81
81
<td class="col value">
82
82
<?= /* @noEscape */ $ parentBlock ->formatDeliveryDateTime ($ track ->getDeliverydate (), $ track ->getDeliverytime ()) ?>
83
83
</td>
You can’t perform that action at this time.
0 commit comments