Skip to content

Commit

Permalink
Merge pull request #898 from magento-mpi/MPI-bugfixes
Browse files Browse the repository at this point in the history
[MPI] Bugfixes
  • Loading branch information
kandy authored Mar 14, 2017
2 parents 24f950d + 9e86f00 commit 378ac7a
Show file tree
Hide file tree
Showing 19 changed files with 526 additions and 40 deletions.
46 changes: 36 additions & 10 deletions app/code/Magento/Fedex/Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -1570,9 +1570,9 @@ private function processTrackingDetails(\stdClass $trackInfo)
'progressdetail' => [],
];

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

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

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

$address = null;
Expand Down Expand Up @@ -1636,7 +1636,7 @@ private function getDeliveryDateTime(\stdClass $trackInfo)
$timestamp = $trackInfo->ActualDeliveryTimestamp;
}

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

/**
Expand Down Expand Up @@ -1685,10 +1685,10 @@ private function processTrackDetailsEvents(array $events)
'deliverylocation' => null
];

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

if (!empty($event->Address)) {
Expand Down Expand Up @@ -1716,4 +1716,30 @@ private function appendTrackingError($trackingValue, $errorMessage)
$result = $this->getResult();
$result->append($error);
}

/**
* Parses datetime string from FedEx response.
* According to FedEx API, datetime string should be in \DateTime::ATOM format, but
* sometimes FedEx returns datetime without timezone and in that case timezone will be set as UTC.
*
* @param string $timestamp
* @return bool|\DateTime
*/
private function parseDate($timestamp)
{
if ($timestamp === null) {
return false;
}
$formats = [\DateTime::ATOM, 'Y-m-d\TH:i:s'];
foreach ($formats as $format) {
// set UTC timezone for a case if timestamp does not contain any timezone
$utcTimezone = new \DateTimeZone('UTC');
$dateTime = \DateTime::createFromFormat($format, $timestamp, $utcTimezone);
if ($dateTime !== false) {
return $dateTime;
}
}

return false;
}
}
51 changes: 37 additions & 14 deletions app/code/Magento/Fedex/Test/Unit/Model/CarrierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,12 @@ public function testGetTrackingErrorResponse()

/**
* @covers \Magento\Fedex\Model\Carrier::getTracking
* @param string $shipTimeStamp
* @param string $expectedDate
* @param string $expectedTime
* @dataProvider shipDateDataProvider
*/
public function testGetTracking()
public function testGetTracking($shipTimeStamp, $expectedDate, $expectedTime)
{
$tracking = '123456789012';

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

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

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

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

$trackDetails->EstimatedDeliveryAddress = new \stdClass();
$trackDetails->EstimatedDeliveryAddress->City = 'Culver City';
Expand Down Expand Up @@ -444,25 +448,44 @@ public function testGetTracking()
'signedby',
'status',
'service',
'shippeddate',
'deliverydate',
'deliverytime',
'deliverylocation',
'weight',
];
array_walk($fields, function ($field) use ($current) {
static::assertNotEmpty($current[$field]);
});

static::assertEquals('2016-08-10', $current['deliverydate']);
static::assertEquals('10:20:26', $current['deliverytime']);
static::assertEquals('2016-08-05', $current['shippeddate']);
static::assertEquals($expectedDate, $current['deliverydate']);
static::assertEquals($expectedTime, $current['deliverytime']);
static::assertEquals($expectedDate, $current['shippeddate']);
}

/**
* Gets list of variations for testing ship date.
*
* @return array
*/
public function shipDateDataProvider()
{
return [
['shipTimestamp' => '2016-08-05T14:06:35+01:00', 'expectedDate' => '2016-08-05', '13:06:35'],
['shipTimestamp' => '2016-08-05T02:06:35+03:00', 'expectedDate' => '2016-08-04', '23:06:35'],
['shipTimestamp' => '2016-08-05T14:06:35', 'expectedDate' => '2016-08-05', '14:06:35'],
['shipTimestamp' => '2016-08-05 14:06:35', 'expectedDate' => null, null],
['shipTimestamp' => '2016-08-05 14:06:35+00:00', 'expectedDate' => null, null],
['shipTimestamp' => '2016-08-05', 'expectedDate' => null, null],
['shipTimestamp' => '2016/08/05', 'expectedDate' => null, null],
];
}

/**
* @covers \Magento\Fedex\Model\Carrier::getTracking
* @param string $shipTimeStamp
* @param string $expectedDate
* @param string $expectedTime
* @dataProvider shipDateDataProvider
*/
public function testGetTrackingWithEvents()
public function testGetTrackingWithEvents($shipTimeStamp, $expectedDate, $expectedTime)
{
$tracking = '123456789012';

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

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

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

$event = $current['progressdetail'][0];
$fields = ['activity', 'deliverydate', 'deliverytime', 'deliverylocation'];
$fields = ['activity', 'deliverylocation'];
array_walk($fields, function ($field) use ($event) {
static::assertNotEmpty($event[$field]);
});
static::assertEquals('2016-08-05', $event['deliverydate']);
static::assertEquals('19:14:53', $event['deliverytime']);
static::assertEquals($expectedDate, $event['deliverydate']);
static::assertEquals($expectedTime, $event['deliverytime']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
} else {
factory(jQuery);
}
}(function ($, cvvValidator, creditCardNumberValidator, expirationDateValidator, monthValidator, creditCardData) {
}(function ($, cvvValidator, creditCardNumberValidator, yearValidator, monthValidator, creditCardData) {
'use strict';

$.each({
Expand Down Expand Up @@ -49,6 +49,7 @@

/**
* Validate credit card number based on mod 10
*
* @param {*} number - credit card number
* @return {Boolean}
*/
Expand All @@ -60,8 +61,9 @@
'validate-card-date': [

/**
* Validate credit card number based on mod 10
* @param {*} date - month
* Validate credit card expiration month
*
* @param {String} date - month
* @return {Boolean}
*/
function (date) {
Expand All @@ -72,8 +74,9 @@
'validate-card-cvv': [

/**
* Validate credit card number based on mod 10
* @param {*} cvv - month
* Validate cvv
*
* @param {String} cvv - card verification value
* @return {Boolean}
*/
function (cvv) {
Expand All @@ -86,12 +89,13 @@
'validate-card-year': [

/**
* Validate credit card number based on mod 10
* @param {*} date - month
* Validate credit card expiration year
*
* @param {String} date - year
* @return {Boolean}
*/
function (date) {
return monthValidator(date).isValid;
return yearValidator(date).isValid;
},
$.mage.__('Incorrect credit card expiration year.')
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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

$parentBlock = $block->getParentBlock();
$track = $block->getData('track');
$email = $block->getData('storeSupportEmail');
$fields = [
Expand All @@ -18,14 +19,15 @@ $fields = [
'Service Type' => 'getService',
'Weight' => 'getWeight',
];
$number = is_object($track) ? $track->getTracking() : $track['number'];
?>
<table class="data table order tracking" id="tracking-table-popup-<?php /* @noEscape */ echo $track->getTracking(); ?>">
<table class="data table order tracking" id="tracking-table-popup-<?php /* @noEscape */ echo $number; ?>">
<caption class="table-caption"><?php echo $block->escapeHtml(__('Order tracking')); ?></caption>
<tbody>
<?php if (is_object($track)): ?>
<tr>
<th class="col label" scope="row"><?php echo $block->escapeHtml(__('Tracking Number:')); ?></th>
<td class="col value"><?php echo $block->escapeHtml($track->getTracking()); ?></td>
<td class="col value"><?php echo $block->escapeHtml($number); ?></td>
</tr>
<?php if ($track->getCarrierTitle()): ?>
<tr>
Expand All @@ -38,8 +40,8 @@ $fields = [
<th class="col label" scope="row"><?php echo $block->escapeHtml(__('Error:')); ?></th>
<td class="col error">
<?php echo $block->escapeHtml(__('Tracking information is currently not available. Please ')); ?>
<?php if ($block->getContactUsEnabled()) : ?>
<a href="<?php echo $block->escapeUrl($block->getContactUs()); ?>" target="_blank"
<?php if ($parentBlock->getContactUsEnabled()) : ?>
<a href="<?php echo $block->escapeUrl($parentBlock->getContactUs()); ?>" target="_blank"
title="<?php echo $block->escapeHtml(__('contact us')); ?>">
<?php echo $block->escapeHtml(__('contact us')); ?>
</a>
Expand Down Expand Up @@ -77,7 +79,7 @@ $fields = [
<tr>
<th class="col label" scope="row"><?php echo $block->escapeHtml(__('Delivered on:')); ?></th>
<td class="col value">
<?php /* @noEscape */ echo $block->formatDeliveryDateTime($track->getDeliverydate(), $track->getDeliverytime()); ?>
<?php /* @noEscape */ echo $parentBlock->formatDeliveryDateTime($track->getDeliverydate(), $track->getDeliverytime()); ?>
</td>
</tr>
<?php endif; ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ $results = $block->getTrackingInfo();
?>
<?php /* @noEscape */ echo $block->getChildHtml('shipping.tracking.details.' . $counter); ?>
</div>
<?php if (!empty($track->getProgressdetail())): ?>
<?php if (is_object($track) && !empty($track->getProgressdetail())): ?>
<?php
$block->addChild('shipping.tracking.progress.'. $counter, Template::class, [
'track' => $track,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// @codingStandardsIgnoreFile

/** @var $block \Magento\Framework\View\Element\Template */
$parentBlock = $block->getParentBlock();
$track = $block->getData('track');
?>
<div class="table-wrapper">
Expand All @@ -22,8 +23,8 @@ $track = $block->getData('track');
</thead>
<tbody>
<?php foreach ($track->getProgressdetail() as $detail): ?>
<?php $detailDate = (!empty($detail['deliverydate']) ? $block->formatDeliveryDate($detail['deliverydate']) : ''); ?>
<?php $detailTime = (!empty($detail['deliverytime']) ? $block->formatDeliveryTime($detail['deliverytime'], $detail['deliverydate']) : ''); ?>
<?php $detailDate = (!empty($detail['deliverydate']) ? $parentBlock->formatDeliveryDate($detail['deliverydate']) : ''); ?>
<?php $detailTime = (!empty($detail['deliverytime']) ? $parentBlock->formatDeliveryTime($detail['deliverytime'], $detail['deliverydate']) : ''); ?>
<tr>
<td data-th="<?php echo $block->escapeHtml(__('Location')); ?>" class="col location">
<?php echo(!empty($detail['deliverylocation']) ? $block->escapeHtml($detail['deliverylocation']) : ''); ?>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
<testCase name="Magento\Shipping\Test\TestCase\TrackingShipmentForPlacedOrderTest" summary="Create shipment for order with FedEx shipping method.">
<variation name="TrackingFedExShipmentForPlacedOrderTestVariation1" summary="Creating shipment for order placed within FedEx." ticketId="MAGETWO-58158">
<data name="products/0" xsi:type="string">catalogProductSimple::product_10_dollar</data>
<data name="customer/dataset" xsi:type="string">default</data>
<data name="shippingAddress/dataset" xsi:type="string">US_address_1_without_email</data>
<data name="checkoutMethod" xsi:type="string">login</data>
<data name="shipping/shipping_service" xsi:type="string">Federal Express</data>
<data name="shipping/shipping_method" xsi:type="string">Smart Post</data>
<data name="cart/data/shipping_method" xsi:type="string">Smart Post</data>
<data name="payment/method" xsi:type="string">checkmo</data>
<data name="configData" xsi:type="string">checkmo, fedex, shipping_origin_US_CA</data>
<data name="trackingData" xsi:type="array">
<item name="carrier" xsi:type="string">Federal Express</item>
<item name="carrier_title" xsi:type="string">Federal Express</item>
<item name="tracking_number" xsi:type="string">449044304137821</item>
</data>
<data name="resultTrackingData" xsi:type="array">
<item name="number" xsi:type="string">449044304137821</item>
</data>
<data name="tag" xsi:type="string">test_type:3rd_party_test, severity:S1</data>
<constraint name="Magento\Shipping\Test\Constraint\AssertTrackingDetailsIsPresent" />
</variation>
</testCase>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\Sales\Test\Block\Adminhtml\Order\View\Tab;

use Magento\Backend\Test\Block\Widget\Tab;
use Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Info\ShippingInfoBlock;
use Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Info\CommentsHistoryBlock;
use Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Info\PaymentInfoBlock;

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

/**
* Selector for `Shipping Information` block.
*
* @var string
*/
private $shippingInfoBlock = '.order-shipping-method';

/**
* Selector for Comments history block.
*
Expand Down Expand Up @@ -59,6 +67,19 @@ public function getPaymentInfoBlock()
);
}

/**
* Gets Order Shipping Information block.
*
* @return ShippingInfoBlock
*/
public function getShippingInfoBlock()
{
return $this->blockFactory->create(
ShippingInfoBlock::class,
['element' => $this->_rootElement->find($this->shippingInfoBlock)]
);
}

/**
* Returns Comments history block.
*
Expand Down
Loading

0 comments on commit 378ac7a

Please sign in to comment.