Skip to content

Commit ea7b254

Browse files
author
Ganin, Roman(rganin)
committed
Merge pull request #327 from magento-troll/sprint37
[Troll] Bugfixes
2 parents 932b845 + 8192379 commit ea7b254

File tree

16 files changed

+19
-96
lines changed

16 files changed

+19
-96
lines changed

app/code/Magento/Reports/Model/Resource/Order/Collection.php

-3
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,6 @@ public function getDateRange($range, $customStart, $customEnd, $returnObjects =
457457
break;
458458
}
459459

460-
$dateStart->setTimezone(new \DateTimeZone('Etc/UTC'));
461-
$dateEnd->setTimezone(new \DateTimeZone('Etc/UTC'));
462-
463460
if ($returnObjects) {
464461
return [$dateStart, $dateEnd];
465462
} else {

app/code/Magento/Reports/Model/Resource/Report/AbstractReport.php

-33
Original file line numberDiff line numberDiff line change
@@ -465,37 +465,4 @@ protected function _getTZOffsetTransitions($timezone, $from = null, $to = null)
465465

466466
return $tzTransitions;
467467
}
468-
469-
/**
470-
* Retrieve store timezone offset from UTC in the form acceptable by SQL's CONVERT_TZ()
471-
*
472-
* @param null|mixed $store
473-
* @return string
474-
*/
475-
protected function _getStoreTimezoneUtcOffset($store = null)
476-
{
477-
return $this->_localeDate->scopeDate($store)->format('P');
478-
}
479-
480-
/**
481-
* Retrieve date in UTC timezone
482-
*
483-
* @param mixed $date
484-
* @return null|\DateTime
485-
*/
486-
protected function _dateToUtc($date)
487-
{
488-
if ($date === null) {
489-
return null;
490-
}
491-
492-
if ($date instanceof \DateTimeInterface) {
493-
$dateUtc = $date;
494-
} else {
495-
$dateUtc = new \DateTime($date);
496-
}
497-
498-
$dateUtc->setTimezone(new \DateTimeZone('UTC'));
499-
return $dateUtc->format('Y-m-d H:i:s');
500-
}
501468
}

app/code/Magento/Reports/Model/Resource/Report/Product/Viewed.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ public function aggregate($from = null, $to = null)
9898
$mainTable = $this->getMainTable();
9999
$adapter = $this->_getWriteAdapter();
100100

101-
// convert input dates to UTC to be comparable with DATETIME fields in DB
102-
$from = $this->_dateToUtc($from);
103-
$to = $this->_dateToUtc($to);
104-
105101
if ($from !== null || $to !== null) {
106102
$subSelect = $this->_getTableDateRangeSelect(
107103
$this->getTable('report_event'),
@@ -114,7 +110,7 @@ public function aggregate($from = null, $to = null)
114110
$subSelect = null;
115111
}
116112
$this->_clearTableByDateRange($mainTable, $from, $to, $subSelect);
117-
// convert dates from UTC to current admin timezone
113+
// convert dates to current admin timezone
118114
$periodExpr = $adapter->getDatePartSql(
119115
$this->getStoreTZOffsetQuery(
120116
['source_table' => $this->getTable('report_event')],

app/code/Magento/Sales/Model/Resource/Report/Bestsellers.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ protected function _construct()
9696
*/
9797
public function aggregate($from = null, $to = null)
9898
{
99-
// convert input dates to UTC to be comparable with DATETIME fields in DB
100-
$from = $this->_dateToUtc($from);
101-
$to = $this->_dateToUtc($to);
102-
10399
$adapter = $this->_getWriteAdapter();
104100
//$this->_getWriteAdapter()->beginTransaction();
105101

@@ -117,7 +113,7 @@ public function aggregate($from = null, $to = null)
117113
}
118114

119115
$this->_clearTableByDateRange($this->getMainTable(), $from, $to, $subSelect);
120-
// convert dates from UTC to current admin timezone
116+
// convert dates to current admin timezone
121117
$periodExpr = $adapter->getDatePartSql(
122118
$this->getStoreTZOffsetQuery(
123119
['source_table' => $this->getTable('sales_order')],

app/code/Magento/Sales/Model/Resource/Report/Invoiced.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ protected function _construct()
3131
*/
3232
public function aggregate($from = null, $to = null)
3333
{
34-
// convert input dates to UTC to be comparable with DATETIME fields in DB
35-
$from = $this->_dateToUtc($from);
36-
$to = $this->_dateToUtc($to);
37-
3834
$this->_aggregateByOrderCreatedAt($from, $to);
3935
$this->_aggregateByInvoiceCreatedAt($from, $to);
4036

@@ -76,7 +72,7 @@ protected function _aggregateByInvoiceCreatedAt($from, $to)
7672
}
7773

7874
$this->_clearTableByDateRange($table, $from, $to, $subSelect);
79-
// convert dates from UTC to current admin timezone
75+
// convert dates to current admin timezone
8076
$periodExpr = $adapter->getDatePartSql(
8177
$this->getStoreTZOffsetQuery(
8278
['source_table' => $sourceTable],
@@ -187,7 +183,7 @@ protected function _aggregateByOrderCreatedAt($from, $to)
187183
}
188184

189185
$this->_clearTableByDateRange($table, $from, $to, $subSelect);
190-
// convert dates from UTC to current admin timezone
186+
// convert dates to current admin timezone
191187
$periodExpr = $adapter->getDatePartSql($this->getStoreTZOffsetQuery($sourceTable, 'created_at', $from, $to));
192188

193189
$columns = [

app/code/Magento/Sales/Model/Resource/Report/Order/Createdat.php

-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ public function aggregate($from = null, $to = null)
4747
*/
4848
protected function _aggregateByField($aggregationField, $from, $to)
4949
{
50-
// convert input dates to UTC to be comparable with DATETIME fields in DB
51-
$from = $this->_dateToUtc($from);
52-
$to = $this->_dateToUtc($to);
53-
5450
$adapter = $this->_getWriteAdapter();
5551

5652
$adapter->beginTransaction();

app/code/Magento/Sales/Model/Resource/Report/Refunded.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ protected function _construct()
3131
*/
3232
public function aggregate($from = null, $to = null)
3333
{
34-
// convert input dates to UTC to be comparable with DATETIME fields in DB
35-
$from = $this->_dateToUtc($from);
36-
$to = $this->_dateToUtc($to);
37-
3834
$this->_aggregateByOrderCreatedAt($from, $to);
3935
$this->_aggregateByRefundCreatedAt($from, $to);
4036

@@ -65,7 +61,7 @@ protected function _aggregateByOrderCreatedAt($from, $to)
6561
}
6662

6763
$this->_clearTableByDateRange($table, $from, $to, $subSelect);
68-
// convert dates from UTC to current admin timezone
64+
// convert dates to current admin timezone
6965
$periodExpr = $adapter->getDatePartSql(
7066
$this->getStoreTZOffsetQuery($sourceTable, 'created_at', $from, $to)
7167
);
@@ -162,7 +158,7 @@ protected function _aggregateByRefundCreatedAt($from, $to)
162158
}
163159

164160
$this->_clearTableByDateRange($table, $from, $to, $subSelect);
165-
// convert dates from UTC to current admin timezone
161+
// convert dates to current admin timezone
166162
$periodExpr = $adapter->getDatePartSql(
167163
$this->getStoreTZOffsetQuery(
168164
['source_table' => $sourceTable],

app/code/Magento/Sales/Model/Resource/Report/Shipping.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ protected function _construct()
3131
*/
3232
public function aggregate($from = null, $to = null)
3333
{
34-
// convert input dates to UTC to be comparable with DATETIME fields in DB
35-
$from = $this->_dateToUtc($from);
36-
$to = $this->_dateToUtc($to);
37-
3834
$this->_aggregateByOrderCreatedAt($from, $to);
3935
$this->_aggregateByShippingCreatedAt($from, $to);
4036
$this->_setFlagData(\Magento\Reports\Model\Flag::REPORT_SHIPPING_FLAG_CODE);
@@ -64,7 +60,7 @@ protected function _aggregateByOrderCreatedAt($from, $to)
6460
}
6561

6662
$this->_clearTableByDateRange($table, $from, $to, $subSelect);
67-
// convert dates from UTC to current admin timezone
63+
// convert dates to current admin timezone
6864
$periodExpr = $adapter->getDatePartSql(
6965
$this->getStoreTZOffsetQuery($sourceTable, 'created_at', $from, $to)
7066
);
@@ -166,7 +162,7 @@ protected function _aggregateByShippingCreatedAt($from, $to)
166162
}
167163

168164
$this->_clearTableByDateRange($table, $from, $to, $subSelect);
169-
// convert dates from UTC to current admin timezone
165+
// convert dates to current admin timezone
170166
$periodExpr = $adapter->getDatePartSql(
171167
$this->getStoreTZOffsetQuery(
172168
['source_table' => $sourceTable],

app/code/Magento/SalesRule/Model/Resource/Report/Rule/Createdat.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ public function aggregate($from = null, $to = null)
4949
*/
5050
protected function _aggregateByOrder($aggregationField, $from, $to)
5151
{
52-
$from = $this->_dateToUtc($from);
53-
$to = $this->_dateToUtc($to);
54-
5552
$table = $this->getMainTable();
5653
$sourceTable = $this->getTable('sales_order');
5754
$adapter = $this->_getWriteAdapter();
@@ -67,7 +64,7 @@ protected function _aggregateByOrder($aggregationField, $from, $to)
6764

6865
$this->_clearTableByDateRange($table, $from, $to, $subSelect, false, $salesAdapter);
6966

70-
// convert dates from UTC to current admin timezone
67+
// convert dates to current admin timezone
7168
$periodExpr = $adapter->getDatePartSql(
7269
$this->getStoreTZOffsetQuery($sourceTable, $aggregationField, $from, $to, null, $salesAdapter)
7370
);

app/code/Magento/Tax/Model/Resource/Report/Tax/Createdat.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ public function aggregate($from = null, $to = null)
4646
*/
4747
protected function _aggregateByOrder($aggregationField, $from, $to)
4848
{
49-
// convert input dates to UTC to be comparable with DATETIME fields in DB
50-
$from = $this->_dateToUtc($from);
51-
$to = $this->_dateToUtc($to);
52-
5349
$writeAdapter = $this->_getWriteAdapter();
5450
$salesAdapter = $this->_resources->getConnection('sales_read');
5551

@@ -69,7 +65,7 @@ protected function _aggregateByOrder($aggregationField, $from, $to)
6965
}
7066

7167
$this->_clearTableByDateRange($this->getMainTable(), $from, $to, $subSelect, false, $salesAdapter);
72-
// convert dates from UTC to current admin timezone
68+
// convert dates to current admin timezone
7369
$periodExpr = $writeAdapter->getDatePartSql(
7470
$this->getStoreTZOffsetQuery(
7571
['e' => $this->getTable('sales_order')],

dev/tests/functional/tests/app/Magento/Reports/Test/Constraint/AssertCouponReportResult.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ public function processAssert(SalesCouponReportView $salesCouponReportView, Orde
3434
$discount = $data['price']['discount'] != 0
3535
? '-' . $currency . number_format($data['price']['discount'], 2)
3636
: $currency . '0.00';
37-
$roleName = $data['coupon_code']->getName();
37+
$couponCode = $data['coupon_code']->getCouponCode();
3838
$filter = [
39-
'coupon_code' => $data['coupon_code']->getCouponCode(),
40-
'rule_name' => $roleName,
39+
'coupon_code' => $couponCode,
40+
'rule_name' => $data['coupon_code']->getName(),
4141
'subtotal' => $currency . number_format($data['price']['subtotal'], 2),
4242
'discount' => $discount,
4343
];
4444
\PHPUnit_Framework_Assert::assertTrue(
4545
$salesCouponReportView->getGridBlock()->isRowVisible($filter, false),
46-
"Coupon '$roleName' is not visible."
46+
"Coupon with code - '$couponCode' is not visible."
4747
);
4848
}
4949

dev/tests/integration/testsuite/Magento/Reports/Controller/Adminhtml/Report/Product/ViewedTest.php

-11
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,6 @@ public function testExecuteWithError()
3434
$this->dispatch('backend/reports/report_product/viewed/filter/' .
3535
'cGVyaW9kX3R5cGU9ZGF5JmZyb209NyUyRjElMkY2NyZ0bz1odG1sJTIwZm90bSZzaG93X2VtcHR5X3Jvd3M9MA==');
3636
$actual = $this->getResponse()->getBody();
37-
38-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
39-
40-
/** @var $messageManager \Magento\Framework\Message\Manager */
41-
$messageManager = $objectManager->get('Magento\Framework\Message\Manager');
42-
43-
$this->assertContains(
44-
'An error occurred while showing the product views report.',
45-
(string)$messageManager->getMessages()->getLastAddedMessage()->getText()
46-
);
47-
4837
$this->assertEquals('', $actual);
4938
}
5039
}

dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php

+2
Original file line numberDiff line numberDiff line change
@@ -2230,4 +2230,6 @@
22302230
['assignData', 'Magento\OfflinePayments\Model\Checkmo'],
22312231
['timeShift', 'Magento\Reports\Model\Resource\Report\Collection'],
22322232
['Magento\Catalog\Model\Product\Attribute\Backend\Startdate', 'Magento\Catalog\Model\Attribute\Backend\Startdate'],
2233+
['_getStoreTimezoneUtcOffset', 'Magento\Reports\Model\Resource\Report\AbstractReport'],
2234+
['_dateToUtc', 'Magento\Reports\Model\Resource\Report\AbstractReport'],
22332235
];

lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function date($date = null, $locale = null, $useTimezone = true)
146146
$locale = $locale ?: $this->_localeResolver->getLocale();
147147
$timezone = $useTimezone
148148
? $this->_scopeConfig->getValue($this->getDefaultTimezonePath(), $this->_scopeType)
149-
: 'UTC';
149+
: date_default_timezone_get();
150150

151151
if (empty($date)) {
152152
return new \DateTime('now', new \DateTimeZone($timezone));

setup/src/Magento/Setup/Fixtures/CategoriesFixture.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function execute()
5252
->setName("Category $categoryIndex")
5353
->setParentId($parentCategoryId[$groupNumber])
5454
->setPath($nestingPath[$groupNumber])
55-
->setLevel($nestingLevel[$groupNumber])
55+
->setLevel($nestingLevel[$groupNumber] + 1)
5656
->setAvailableSortBy('name')
5757
->setDefaultSortBy('name')
5858
->setIsActive(true)

setup/src/Magento/Setup/Fixtures/OrdersFixture.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ public function execute()
194194
$zip = '11111';
195195
$phone = '911';
196196
$dateStart = new \DateTime();
197-
$dateStart->setTimezone(new \DateTimeZone('Etc/UTC'));
198197
$time = $dateStart->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
199198

200199
$simpleProductIdLen[0] = strlen($simpleProductId[0]($entityId));
@@ -268,7 +267,7 @@ public function execute()
268267
$queries[] = "INSERT INTO `{$salesOrderStatusHistoryTableName}` (`entity_id`, `parent_id`, `is_customer_notified`, `is_visible_on_front`, `comment`, `status`, `created_at`, `entity_name`) VALUES ({$salesOrderStatusHistoryId}, {$salesOrderId}, 1, 0, NULL, 'pending', '{$time}', 'order');";
269268

270269
// @codingStandardsIgnoreEnd
271-
foreach($queries as $query) {
270+
foreach ($queries as $query) {
272271
$writeAdapter->query($query);
273272
}
274273

0 commit comments

Comments
 (0)