10
10
use Magento \Catalog \Model \ResourceModel \Indexer \ActiveTableSwitcher ;
11
11
use Magento \CatalogRule \Model \Rule ;
12
12
use Magento \Framework \App \ResourceConnection ;
13
- use Magento \Framework \Stdlib \DateTime \Timezone \LocalizedDateToUtcConverterInterface ;
13
+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
14
+ use Magento \Store \Model \ScopeInterface ;
14
15
15
16
/**
16
17
* Reindex rule relations with products.
@@ -33,26 +34,26 @@ class ReindexRuleProduct
33
34
private $ tableSwapper ;
34
35
35
36
/**
36
- * @var LocalizedDateToUtcConverterInterface
37
+ * @var TimezoneInterface
37
38
*/
38
- private $ dateToUtcConverter ;
39
+ private $ localeDate ;
39
40
40
41
/**
41
42
* @param ResourceConnection $resource
42
43
* @param ActiveTableSwitcher $activeTableSwitcher
43
44
* @param TableSwapper $tableSwapper
44
- * @param LocalizedDateToUtcConverterInterface $dateToUtcConverter
45
+ * @param TimezoneInterface $localeDate
45
46
*/
46
47
public function __construct (
47
48
ResourceConnection $ resource ,
48
49
ActiveTableSwitcher $ activeTableSwitcher ,
49
50
TableSwapper $ tableSwapper ,
50
- LocalizedDateToUtcConverterInterface $ dateToUtcConverter
51
+ TimezoneInterface $ localeDate
51
52
) {
52
53
$ this ->resource = $ resource ;
53
54
$ this ->activeTableSwitcher = $ activeTableSwitcher ;
54
55
$ this ->tableSwapper = $ tableSwapper ;
55
- $ this ->dateToUtcConverter = $ dateToUtcConverter ;
56
+ $ this ->localeDate = $ localeDate ;
56
57
}
57
58
58
59
/**
@@ -96,17 +97,20 @@ public function execute(Rule $rule, $batchCount, $useAdditionalTable = false)
96
97
$ actionStop = $ rule ->getStopRulesProcessing ();
97
98
98
99
$ rows = [];
99
- foreach ($ productIds as $ productId => $ validationByWebsite ) {
100
- foreach ($ websiteIds as $ websiteId ) {
100
+ foreach ($ websiteIds as $ websiteId ) {
101
+ $ scopeTz = new \DateTimeZone (
102
+ $ this ->localeDate ->getConfigTimezone (ScopeInterface::SCOPE_WEBSITE , $ websiteId )
103
+ );
104
+ $ fromTime = (new \DateTime ($ rule ->getFromDate (), $ scopeTz ))->getTimestamp ();
105
+ $ toTime = $ rule ->getToDate ()
106
+ ? (new \DateTime ($ rule ->getToDate (), $ scopeTz ))->getTimestamp () + IndexBuilder::SECONDS_IN_DAY - 1
107
+ : 0 ;
108
+
109
+ foreach ($ productIds as $ productId => $ validationByWebsite ) {
101
110
if (empty ($ validationByWebsite [$ websiteId ])) {
102
111
continue ;
103
112
}
104
113
105
- $ fromTime = strtotime ($ this ->dateToUtcConverter ->convertLocalizedDateToUtc ($ rule ->getFromDate ()));
106
- $ toTime = $ rule ->getToDate ()
107
- ? strtotime ($ this ->dateToUtcConverter ->convertLocalizedDateToUtc ($ rule ->getToDate ()))
108
- : 0 ;
109
-
110
114
foreach ($ customerGroupIds as $ customerGroupId ) {
111
115
$ rows [] = [
112
116
'rule_id ' => $ ruleId ,
0 commit comments