Skip to content

Commit

Permalink
Merge pull request #327 from magento-troll/sprint37
Browse files Browse the repository at this point in the history
[Troll] Bugfixes
  • Loading branch information
Ganin, Roman(rganin) committed May 28, 2015
2 parents 932b845 + 8192379 commit ea7b254
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 96 deletions.
3 changes: 0 additions & 3 deletions app/code/Magento/Reports/Model/Resource/Order/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,6 @@ public function getDateRange($range, $customStart, $customEnd, $returnObjects =
break;
}

$dateStart->setTimezone(new \DateTimeZone('Etc/UTC'));
$dateEnd->setTimezone(new \DateTimeZone('Etc/UTC'));

if ($returnObjects) {
return [$dateStart, $dateEnd];
} else {
Expand Down
33 changes: 0 additions & 33 deletions app/code/Magento/Reports/Model/Resource/Report/AbstractReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,37 +465,4 @@ protected function _getTZOffsetTransitions($timezone, $from = null, $to = null)

return $tzTransitions;
}

/**
* Retrieve store timezone offset from UTC in the form acceptable by SQL's CONVERT_TZ()
*
* @param null|mixed $store
* @return string
*/
protected function _getStoreTimezoneUtcOffset($store = null)
{
return $this->_localeDate->scopeDate($store)->format('P');
}

/**
* Retrieve date in UTC timezone
*
* @param mixed $date
* @return null|\DateTime
*/
protected function _dateToUtc($date)
{
if ($date === null) {
return null;
}

if ($date instanceof \DateTimeInterface) {
$dateUtc = $date;
} else {
$dateUtc = new \DateTime($date);
}

$dateUtc->setTimezone(new \DateTimeZone('UTC'));
return $dateUtc->format('Y-m-d H:i:s');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ public function aggregate($from = null, $to = null)
$mainTable = $this->getMainTable();
$adapter = $this->_getWriteAdapter();

// convert input dates to UTC to be comparable with DATETIME fields in DB
$from = $this->_dateToUtc($from);
$to = $this->_dateToUtc($to);

if ($from !== null || $to !== null) {
$subSelect = $this->_getTableDateRangeSelect(
$this->getTable('report_event'),
Expand All @@ -114,7 +110,7 @@ public function aggregate($from = null, $to = null)
$subSelect = null;
}
$this->_clearTableByDateRange($mainTable, $from, $to, $subSelect);
// convert dates from UTC to current admin timezone
// convert dates to current admin timezone
$periodExpr = $adapter->getDatePartSql(
$this->getStoreTZOffsetQuery(
['source_table' => $this->getTable('report_event')],
Expand Down
6 changes: 1 addition & 5 deletions app/code/Magento/Sales/Model/Resource/Report/Bestsellers.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ protected function _construct()
*/
public function aggregate($from = null, $to = null)
{
// convert input dates to UTC to be comparable with DATETIME fields in DB
$from = $this->_dateToUtc($from);
$to = $this->_dateToUtc($to);

$adapter = $this->_getWriteAdapter();
//$this->_getWriteAdapter()->beginTransaction();

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

$this->_clearTableByDateRange($this->getMainTable(), $from, $to, $subSelect);
// convert dates from UTC to current admin timezone
// convert dates to current admin timezone
$periodExpr = $adapter->getDatePartSql(
$this->getStoreTZOffsetQuery(
['source_table' => $this->getTable('sales_order')],
Expand Down
8 changes: 2 additions & 6 deletions app/code/Magento/Sales/Model/Resource/Report/Invoiced.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ protected function _construct()
*/
public function aggregate($from = null, $to = null)
{
// convert input dates to UTC to be comparable with DATETIME fields in DB
$from = $this->_dateToUtc($from);
$to = $this->_dateToUtc($to);

$this->_aggregateByOrderCreatedAt($from, $to);
$this->_aggregateByInvoiceCreatedAt($from, $to);

Expand Down Expand Up @@ -76,7 +72,7 @@ protected function _aggregateByInvoiceCreatedAt($from, $to)
}

$this->_clearTableByDateRange($table, $from, $to, $subSelect);
// convert dates from UTC to current admin timezone
// convert dates to current admin timezone
$periodExpr = $adapter->getDatePartSql(
$this->getStoreTZOffsetQuery(
['source_table' => $sourceTable],
Expand Down Expand Up @@ -187,7 +183,7 @@ protected function _aggregateByOrderCreatedAt($from, $to)
}

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

$columns = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ public function aggregate($from = null, $to = null)
*/
protected function _aggregateByField($aggregationField, $from, $to)
{
// convert input dates to UTC to be comparable with DATETIME fields in DB
$from = $this->_dateToUtc($from);
$to = $this->_dateToUtc($to);

$adapter = $this->_getWriteAdapter();

$adapter->beginTransaction();
Expand Down
8 changes: 2 additions & 6 deletions app/code/Magento/Sales/Model/Resource/Report/Refunded.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ protected function _construct()
*/
public function aggregate($from = null, $to = null)
{
// convert input dates to UTC to be comparable with DATETIME fields in DB
$from = $this->_dateToUtc($from);
$to = $this->_dateToUtc($to);

$this->_aggregateByOrderCreatedAt($from, $to);
$this->_aggregateByRefundCreatedAt($from, $to);

Expand Down Expand Up @@ -65,7 +61,7 @@ protected function _aggregateByOrderCreatedAt($from, $to)
}

$this->_clearTableByDateRange($table, $from, $to, $subSelect);
// convert dates from UTC to current admin timezone
// convert dates to current admin timezone
$periodExpr = $adapter->getDatePartSql(
$this->getStoreTZOffsetQuery($sourceTable, 'created_at', $from, $to)
);
Expand Down Expand Up @@ -162,7 +158,7 @@ protected function _aggregateByRefundCreatedAt($from, $to)
}

$this->_clearTableByDateRange($table, $from, $to, $subSelect);
// convert dates from UTC to current admin timezone
// convert dates to current admin timezone
$periodExpr = $adapter->getDatePartSql(
$this->getStoreTZOffsetQuery(
['source_table' => $sourceTable],
Expand Down
8 changes: 2 additions & 6 deletions app/code/Magento/Sales/Model/Resource/Report/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ protected function _construct()
*/
public function aggregate($from = null, $to = null)
{
// convert input dates to UTC to be comparable with DATETIME fields in DB
$from = $this->_dateToUtc($from);
$to = $this->_dateToUtc($to);

$this->_aggregateByOrderCreatedAt($from, $to);
$this->_aggregateByShippingCreatedAt($from, $to);
$this->_setFlagData(\Magento\Reports\Model\Flag::REPORT_SHIPPING_FLAG_CODE);
Expand Down Expand Up @@ -64,7 +60,7 @@ protected function _aggregateByOrderCreatedAt($from, $to)
}

$this->_clearTableByDateRange($table, $from, $to, $subSelect);
// convert dates from UTC to current admin timezone
// convert dates to current admin timezone
$periodExpr = $adapter->getDatePartSql(
$this->getStoreTZOffsetQuery($sourceTable, 'created_at', $from, $to)
);
Expand Down Expand Up @@ -166,7 +162,7 @@ protected function _aggregateByShippingCreatedAt($from, $to)
}

$this->_clearTableByDateRange($table, $from, $to, $subSelect);
// convert dates from UTC to current admin timezone
// convert dates to current admin timezone
$periodExpr = $adapter->getDatePartSql(
$this->getStoreTZOffsetQuery(
['source_table' => $sourceTable],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public function aggregate($from = null, $to = null)
*/
protected function _aggregateByOrder($aggregationField, $from, $to)
{
$from = $this->_dateToUtc($from);
$to = $this->_dateToUtc($to);

$table = $this->getMainTable();
$sourceTable = $this->getTable('sales_order');
$adapter = $this->_getWriteAdapter();
Expand All @@ -67,7 +64,7 @@ protected function _aggregateByOrder($aggregationField, $from, $to)

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

// convert dates from UTC to current admin timezone
// convert dates to current admin timezone
$periodExpr = $adapter->getDatePartSql(
$this->getStoreTZOffsetQuery($sourceTable, $aggregationField, $from, $to, null, $salesAdapter)
);
Expand Down
6 changes: 1 addition & 5 deletions app/code/Magento/Tax/Model/Resource/Report/Tax/Createdat.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ public function aggregate($from = null, $to = null)
*/
protected function _aggregateByOrder($aggregationField, $from, $to)
{
// convert input dates to UTC to be comparable with DATETIME fields in DB
$from = $this->_dateToUtc($from);
$to = $this->_dateToUtc($to);

$writeAdapter = $this->_getWriteAdapter();
$salesAdapter = $this->_resources->getConnection('sales_read');

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

$this->_clearTableByDateRange($this->getMainTable(), $from, $to, $subSelect, false, $salesAdapter);
// convert dates from UTC to current admin timezone
// convert dates to current admin timezone
$periodExpr = $writeAdapter->getDatePartSql(
$this->getStoreTZOffsetQuery(
['e' => $this->getTable('sales_order')],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public function processAssert(SalesCouponReportView $salesCouponReportView, Orde
$discount = $data['price']['discount'] != 0
? '-' . $currency . number_format($data['price']['discount'], 2)
: $currency . '0.00';
$roleName = $data['coupon_code']->getName();
$couponCode = $data['coupon_code']->getCouponCode();
$filter = [
'coupon_code' => $data['coupon_code']->getCouponCode(),
'rule_name' => $roleName,
'coupon_code' => $couponCode,
'rule_name' => $data['coupon_code']->getName(),
'subtotal' => $currency . number_format($data['price']['subtotal'], 2),
'discount' => $discount,
];
\PHPUnit_Framework_Assert::assertTrue(
$salesCouponReportView->getGridBlock()->isRowVisible($filter, false),
"Coupon '$roleName' is not visible."
"Coupon with code - '$couponCode' is not visible."
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@ public function testExecuteWithError()
$this->dispatch('backend/reports/report_product/viewed/filter/' .
'cGVyaW9kX3R5cGU9ZGF5JmZyb209NyUyRjElMkY2NyZ0bz1odG1sJTIwZm90bSZzaG93X2VtcHR5X3Jvd3M9MA==');
$actual = $this->getResponse()->getBody();

$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();

/** @var $messageManager \Magento\Framework\Message\Manager */
$messageManager = $objectManager->get('Magento\Framework\Message\Manager');

$this->assertContains(
'An error occurred while showing the product views report.',
(string)$messageManager->getMessages()->getLastAddedMessage()->getText()
);

$this->assertEquals('', $actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2230,4 +2230,6 @@
['assignData', 'Magento\OfflinePayments\Model\Checkmo'],
['timeShift', 'Magento\Reports\Model\Resource\Report\Collection'],
['Magento\Catalog\Model\Product\Attribute\Backend\Startdate', 'Magento\Catalog\Model\Attribute\Backend\Startdate'],
['_getStoreTimezoneUtcOffset', 'Magento\Reports\Model\Resource\Report\AbstractReport'],
['_dateToUtc', 'Magento\Reports\Model\Resource\Report\AbstractReport'],
];
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function date($date = null, $locale = null, $useTimezone = true)
$locale = $locale ?: $this->_localeResolver->getLocale();
$timezone = $useTimezone
? $this->_scopeConfig->getValue($this->getDefaultTimezonePath(), $this->_scopeType)
: 'UTC';
: date_default_timezone_get();

if (empty($date)) {
return new \DateTime('now', new \DateTimeZone($timezone));
Expand Down
2 changes: 1 addition & 1 deletion setup/src/Magento/Setup/Fixtures/CategoriesFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function execute()
->setName("Category $categoryIndex")
->setParentId($parentCategoryId[$groupNumber])
->setPath($nestingPath[$groupNumber])
->setLevel($nestingLevel[$groupNumber])
->setLevel($nestingLevel[$groupNumber] + 1)
->setAvailableSortBy('name')
->setDefaultSortBy('name')
->setIsActive(true)
Expand Down
3 changes: 1 addition & 2 deletions setup/src/Magento/Setup/Fixtures/OrdersFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ public function execute()
$zip = '11111';
$phone = '911';
$dateStart = new \DateTime();
$dateStart->setTimezone(new \DateTimeZone('Etc/UTC'));
$time = $dateStart->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);

$simpleProductIdLen[0] = strlen($simpleProductId[0]($entityId));
Expand Down Expand Up @@ -268,7 +267,7 @@ public function execute()
$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');";

// @codingStandardsIgnoreEnd
foreach($queries as $query) {
foreach ($queries as $query) {
$writeAdapter->query($query);
}

Expand Down

0 comments on commit ea7b254

Please sign in to comment.