Skip to content

Commit f8a635a

Browse files
author
Dmytro Voskoboinikov
committed
Merge branch 'MAGETWO-44627' of https://github.corp.magento.com/magento-firedrakes/magento2ce into MAGETWO-44627
2 parents eacba1c + 7e3fbdc commit f8a635a

File tree

3 files changed

+103
-5
lines changed

3 files changed

+103
-5
lines changed

app/code/Magento/SalesRule/Model/ResourceModel/Rule/Collection.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\Abstr
3434
];
3535

3636
/**
37-
* @var \Magento\Framework\Stdlib\DateTime\DateTime
37+
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
3838
*/
3939
protected $_date;
4040

@@ -43,7 +43,7 @@ class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\Abstr
4343
* @param \Psr\Log\LoggerInterface $logger
4444
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
4545
* @param \Magento\Framework\Event\ManagerInterface $eventManager
46-
* @param \Magento\Framework\Stdlib\DateTime\DateTime $date
46+
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $date
4747
* @param mixed $connection
4848
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
4949
*/
@@ -52,7 +52,7 @@ public function __construct(
5252
\Psr\Log\LoggerInterface $logger,
5353
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
5454
\Magento\Framework\Event\ManagerInterface $eventManager,
55-
\Magento\Framework\Stdlib\DateTime\DateTime $date,
55+
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $date,
5656
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
5757
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
5858
) {
@@ -130,7 +130,7 @@ public function setValidationFilter($websiteId, $customerGroupId, $couponCode =
130130
),
131131
$connection->quoteInto(
132132
'(rule_coupons.expiration_date IS NULL OR rule_coupons.expiration_date >= ?)',
133-
$this->_date->date('Y-m-d')
133+
$this->_date->date()->format('Y-m-d')
134134
),
135135
];
136136

@@ -166,7 +166,7 @@ public function addWebsiteGroupDateFilter($websiteId, $customerGroupId, $now = n
166166
{
167167
if (!$this->getFlag('website_group_date_filter')) {
168168
if (is_null($now)) {
169-
$now = $this->_date->date('Y-m-d');
169+
$now = $this->_date->date()->format('Y-m-d');
170170
}
171171

172172
$this->addWebsiteFilter($websiteId);

dev/tests/integration/testsuite/Magento/SalesRule/Model/ResourceModel/Rule/CollectionTest.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\SalesRule\Model\ResourceModel\Rule;
77

88
/**
9+
* @magentoDbIsolation enabled
10+
* @magentoAppIsolation enabled
911
* @magentoDataFixture Magento/SalesRule/_files/rules.php
1012
* @magentoDataFixture Magento/SalesRule/_files/coupons.php
1113
*/
@@ -47,4 +49,71 @@ public function setValidationFilterDataProvider()
4749
'Check result with wrong code' => ['wrong_code', ['#5']]
4850
];
4951
}
52+
53+
/**
54+
* Test checks timezone when timezone is not changed
55+
*
56+
* @magentoDbIsolation enabled
57+
* @magentoAppIsolation enabled
58+
* @magentoDataFixture Magento/SalesRule/_files/rule_specific_date.php
59+
* @magentoConfigFixture general/locale/timezone Europe/Kiev
60+
*/
61+
public function testMultiRulesWithTimezone()
62+
{
63+
$this->setSpecificTimezone('Europe/Kiev');
64+
$collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
65+
'Magento\SalesRule\Model\ResourceModel\Rule\Collection'
66+
);
67+
$collection->addWebsiteGroupDateFilter(1, 0);
68+
$items = array_values($collection->getItems());
69+
$this->assertNotEmpty($items);
70+
}
71+
72+
/**
73+
* Test checks timezone when timezone is shifted to locale where current day already +1
74+
* (e.g. existed rule: from day 2000-01-01 to day 2000-01-01, after changing timezone 2000-01-02)
75+
*
76+
* @magentoDbIsolation enabled
77+
* @magentoAppIsolation enabled
78+
* @magentoDataFixture Magento/SalesRule/_files/rule_specific_date.php
79+
* @magentoConfigFixture general/locale/timezone Australia/Sydney
80+
*/
81+
public function testMultiRulesWithDifferentTimezone()
82+
{
83+
$this->setSpecificTimezone('Australia/Sydney');
84+
$collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
85+
'Magento\SalesRule\Model\ResourceModel\Rule\Collection'
86+
);
87+
$collection->addWebsiteGroupDateFilter(1, 0);
88+
$items = array_values($collection->getItems());
89+
$this->assertEmpty($items);
90+
}
91+
92+
protected function setSpecificTimezone($timezone)
93+
{
94+
$localeData = [
95+
'section' => 'general',
96+
'website' => null,
97+
'store' => null,
98+
'groups' => [
99+
'locale' => [
100+
'fields' => [
101+
'timezone' => [
102+
'value' => $timezone
103+
]
104+
]
105+
]
106+
]
107+
];
108+
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Config\Model\Config\Factory')
109+
->create()
110+
->addData($localeData)
111+
->save();
112+
}
113+
114+
public function tearDown()
115+
{
116+
// restore default timezone
117+
$this->setSpecificTimezone('America/Los_Angeles');
118+
}
50119
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** @var \Magento\SalesRule\Model\Rule $rule */
8+
$rule = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\SalesRule\Model\Rule');
9+
$rule->setName(
10+
'#1'
11+
)->setIsActive(
12+
1
13+
)->setStopRulesProcessing(
14+
0
15+
)->setIsAdvanced(
16+
1
17+
)->setCouponType(
18+
Magento\SalesRule\Model\Rule::COUPON_TYPE_NO_COUPON
19+
)->setUseAutoGeneration(
20+
0
21+
)->setWebsiteIds(
22+
'1'
23+
)->setCustomerGroupIds(
24+
'0'
25+
)->setFromDate(
26+
date('Y-m-d')
27+
)->setToDate(
28+
date('Y-m-d')
29+
)->save();

0 commit comments

Comments
 (0)