9
9
use Magento \CatalogRule \Model \Indexer \IndexerTableSwapperInterface as TableSwapper ;
10
10
use Magento \Catalog \Model \ResourceModel \Indexer \ActiveTableSwitcher ;
11
11
use Magento \CatalogRule \Model \Rule ;
12
- use Magento \Framework \App \Config \ScopeConfigInterface ;
13
12
use Magento \Framework \App \ResourceConnection ;
14
- use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
15
- use Magento \Store \Model \ScopeInterface ;
13
+ use Magento \Framework \Stdlib \DateTime \Timezone \LocalizedDateToUtcConverterInterface ;
16
14
17
15
/**
18
16
* Reindex rule relations with products.
@@ -35,34 +33,26 @@ class ReindexRuleProduct
35
33
private $ tableSwapper ;
36
34
37
35
/**
38
- * @var ScopeConfigInterface
36
+ * @var LocalizedDateToUtcConverterInterface
39
37
*/
40
- private $ scopeConfig ;
41
-
42
- /**
43
- * @var TimezoneInterface
44
- */
45
- private $ localeDate ;
38
+ private $ dateToUtcConverter ;
46
39
47
40
/**
48
41
* @param ResourceConnection $resource
49
42
* @param ActiveTableSwitcher $activeTableSwitcher
50
43
* @param TableSwapper $tableSwapper
51
- * @param ScopeConfigInterface $scopeConfig
52
- * @param TimezoneInterface $localeDate
44
+ * @param LocalizedDateToUtcConverterInterface $dateToUtcConverter
53
45
*/
54
46
public function __construct (
55
47
ResourceConnection $ resource ,
56
48
ActiveTableSwitcher $ activeTableSwitcher ,
57
49
TableSwapper $ tableSwapper ,
58
- ScopeConfigInterface $ scopeConfig ,
59
- TimezoneInterface $ localeDate
50
+ LocalizedDateToUtcConverterInterface $ dateToUtcConverter
60
51
) {
61
52
$ this ->resource = $ resource ;
62
53
$ this ->activeTableSwitcher = $ activeTableSwitcher ;
63
54
$ this ->tableSwapper = $ tableSwapper ;
64
- $ this ->scopeConfig = $ scopeConfig ;
65
- $ this ->localeDate = $ localeDate ;
55
+ $ this ->dateToUtcConverter = $ dateToUtcConverter ;
66
56
}
67
57
68
58
/**
@@ -75,11 +65,8 @@ public function __construct(
75
65
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
76
66
* @SuppressWarnings(PHPMD.NPathComplexity)
77
67
*/
78
- public function execute (
79
- Rule $ rule ,
80
- $ batchCount ,
81
- $ useAdditionalTable = false
82
- ) {
68
+ public function execute (Rule $ rule , $ batchCount , $ useAdditionalTable = false )
69
+ {
83
70
if (!$ rule ->getIsActive () || empty ($ rule ->getWebsiteIds ())) {
84
71
return false ;
85
72
}
@@ -109,20 +96,15 @@ public function execute(
109
96
$ actionStop = $ rule ->getStopRulesProcessing ();
110
97
111
98
$ rows = [];
112
-
113
99
foreach ($ productIds as $ productId => $ validationByWebsite ) {
114
100
foreach ($ websiteIds as $ websiteId ) {
115
101
if (empty ($ validationByWebsite [$ websiteId ])) {
116
102
continue ;
117
103
}
118
104
119
- $ scopeTzPath = $ this ->localeDate ->getDefaultTimezonePath ();
120
- $ scopeTz = new \DateTimeZone (
121
- $ this ->scopeConfig ->getValue ($ scopeTzPath , ScopeInterface::SCOPE_WEBSITE , $ websiteId )
122
- );
123
- $ fromTime = (new \DateTime ($ rule ->getFromDate (), $ scopeTz ))->getTimestamp ();
105
+ $ fromTime = strtotime ($ this ->dateToUtcConverter ->convertLocalizedDateToUtc ($ rule ->getFromDate ()));
124
106
$ toTime = $ rule ->getToDate ()
125
- ? ( new \ DateTime ($ rule ->getToDate (), $ scopeTz ))-> getTimestamp () + IndexBuilder:: SECONDS_IN_DAY - 1
107
+ ? strtotime ( $ this -> dateToUtcConverter -> convertLocalizedDateToUtc ($ rule ->getToDate ()))
126
108
: 0 ;
127
109
128
110
foreach ($ customerGroupIds as $ customerGroupId ) {
0 commit comments