Skip to content

Commit 8b09a6f

Browse files
author
Oleksandr Iegorov
committed
MAGETWO-98328: Update FedEx Shipping Dates behavior in Tracking Popup
1 parent 9cdc1b7 commit 8b09a6f

File tree

6 files changed

+124
-2
lines changed

6 files changed

+124
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
* @param Subject $subject
20+
* @param \Magento\Framework\Phrase|string $result
21+
* @param Status $trackingStatus
22+
* @return \Magento\Framework\Phrase|string
23+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
24+
*/
25+
public function afterGetTitle(Subject $subject, $result, Status $trackingStatus): string
26+
{
27+
if ($trackingStatus->getCarrier() === Carrier::CODE) {
28+
$result = __('Expected Delivery:');
29+
}
30+
return $result;
31+
}
32+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Fedex\Plugin\Block\Tracking;
9+
10+
use Magento\Shipping\Block\Tracking\Popup;
11+
use Magento\Fedex\Model\Carrier;
12+
use Magento\Shipping\Model\Tracking\Result\Status;
13+
14+
/**
15+
* Plugin to update delivery date value in case if Fedex used
16+
*/
17+
class PopupDeliveryDate
18+
{
19+
/**
20+
* Show only date for expected delivery in case if Fedex is a carrier
21+
*
22+
* @param Popup $subject
23+
* @param string $result
24+
* @param string $date
25+
* @param string $time
26+
* @return string
27+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
28+
*/
29+
public function afterFormatDeliveryDateTime(Popup $subject, string $result, string $date, string $time): string
30+
{
31+
if ($this->getCarrier($subject) === Carrier::CODE) {
32+
$result = $subject->formatDeliveryDate($date);
33+
}
34+
return $result;
35+
}
36+
37+
/**
38+
* Retrieve carrier name from tracking info
39+
*
40+
* @param Popup $subject
41+
* @return string
42+
*/
43+
private function getCarrier(Popup $subject): string
44+
{
45+
foreach ($subject->getTrackingInfo() as $trackingData) {
46+
foreach ($trackingData as $trackingInfo) {
47+
if ($trackingInfo instanceof Status) {
48+
$carrier = $trackingInfo->getCarrier();
49+
return $carrier;
50+
}
51+
}
52+
}
53+
return '';
54+
}
55+
}

app/code/Magento/Fedex/etc/di.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,10 @@
2222
</argument>
2323
</arguments>
2424
</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>
2531
</config>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
* @param Status $trackingStatus
19+
* @return \Magento\Framework\Phrase|string
20+
*/
21+
public function getTitle(Status $trackingStatus)
22+
{
23+
return $trackingStatus->getCarrier() ? __('Delivered on:') : '';
24+
}
25+
}

app/code/Magento/Shipping/view/frontend/layout/shipping_tracking_popup.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="empty" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
99
<body>
1010
<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>
1216
</referenceContainer>
1317
</body>
1418
</page>

app/code/Magento/Shipping/view/frontend/templates/tracking/details.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ $number = is_object($track) ? $track->getTracking() : $track['number'];
7777

7878
<?php if ($track->getDeliverydate()): ?>
7979
<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>
8181
<td class="col value">
8282
<?= /* @noEscape */ $parentBlock->formatDeliveryDateTime($track->getDeliverydate(), $track->getDeliverytime()) ?>
8383
</td>

0 commit comments

Comments
 (0)