Skip to content

Commit ed0c0c4

Browse files
committed
MAGETWO-57460: [Backport] - Exception occurs when tracking shipment with invalid FedEx tracking number - for 2.1.x
- Added more validation for shipTimestamp
1 parent ec1884b commit ed0c0c4

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,8 +1561,9 @@ private function processTrackingDetails(\stdClass $trackInfo)
15611561
'progressdetail' => [],
15621562
];
15631563

1564-
if (!empty($trackInfo->ShipTimestamp)) {
1565-
$datetime = \DateTime::createFromFormat(\DateTime::ISO8601, $trackInfo->ShipTimestamp);
1564+
if (!empty($trackInfo->ShipTimestamp) &&
1565+
($datetime = \DateTime::createFromFormat(\DateTime::ISO8601, $trackInfo->ShipTimestamp)) !== false
1566+
) {
15661567
$result['shippeddate'] = $datetime->format('Y-m-d');
15671568
}
15681569

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,11 @@ public function testGetTrackingErrorResponse()
363363

364364
/**
365365
* @covers \Magento\Fedex\Model\Carrier::getTracking
366+
* @param string $shipTimestamp
367+
* @param string $expectedDate
368+
* @dataProvider shipDateDataProvider
366369
*/
367-
public function testGetTracking()
370+
public function testGetTracking($shipTimestamp, $expectedDate)
368371
{
369372
$tracking = '123456789012';
370373

@@ -374,7 +377,7 @@ public function testGetTracking()
374377
$response->CompletedTrackDetails = new \stdClass();
375378

376379
$trackDetails = new \stdClass();
377-
$trackDetails->ShipTimestamp = '2016-08-05T14:06:35+00:00';
380+
$trackDetails->ShipTimestamp = $shipTimestamp;
378381
$trackDetails->DeliverySignatureName = 'signature';
379382

380383
$trackDetails->StatusDetail = new \stdClass();
@@ -414,7 +417,6 @@ public function testGetTracking()
414417
'signedby',
415418
'status',
416419
'service',
417-
'shippeddate',
418420
'deliverydate',
419421
'deliverytime',
420422
'deliverylocation',
@@ -426,7 +428,23 @@ public function testGetTracking()
426428

427429
static::assertEquals('2016-08-10', $current['deliverydate']);
428430
static::assertEquals('10:20:26', $current['deliverytime']);
429-
static::assertEquals('2016-08-05', $current['shippeddate']);
431+
static::assertEquals($expectedDate, $current['shippeddate']);
432+
}
433+
434+
/**
435+
* Get list of variations for testing ship date
436+
* @return array
437+
*/
438+
public function shipDateDataProvider()
439+
{
440+
return [
441+
['shipTimestamp' => '2016-08-05T14:06:35+00:00', 'expectedDate' => '2016-08-05'],
442+
['shipTimestamp' => '2016-08-05T14:06:35', 'expectedDate' => null],
443+
['shipTimestamp' => '2016-08-05 14:06:35', 'expectedDate' => null],
444+
['shipTimestamp' => '2016-08-05 14:06:35+00:00', 'expectedDate' => null],
445+
['shipTimestamp' => '2016-08-05', 'expectedDate' => null],
446+
['shipTimestamp' => '2016/08/05', 'expectedDate' => null],
447+
];
430448
}
431449

432450
/**

0 commit comments

Comments
 (0)