Skip to content

Commit 697978e

Browse files
authored
Merge pull request #3806 from magento-tango/MAGETWO-98328
MAGETWO-98328: Update FedEx Shipping Dates behavior in Tracking Popup
2 parents 0a91fff + a804b62 commit 697978e

File tree

6 files changed

+127
-2
lines changed

6 files changed

+127
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

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

+6
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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

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

+5-1
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

+1-1
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)