Skip to content

Commit

Permalink
Merge pull request #3806 from magento-tango/MAGETWO-98328
Browse files Browse the repository at this point in the history
MAGETWO-98328: Update FedEx Shipping Dates behavior in Tracking Popup
  • Loading branch information
dhorytskyi authored Feb 26, 2019
2 parents 0a91fff + a804b62 commit 697978e
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Fedex\Plugin\Block\DataProviders\Tracking;

use Magento\Fedex\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 FedEx customized value
*/
class ChangeTitle
{
/**
* Title modification in case if FedEx 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;
}
}
54 changes: 54 additions & 0 deletions app/code/Magento/Fedex/Plugin/Block/Tracking/PopupDeliveryDate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Fedex\Plugin\Block\Tracking;

use Magento\Shipping\Block\Tracking\Popup;
use Magento\Fedex\Model\Carrier;
use Magento\Shipping\Model\Tracking\Result\Status;

/**
* Plugin to update delivery date value in case if Fedex used
*/
class PopupDeliveryDate
{
/**
* Show only date for expected delivery in case if Fedex is a carrier
*
* @param Popup $subject
* @param string $result
* @param string $date
* @param string $time
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterFormatDeliveryDateTime(Popup $subject, $result, $date, $time)
{
if ($this->getCarrier($subject) === Carrier::CODE) {
$result = $subject->formatDeliveryDate($date);
}
return $result;
}

/**
* Retrieve carrier name from tracking info
*
* @param Popup $subject
* @return string
*/
private function getCarrier(Popup $subject): string
{
foreach ($subject->getTrackingInfo() as $trackingData) {
foreach ($trackingData as $trackingInfo) {
if ($trackingInfo instanceof Status) {
$carrier = $trackingInfo->getCarrier();
return $carrier;
}
}
}
return '';
}
}
6 changes: 6 additions & 0 deletions app/code/Magento/Fedex/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@
</argument>
</arguments>
</type>
<type name="Magento\Shipping\Block\DataProviders\Tracking\DeliveryDateTitle">
<plugin name="update_delivery_date_title" type="Magento\Fedex\Plugin\Block\DataProviders\Tracking\ChangeTitle"/>
</type>
<type name="Magento\Shipping\Block\Tracking\Popup">
<plugin name="update_delivery_date_value" type="Magento\Fedex\Plugin\Block\Tracking\PopupDeliveryDate"/>
</type>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Shipping\Block\DataProviders\Tracking;

use Magento\Framework\View\Element\Block\ArgumentInterface;
use Magento\Shipping\Model\Tracking\Result\Status;

/**
* Extension point to provide ability to change tracking details titles
*/
class DeliveryDateTitle implements ArgumentInterface
{
/**
* Returns Title in case if carrier defined
*
* @param Status $trackingStatus
* @return \Magento\Framework\Phrase|string
*/
public function getTitle(Status $trackingStatus)
{
return $trackingStatus->getCarrier() ? __('Delivered on:') : '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="empty" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Magento\Shipping\Block\Tracking\Popup" name="shipping.tracking.popup" template="Magento_Shipping::tracking/popup.phtml" cacheable="false" />
<block class="Magento\Shipping\Block\Tracking\Popup" name="shipping.tracking.popup" template="Magento_Shipping::tracking/popup.phtml" cacheable="false">
<arguments>
<argument name="delivery_date_title" xsi:type="object">Magento\Shipping\Block\DataProviders\Tracking\DeliveryDateTitle</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ $number = is_object($track) ? $track->getTracking() : $track['number'];

<?php if ($track->getDeliverydate()): ?>
<tr>
<th class="col label" scope="row"><?= $block->escapeHtml(__('Delivered on:')) ?></th>
<th class="col label" scope="row"><?= $block->escapeHtml($parentBlock->getDeliveryDateTitle()->getTitle($track)) ?></th>
<td class="col value">
<?= /* @noEscape */ $parentBlock->formatDeliveryDateTime($track->getDeliverydate(), $track->getDeliverytime()) ?>
</td>
Expand Down

0 comments on commit 697978e

Please sign in to comment.