Skip to content

Commit ae76e04

Browse files
committed
MC-18248: Order Products Report Interval Date incorrect
1 parent 6874630 commit ae76e04

File tree

3 files changed

+31
-39
lines changed

3 files changed

+31
-39
lines changed

app/code/Magento/Reports/Block/Adminhtml/Grid.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,8 @@ protected function _prepareCollection()
172172
* Validate from and to date
173173
*/
174174
try {
175-
$from = $this->_localeDate->date($this->getFilter('report_from'), null, false, false);
176-
$to = $this->_localeDate->date($this->getFilter('report_to'), null, false, false);
177-
175+
$from = $this->_localeDate->date($this->getFilter('report_from'), null, true, false);
176+
$to = $this->_localeDate->date($this->getFilter('report_to'), null, true, false);
178177
$collection->setInterval($from, $to);
179178
} catch (\Exception $e) {
180179
$this->_errors[] = __('Invalid date specified');

app/code/Magento/Reports/Model/ResourceModel/Report/Collection.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ class Collection extends \Magento\Framework\Data\Collection
2020
/**
2121
* From value
2222
*
23-
* @var \DateTime
23+
* @var \DateTimeInterface
2424
*/
2525
protected $_from;
2626

2727
/**
2828
* To value
2929
*
30-
* @var \DateTime
30+
* @var \DateTimeInterface
3131
*/
3232
protected $_to;
3333

@@ -121,8 +121,8 @@ public function setPeriod($period)
121121
*/
122122
public function setInterval(\DateTimeInterface $fromDate, \DateTimeInterface $toDate)
123123
{
124-
$this->_from = new \DateTime($fromDate->format('Y-m-d'), $fromDate->getTimezone());
125-
$this->_to = new \DateTime($toDate->format('Y-m-d'), $toDate->getTimezone());
124+
$this->_from = $fromDate;
125+
$this->_to = $toDate;
126126

127127
return $this;
128128
}
@@ -139,8 +139,8 @@ protected function _getIntervals()
139139
if (!$this->_from && !$this->_to) {
140140
return $this->_intervals;
141141
}
142-
$dateStart = $this->_from;
143-
$dateEnd = $this->_to;
142+
$dateStart = new \DateTime($this->_from->format('Y-m-d'), $this->_from->getTimezone());
143+
$dateEnd = new \DateTime($this->_to->format('Y-m-d'), $this->_to->getTimezone());
144144

145145
$firstInterval = true;
146146
while ($dateStart <= $dateEnd) {
@@ -175,11 +175,7 @@ protected function _getIntervals()
175175
protected function _getDayInterval(\DateTime $dateStart)
176176
{
177177
$interval = [
178-
'period' => $this->_localeDate->formatDateTime(
179-
$dateStart,
180-
\IntlDateFormatter::SHORT,
181-
\IntlDateFormatter::NONE
182-
),
178+
'period' => $this->_localeDate->formatDate($dateStart, \IntlDateFormatter::SHORT),
183179
'start' => $this->_localeDate->convertConfigTimeToUtc($dateStart->format('Y-m-d 00:00:00')),
184180
'end' => $this->_localeDate->convertConfigTimeToUtc($dateStart->format('Y-m-d 23:59:59')),
185181
];

app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/CollectionTest.php

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,49 @@
66

77
namespace Magento\Reports\Test\Unit\Model\ResourceModel\Report;
88

9+
use Magento\Framework\Data\Collection\EntityFactory;
10+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
911
use Magento\Reports\Model\ResourceModel\Report\Collection;
12+
use Magento\Reports\Model\ResourceModel\Report\Collection\Factory as ReportCollectionFactory;
1013

14+
/**
15+
* Class CollectionTest
16+
*
17+
* @covers \Magento\Reports\Model\ResourceModel\Report\Collection
18+
*/
1119
class CollectionTest extends \PHPUnit\Framework\TestCase
1220
{
1321
/**
14-
* @var \Magento\Reports\Model\ResourceModel\Report\Collection
22+
* @var Collection
1523
*/
1624
protected $collection;
1725

1826
/**
19-
* @var \Magento\Framework\Data\Collection\EntityFactory|\PHPUnit_Framework_MockObject_MockObject
27+
* @var EntityFactory|\PHPUnit_Framework_MockObject_MockObject
2028
*/
2129
protected $entityFactoryMock;
2230

2331
/**
24-
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
32+
* @var TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
2533
*/
2634
protected $timezoneMock;
2735

2836
/**
29-
* @var \Magento\Reports\Model\ResourceModel\Report\Collection\Factory|\PHPUnit_Framework_MockObject_MockObject
37+
* @var ReportCollectionFactory|\PHPUnit_Framework_MockObject_MockObject
3038
*/
3139
protected $factoryMock;
3240

3341
/**
34-
* {@inheritDoc}
42+
* @inheritDoc
3543
*/
3644
protected function setUp()
3745
{
38-
$this->entityFactoryMock = $this->getMockBuilder(\Magento\Framework\Data\Collection\EntityFactory::class)
39-
->disableOriginalConstructor()
40-
->getMock();
41-
$this->timezoneMock = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class)
42-
->getMock();
43-
$this->factoryMock = $this->getMockBuilder(
44-
\Magento\Reports\Model\ResourceModel\Report\Collection\Factory::class
45-
)->disableOriginalConstructor()
46-
->getMock();
47-
48-
$this->timezoneMock
49-
->expects($this->any())
50-
->method('formatDateTime')
51-
->will($this->returnCallback([$this, 'formatDateTime']));
46+
$this->entityFactoryMock = $this->createMock(EntityFactory::class);
47+
$this->timezoneMock = $this->createMock(TimezoneInterface::class);
48+
$this->factoryMock = $this->createMock(ReportCollectionFactory::class);
49+
50+
$this->timezoneMock->method('formatDate')
51+
->will($this->returnCallback([$this, 'formatDate']));
5252

5353
$this->collection = new Collection(
5454
$this->entityFactoryMock,
@@ -131,7 +131,7 @@ public function testGetReports($period, $fromDate, $toDate, $size)
131131
public function testLoadData()
132132
{
133133
$this->assertInstanceOf(
134-
\Magento\Reports\Model\ResourceModel\Report\Collection::class,
134+
Collection::class,
135135
$this->collection->loadData()
136136
);
137137
}
@@ -182,14 +182,11 @@ public function intervalsDataProvider()
182182
}
183183

184184
/**
185+
* @param \DateTimeInterface $dateStart
185186
* @return string
186187
*/
187-
public function formatDateTime()
188+
public function formatDate(\DateTimeInterface $dateStart): string
188189
{
189-
$args = func_get_args();
190-
191-
$dateStart = $args[0];
192-
193190
$formatter = new \IntlDateFormatter(
194191
"en_US",
195192
\IntlDateFormatter::SHORT,

0 commit comments

Comments
 (0)