7
7
namespace Magento \CatalogRule \Model \Indexer ;
8
8
9
9
use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
10
+ use Magento \Store \Model \Store ;
10
11
use Magento \Store \Model \StoreManagerInterface ;
11
12
12
13
/**
@@ -39,25 +40,33 @@ class ReindexRuleProductPrice
39
40
*/
40
41
private $ pricesPersistor ;
41
42
43
+ /**
44
+ * @var bool
45
+ */
46
+ private $ useWebsiteTimezone ;
47
+
42
48
/**
43
49
* @param StoreManagerInterface $storeManager
44
50
* @param RuleProductsSelectBuilder $ruleProductsSelectBuilder
45
51
* @param ProductPriceCalculator $productPriceCalculator
46
52
* @param TimezoneInterface $localeDate
47
53
* @param RuleProductPricesPersistor $pricesPersistor
54
+ * @param bool $useWebsiteTimezone
48
55
*/
49
56
public function __construct (
50
57
StoreManagerInterface $ storeManager ,
51
58
RuleProductsSelectBuilder $ ruleProductsSelectBuilder ,
52
59
ProductPriceCalculator $ productPriceCalculator ,
53
60
TimezoneInterface $ localeDate ,
54
- RuleProductPricesPersistor $ pricesPersistor
61
+ RuleProductPricesPersistor $ pricesPersistor ,
62
+ bool $ useWebsiteTimezone = true
55
63
) {
56
64
$ this ->storeManager = $ storeManager ;
57
65
$ this ->ruleProductsSelectBuilder = $ ruleProductsSelectBuilder ;
58
66
$ this ->productPriceCalculator = $ productPriceCalculator ;
59
67
$ this ->localeDate = $ localeDate ;
60
68
$ this ->pricesPersistor = $ pricesPersistor ;
69
+ $ this ->useWebsiteTimezone = $ useWebsiteTimezone ;
61
70
}
62
71
63
72
/**
@@ -82,11 +91,9 @@ public function execute(int $batchCount, ?int $productId = null, bool $useAdditi
82
91
$ prevKey = null ;
83
92
84
93
$ storeGroup = $ this ->storeManager ->getGroup ($ website ->getDefaultGroupId ());
85
- $ currentDate = $ this ->localeDate ->scopeDate ($ storeGroup ->getDefaultStoreId (), null , true );
86
- $ previousDate = (clone $ currentDate )->modify ('-1 day ' );
87
- $ previousDate ->setTime (23 , 59 , 59 );
88
- $ nextDate = (clone $ currentDate )->modify ('+1 day ' );
89
- $ nextDate ->setTime (0 , 0 , 0 );
94
+ $ dateInterval = $ this ->useWebsiteTimezone
95
+ ? $ this ->getDateInterval ((int )$ storeGroup ->getDefaultStoreId ())
96
+ : $ this ->getDateInterval (Store::DEFAULT_STORE_ID );
90
97
91
98
while ($ ruleData = $ productsStmt ->fetch ()) {
92
99
$ ruleProductId = $ ruleData ['product_id ' ];
@@ -107,7 +114,7 @@ public function execute(int $batchCount, ?int $productId = null, bool $useAdditi
107
114
/**
108
115
* Build prices for each day
109
116
*/
110
- foreach ([ $ previousDate , $ currentDate , $ nextDate ] as $ date ) {
117
+ foreach ($ dateInterval as $ date ) {
111
118
$ time = $ date ->getTimestamp ();
112
119
if (($ ruleData ['from_time ' ] == 0 ||
113
120
$ time >= $ ruleData ['from_time ' ]) && ($ ruleData ['to_time ' ] == 0 ||
@@ -157,4 +164,21 @@ public function execute(int $batchCount, ?int $productId = null, bool $useAdditi
157
164
158
165
return true ;
159
166
}
167
+
168
+ /**
169
+ * Retrieve date sequence in store time zone
170
+ *
171
+ * @param int $storeId
172
+ * @return \DateTime[]
173
+ */
174
+ private function getDateInterval (int $ storeId ): array
175
+ {
176
+ $ currentDate = $ this ->localeDate ->scopeDate ($ storeId , null , true );
177
+ $ previousDate = (clone $ currentDate )->modify ('-1 day ' );
178
+ $ previousDate ->setTime (23 , 59 , 59 );
179
+ $ nextDate = (clone $ currentDate )->modify ('+1 day ' );
180
+ $ nextDate ->setTime (0 , 0 , 0 );
181
+
182
+ return [$ previousDate , $ currentDate , $ nextDate ];
183
+ }
160
184
}
0 commit comments