Skip to content

Commit 5446b08

Browse files
author
Viktor Tymchynskyi
committed
Merge remote-tracking branch 'origin/MAGETWO-51789' into MPI-BUGFIXES
2 parents f4ae285 + 5e3615d commit 5446b08

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

app/code/Magento/Paypal/Model/Report/Settlement.php

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

99
namespace Magento\Paypal\Model\Report;
1010

11+
use DateTime;
1112
use Magento\Framework\Filesystem;
1213
use Magento\Framework\Filesystem\DirectoryList;
1314

@@ -162,6 +163,13 @@ class Settlement extends \Magento\Framework\Model\AbstractModel
162163
*/
163164
protected $_scopeConfig;
164165

166+
/**
167+
* Columns with DateTime data type
168+
*
169+
* @var array
170+
*/
171+
private $dateTimeColumns = ['transaction_initiation_date', 'transaction_completion_date'];
172+
165173
/**
166174
* @param \Magento\Framework\Model\Context $context
167175
* @param \Magento\Framework\Registry $registry
@@ -249,7 +257,8 @@ public function fetchAndSave(\Magento\Framework\Filesystem\Io\Sftp $connection)
249257

250258
// Set last modified date, this value will be overwritten during parsing
251259
if (isset($attributes['mtime'])) {
252-
$lastModified = new \DateTime($attributes['mtime']);
260+
$date = new \DateTime();
261+
$lastModified = $date->setTimestamp($attributes['mtime']);
253262
$this->setReportLastModified(
254263
$lastModified->format('Y-m-d H:i:s')
255264
);
@@ -324,7 +333,7 @@ public function parseCsv($localCsv, $format = 'new')
324333
$rowMap = $this->_csvColumns[$format]['rowmap'];
325334

326335
$flippedSectionColumns = array_flip($sectionColumns);
327-
$stream = $this->_tmpDirectory->openFile($localCsv);
336+
$stream = $this->_tmpDirectory->openFile($localCsv, 'r');
328337
while ($line = $stream->readCsv()) {
329338
if (empty($line)) {
330339
// The line was empty, so skip it.
@@ -360,11 +369,7 @@ public function parseCsv($localCsv, $format = 'new')
360369
break;
361370
case 'SB':
362371
// Section body.
363-
$bodyItem = [];
364-
for ($i = 1; $i < count($line); $i++) {
365-
$bodyItem[$rowMap[$flippedSectionColumns[$i]]] = $line[$i];
366-
}
367-
$this->_rows[] = $bodyItem;
372+
$this->_rows[] = $this->getBodyItems($line, $flippedSectionColumns, $rowMap);
368373
break;
369374
case 'SC':
370375
// Section records count.
@@ -385,6 +390,41 @@ public function parseCsv($localCsv, $format = 'new')
385390
return $this;
386391
}
387392

393+
/**
394+
* Parse columns from line of csv file
395+
*
396+
* @param array $line
397+
* @param array $sectionColumns
398+
* @param array $rowMap
399+
* @return array
400+
*/
401+
private function getBodyItems(array $line, array $sectionColumns, array $rowMap)
402+
{
403+
$bodyItem = [];
404+
for ($i = 1, $count = count($line); $i < $count; $i++) {
405+
if(isset($rowMap[$sectionColumns[$i]])) {
406+
if (in_array($rowMap[$sectionColumns[$i]], $this->dateTimeColumns)) {
407+
$line[$i] = $this->formatDateTimeColumns($line[$i]);
408+
}
409+
$bodyItem[$rowMap[$sectionColumns[$i]]] = $line[$i];
410+
}
411+
}
412+
return $bodyItem;
413+
}
414+
415+
/**
416+
* Format date columns in UTC
417+
*
418+
* @param string $lineItem
419+
* @return string
420+
*/
421+
private function formatDateTimeColumns($lineItem)
422+
{
423+
/** @var DateTime $date */
424+
$date = new DateTime($lineItem, new \DateTimeZone('UTC'));
425+
return $date->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
426+
}
427+
388428
/**
389429
* Load report by unique key (accoutn + report date)
390430
*

0 commit comments

Comments
 (0)