Skip to content

Commit 378ac7a

Browse files
authored
Merge pull request #898 from magento-mpi/MPI-bugfixes
[MPI] Bugfixes
2 parents 24f950d + 9e86f00 commit 378ac7a

File tree

19 files changed

+526
-40
lines changed

19 files changed

+526
-40
lines changed

app/code/Magento/Fedex/Model/Carrier.php

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,9 +1570,9 @@ private function processTrackingDetails(\stdClass $trackInfo)
15701570
'progressdetail' => [],
15711571
];
15721572

1573-
if (!empty($trackInfo->ShipTimestamp)) {
1574-
$datetime = \DateTime::createFromFormat(\DateTime::ISO8601, $trackInfo->ShipTimestamp);
1575-
$result['shippeddate'] = $datetime->format('Y-m-d');
1573+
$datetime = $this->parseDate(!empty($trackInfo->ShipTimestamp) ? $trackInfo->ShipTimestamp : null);
1574+
if ($datetime) {
1575+
$result['shippeddate'] = gmdate('Y-m-d', $datetime->getTimestamp());
15761576
}
15771577

15781578
$result['signedby'] = !empty($trackInfo->DeliverySignatureName) ?
@@ -1588,8 +1588,8 @@ private function processTrackingDetails(\stdClass $trackInfo)
15881588

15891589
$datetime = $this->getDeliveryDateTime($trackInfo);
15901590
if ($datetime) {
1591-
$result['deliverydate'] = $datetime->format('Y-m-d');
1592-
$result['deliverytime'] = $datetime->format('H:i:s');
1591+
$result['deliverydate'] = gmdate('Y-m-d', $datetime->getTimestamp());
1592+
$result['deliverytime'] = gmdate('H:i:s', $datetime->getTimestamp());
15931593
}
15941594

15951595
$address = null;
@@ -1636,7 +1636,7 @@ private function getDeliveryDateTime(\stdClass $trackInfo)
16361636
$timestamp = $trackInfo->ActualDeliveryTimestamp;
16371637
}
16381638

1639-
return $timestamp ? \DateTime::createFromFormat(\DateTime::ISO8601, $timestamp) : null;
1639+
return $timestamp ? $this->parseDate($timestamp) : null;
16401640
}
16411641

16421642
/**
@@ -1685,10 +1685,10 @@ private function processTrackDetailsEvents(array $events)
16851685
'deliverylocation' => null
16861686
];
16871687

1688-
if (!empty($event->Timestamp)) {
1689-
$datetime = \DateTime::createFromFormat(\DateTime::ISO8601, $event->Timestamp);
1690-
$item['deliverydate'] = $datetime->format('Y-m-d');
1691-
$item['deliverytime'] = $datetime->format('H:i:s');
1688+
$datetime = $this->parseDate(!empty($event->Timestamp) ? $event->Timestamp : null);
1689+
if ($datetime) {
1690+
$item['deliverydate'] = gmdate('Y-m-d', $datetime->getTimestamp());
1691+
$item['deliverytime'] = gmdate('H:i:s', $datetime->getTimestamp());
16921692
}
16931693

16941694
if (!empty($event->Address)) {
@@ -1716,4 +1716,30 @@ private function appendTrackingError($trackingValue, $errorMessage)
17161716
$result = $this->getResult();
17171717
$result->append($error);
17181718
}
1719+
1720+
/**
1721+
* Parses datetime string from FedEx response.
1722+
* According to FedEx API, datetime string should be in \DateTime::ATOM format, but
1723+
* sometimes FedEx returns datetime without timezone and in that case timezone will be set as UTC.
1724+
*
1725+
* @param string $timestamp
1726+
* @return bool|\DateTime
1727+
*/
1728+
private function parseDate($timestamp)
1729+
{
1730+
if ($timestamp === null) {
1731+
return false;
1732+
}
1733+
$formats = [\DateTime::ATOM, 'Y-m-d\TH:i:s'];
1734+
foreach ($formats as $format) {
1735+
// set UTC timezone for a case if timestamp does not contain any timezone
1736+
$utcTimezone = new \DateTimeZone('UTC');
1737+
$dateTime = \DateTime::createFromFormat($format, $timestamp, $utcTimezone);
1738+
if ($dateTime !== false) {
1739+
return $dateTime;
1740+
}
1741+
}
1742+
1743+
return false;
1744+
}
17191745
}

app/code/Magento/Fedex/Test/Unit/Model/CarrierTest.php

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,12 @@ public function testGetTrackingErrorResponse()
393393

394394
/**
395395
* @covers \Magento\Fedex\Model\Carrier::getTracking
396+
* @param string $shipTimeStamp
397+
* @param string $expectedDate
398+
* @param string $expectedTime
399+
* @dataProvider shipDateDataProvider
396400
*/
397-
public function testGetTracking()
401+
public function testGetTracking($shipTimeStamp, $expectedDate, $expectedTime)
398402
{
399403
$tracking = '123456789012';
400404

@@ -404,15 +408,15 @@ public function testGetTracking()
404408
$response->CompletedTrackDetails = new \stdClass();
405409

406410
$trackDetails = new \stdClass();
407-
$trackDetails->ShipTimestamp = '2016-08-05T14:06:35+00:00';
411+
$trackDetails->ShipTimestamp = $shipTimeStamp;
408412
$trackDetails->DeliverySignatureName = 'signature';
409413

410414
$trackDetails->StatusDetail = new \stdClass();
411415
$trackDetails->StatusDetail->Description = 'SUCCESS';
412416

413417
$trackDetails->Service = new \stdClass();
414418
$trackDetails->Service->Description = 'ground';
415-
$trackDetails->EstimatedDeliveryTimestamp = '2016-08-10T10:20:26+00:00';
419+
$trackDetails->EstimatedDeliveryTimestamp = $shipTimeStamp;
416420

417421
$trackDetails->EstimatedDeliveryAddress = new \stdClass();
418422
$trackDetails->EstimatedDeliveryAddress->City = 'Culver City';
@@ -444,25 +448,44 @@ public function testGetTracking()
444448
'signedby',
445449
'status',
446450
'service',
447-
'shippeddate',
448-
'deliverydate',
449-
'deliverytime',
450451
'deliverylocation',
451452
'weight',
452453
];
453454
array_walk($fields, function ($field) use ($current) {
454455
static::assertNotEmpty($current[$field]);
455456
});
456457

457-
static::assertEquals('2016-08-10', $current['deliverydate']);
458-
static::assertEquals('10:20:26', $current['deliverytime']);
459-
static::assertEquals('2016-08-05', $current['shippeddate']);
458+
static::assertEquals($expectedDate, $current['deliverydate']);
459+
static::assertEquals($expectedTime, $current['deliverytime']);
460+
static::assertEquals($expectedDate, $current['shippeddate']);
461+
}
462+
463+
/**
464+
* Gets list of variations for testing ship date.
465+
*
466+
* @return array
467+
*/
468+
public function shipDateDataProvider()
469+
{
470+
return [
471+
['shipTimestamp' => '2016-08-05T14:06:35+01:00', 'expectedDate' => '2016-08-05', '13:06:35'],
472+
['shipTimestamp' => '2016-08-05T02:06:35+03:00', 'expectedDate' => '2016-08-04', '23:06:35'],
473+
['shipTimestamp' => '2016-08-05T14:06:35', 'expectedDate' => '2016-08-05', '14:06:35'],
474+
['shipTimestamp' => '2016-08-05 14:06:35', 'expectedDate' => null, null],
475+
['shipTimestamp' => '2016-08-05 14:06:35+00:00', 'expectedDate' => null, null],
476+
['shipTimestamp' => '2016-08-05', 'expectedDate' => null, null],
477+
['shipTimestamp' => '2016/08/05', 'expectedDate' => null, null],
478+
];
460479
}
461480

462481
/**
463482
* @covers \Magento\Fedex\Model\Carrier::getTracking
483+
* @param string $shipTimeStamp
484+
* @param string $expectedDate
485+
* @param string $expectedTime
486+
* @dataProvider shipDateDataProvider
464487
*/
465-
public function testGetTrackingWithEvents()
488+
public function testGetTrackingWithEvents($shipTimeStamp, $expectedDate, $expectedTime)
466489
{
467490
$tracking = '123456789012';
468491

@@ -473,7 +496,7 @@ public function testGetTrackingWithEvents()
473496

474497
$event = new \stdClass();
475498
$event->EventDescription = 'Test';
476-
$event->Timestamp = '2016-08-05T19:14:53+00:00';
499+
$event->Timestamp = $shipTimeStamp;
477500
$event->Address = new \stdClass();
478501

479502
$event->Address->City = 'Culver City';
@@ -504,12 +527,12 @@ public function testGetTrackingWithEvents()
504527
static::assertEquals(1, count($current['progressdetail']));
505528

506529
$event = $current['progressdetail'][0];
507-
$fields = ['activity', 'deliverydate', 'deliverytime', 'deliverylocation'];
530+
$fields = ['activity', 'deliverylocation'];
508531
array_walk($fields, function ($field) use ($event) {
509532
static::assertNotEmpty($event[$field]);
510533
});
511-
static::assertEquals('2016-08-05', $event['deliverydate']);
512-
static::assertEquals('19:14:53', $event['deliverytime']);
534+
static::assertEquals($expectedDate, $event['deliverydate']);
535+
static::assertEquals($expectedTime, $event['deliverytime']);
513536
}
514537

515538
/**

app/code/Magento/Payment/view/base/web/js/model/credit-card-validation/validator.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
} else {
2020
factory(jQuery);
2121
}
22-
}(function ($, cvvValidator, creditCardNumberValidator, expirationDateValidator, monthValidator, creditCardData) {
22+
}(function ($, cvvValidator, creditCardNumberValidator, yearValidator, monthValidator, creditCardData) {
2323
'use strict';
2424

2525
$.each({
@@ -49,6 +49,7 @@
4949

5050
/**
5151
* Validate credit card number based on mod 10
52+
*
5253
* @param {*} number - credit card number
5354
* @return {Boolean}
5455
*/
@@ -60,8 +61,9 @@
6061
'validate-card-date': [
6162

6263
/**
63-
* Validate credit card number based on mod 10
64-
* @param {*} date - month
64+
* Validate credit card expiration month
65+
*
66+
* @param {String} date - month
6567
* @return {Boolean}
6668
*/
6769
function (date) {
@@ -72,8 +74,9 @@
7274
'validate-card-cvv': [
7375

7476
/**
75-
* Validate credit card number based on mod 10
76-
* @param {*} cvv - month
77+
* Validate cvv
78+
*
79+
* @param {String} cvv - card verification value
7780
* @return {Boolean}
7881
*/
7982
function (cvv) {
@@ -86,12 +89,13 @@
8689
'validate-card-year': [
8790

8891
/**
89-
* Validate credit card number based on mod 10
90-
* @param {*} date - month
92+
* Validate credit card expiration year
93+
*
94+
* @param {String} date - year
9195
* @return {Boolean}
9296
*/
9397
function (date) {
94-
return monthValidator(date).isValid;
98+
return yearValidator(date).isValid;
9599
},
96100
$.mage.__('Incorrect credit card expiration year.')
97101
]

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/** @var $block \Magento\Framework\View\Element\Template */
1010

11+
$parentBlock = $block->getParentBlock();
1112
$track = $block->getData('track');
1213
$email = $block->getData('storeSupportEmail');
1314
$fields = [
@@ -18,14 +19,15 @@ $fields = [
1819
'Service Type' => 'getService',
1920
'Weight' => 'getWeight',
2021
];
22+
$number = is_object($track) ? $track->getTracking() : $track['number'];
2123
?>
22-
<table class="data table order tracking" id="tracking-table-popup-<?php /* @noEscape */ echo $track->getTracking(); ?>">
24+
<table class="data table order tracking" id="tracking-table-popup-<?php /* @noEscape */ echo $number; ?>">
2325
<caption class="table-caption"><?php echo $block->escapeHtml(__('Order tracking')); ?></caption>
2426
<tbody>
2527
<?php if (is_object($track)): ?>
2628
<tr>
2729
<th class="col label" scope="row"><?php echo $block->escapeHtml(__('Tracking Number:')); ?></th>
28-
<td class="col value"><?php echo $block->escapeHtml($track->getTracking()); ?></td>
30+
<td class="col value"><?php echo $block->escapeHtml($number); ?></td>
2931
</tr>
3032
<?php if ($track->getCarrierTitle()): ?>
3133
<tr>
@@ -38,8 +40,8 @@ $fields = [
3840
<th class="col label" scope="row"><?php echo $block->escapeHtml(__('Error:')); ?></th>
3941
<td class="col error">
4042
<?php echo $block->escapeHtml(__('Tracking information is currently not available. Please ')); ?>
41-
<?php if ($block->getContactUsEnabled()) : ?>
42-
<a href="<?php echo $block->escapeUrl($block->getContactUs()); ?>" target="_blank"
43+
<?php if ($parentBlock->getContactUsEnabled()) : ?>
44+
<a href="<?php echo $block->escapeUrl($parentBlock->getContactUs()); ?>" target="_blank"
4345
title="<?php echo $block->escapeHtml(__('contact us')); ?>">
4446
<?php echo $block->escapeHtml(__('contact us')); ?>
4547
</a>
@@ -77,7 +79,7 @@ $fields = [
7779
<tr>
7880
<th class="col label" scope="row"><?php echo $block->escapeHtml(__('Delivered on:')); ?></th>
7981
<td class="col value">
80-
<?php /* @noEscape */ echo $block->formatDeliveryDateTime($track->getDeliverydate(), $track->getDeliverytime()); ?>
82+
<?php /* @noEscape */ echo $parentBlock->formatDeliveryDateTime($track->getDeliverydate(), $track->getDeliverytime()); ?>
8183
</td>
8284
</tr>
8385
<?php endif; ?>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $results = $block->getTrackingInfo();
3131
?>
3232
<?php /* @noEscape */ echo $block->getChildHtml('shipping.tracking.details.' . $counter); ?>
3333
</div>
34-
<?php if (!empty($track->getProgressdetail())): ?>
34+
<?php if (is_object($track) && !empty($track->getProgressdetail())): ?>
3535
<?php
3636
$block->addChild('shipping.tracking.progress.'. $counter, Template::class, [
3737
'track' => $track,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// @codingStandardsIgnoreFile
88

99
/** @var $block \Magento\Framework\View\Element\Template */
10+
$parentBlock = $block->getParentBlock();
1011
$track = $block->getData('track');
1112
?>
1213
<div class="table-wrapper">
@@ -22,8 +23,8 @@ $track = $block->getData('track');
2223
</thead>
2324
<tbody>
2425
<?php foreach ($track->getProgressdetail() as $detail): ?>
25-
<?php $detailDate = (!empty($detail['deliverydate']) ? $block->formatDeliveryDate($detail['deliverydate']) : ''); ?>
26-
<?php $detailTime = (!empty($detail['deliverytime']) ? $block->formatDeliveryTime($detail['deliverytime'], $detail['deliverydate']) : ''); ?>
26+
<?php $detailDate = (!empty($detail['deliverydate']) ? $parentBlock->formatDeliveryDate($detail['deliverydate']) : ''); ?>
27+
<?php $detailTime = (!empty($detail['deliverytime']) ? $parentBlock->formatDeliveryTime($detail['deliverytime'], $detail['deliverydate']) : ''); ?>
2728
<tr>
2829
<td data-th="<?php echo $block->escapeHtml(__('Location')); ?>" class="col location">
2930
<?php echo(!empty($detail['deliverylocation']) ? $block->escapeHtml($detail['deliverylocation']) : ''); ?>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\Shipping\Test\TestCase\TrackingShipmentForPlacedOrderTest" summary="Create shipment for order with FedEx shipping method.">
10+
<variation name="TrackingFedExShipmentForPlacedOrderTestVariation1" summary="Creating shipment for order placed within FedEx." ticketId="MAGETWO-58158">
11+
<data name="products/0" xsi:type="string">catalogProductSimple::product_10_dollar</data>
12+
<data name="customer/dataset" xsi:type="string">default</data>
13+
<data name="shippingAddress/dataset" xsi:type="string">US_address_1_without_email</data>
14+
<data name="checkoutMethod" xsi:type="string">login</data>
15+
<data name="shipping/shipping_service" xsi:type="string">Federal Express</data>
16+
<data name="shipping/shipping_method" xsi:type="string">Smart Post</data>
17+
<data name="cart/data/shipping_method" xsi:type="string">Smart Post</data>
18+
<data name="payment/method" xsi:type="string">checkmo</data>
19+
<data name="configData" xsi:type="string">checkmo, fedex, shipping_origin_US_CA</data>
20+
<data name="trackingData" xsi:type="array">
21+
<item name="carrier" xsi:type="string">Federal Express</item>
22+
<item name="carrier_title" xsi:type="string">Federal Express</item>
23+
<item name="tracking_number" xsi:type="string">449044304137821</item>
24+
</data>
25+
<data name="resultTrackingData" xsi:type="array">
26+
<item name="number" xsi:type="string">449044304137821</item>
27+
</data>
28+
<data name="tag" xsi:type="string">test_type:3rd_party_test, severity:S1</data>
29+
<constraint name="Magento\Shipping\Test\Constraint\AssertTrackingDetailsIsPresent" />
30+
</variation>
31+
</testCase>
32+
</config>

dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Sales\Test\Block\Adminhtml\Order\View\Tab;
88

99
use Magento\Backend\Test\Block\Widget\Tab;
10+
use Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Info\ShippingInfoBlock;
1011
use Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Info\CommentsHistoryBlock;
1112
use Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Info\PaymentInfoBlock;
1213

@@ -29,6 +30,13 @@ class Info extends Tab
2930
*/
3031
private $paymentInfoBlockSelector = '.order-payment-method';
3132

33+
/**
34+
* Selector for `Shipping Information` block.
35+
*
36+
* @var string
37+
*/
38+
private $shippingInfoBlock = '.order-shipping-method';
39+
3240
/**
3341
* Selector for Comments history block.
3442
*
@@ -59,6 +67,19 @@ public function getPaymentInfoBlock()
5967
);
6068
}
6169

70+
/**
71+
* Gets Order Shipping Information block.
72+
*
73+
* @return ShippingInfoBlock
74+
*/
75+
public function getShippingInfoBlock()
76+
{
77+
return $this->blockFactory->create(
78+
ShippingInfoBlock::class,
79+
['element' => $this->_rootElement->find($this->shippingInfoBlock)]
80+
);
81+
}
82+
6283
/**
6384
* Returns Comments history block.
6485
*

0 commit comments

Comments
 (0)