6
6
7
7
namespace Magento \CatalogRule \Model \Indexer ;
8
8
9
+ use DateTime ;
9
10
use Magento \Catalog \Model \Product ;
10
11
use Magento \CatalogRule \Model \ResourceModel \Rule \Collection as RuleCollection ;
11
12
use Magento \CatalogRule \Model \ResourceModel \Rule \CollectionFactory as RuleCollectionFactory ;
14
15
use Magento \Framework \Pricing \PriceCurrencyInterface ;
15
16
use Magento \CatalogRule \Model \Indexer \IndexBuilder \ProductLoader ;
16
17
use Magento \CatalogRule \Model \Indexer \IndexerTableSwapperInterface as TableSwapper ;
18
+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
19
+ use Magento \Store \Model \ScopeInterface ;
17
20
18
21
/**
19
22
* Catalog rule index builder
@@ -150,6 +153,11 @@ class IndexBuilder
150
153
*/
151
154
private $ productLoader ;
152
155
156
+ /**
157
+ * @var TimezoneInterface|mixed
158
+ */
159
+ private $ localeDate ;
160
+
153
161
/**
154
162
* @param RuleCollectionFactory $ruleCollectionFactory
155
163
* @param PriceCurrencyInterface $priceCurrency
@@ -170,6 +178,7 @@ class IndexBuilder
170
178
* @param \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher|null $activeTableSwitcher
171
179
* @param ProductLoader|null $productLoader
172
180
* @param TableSwapper|null $tableSwapper
181
+ * @param TimezoneInterface|null $localeDate
173
182
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
174
183
*/
175
184
public function __construct (
@@ -191,7 +200,8 @@ public function __construct(
191
200
RuleProductPricesPersistor $ pricesPersistor = null ,
192
201
\Magento \Catalog \Model \ResourceModel \Indexer \ActiveTableSwitcher $ activeTableSwitcher = null ,
193
202
ProductLoader $ productLoader = null ,
194
- TableSwapper $ tableSwapper = null
203
+ TableSwapper $ tableSwapper = null ,
204
+ ?TimezoneInterface $ localeDate = null
195
205
) {
196
206
$ this ->resource = $ resource ;
197
207
$ this ->connection = $ resource ->getConnection ();
@@ -231,6 +241,8 @@ public function __construct(
231
241
);
232
242
$ this ->tableSwapper = $ tableSwapper ??
233
243
ObjectManager::getInstance ()->get (TableSwapper::class);
244
+ $ this ->localeDate = $ localeDate ??
245
+ ObjectManager::getInstance ()->get (TimezoneInterface::class);
234
246
}
235
247
236
248
/**
@@ -389,7 +401,9 @@ protected function cleanByIds($productIds)
389
401
* @param Rule $rule
390
402
* @param int $productEntityId
391
403
* @param array $websiteIds
404
+ *
392
405
* @return void
406
+ * @throws \Exception
393
407
*/
394
408
private function assignProductToRule (Rule $ rule , int $ productEntityId , array $ websiteIds ): void
395
409
{
@@ -404,16 +418,23 @@ private function assignProductToRule(Rule $rule, int $productEntityId, array $we
404
418
);
405
419
406
420
$ customerGroupIds = $ rule ->getCustomerGroupIds ();
407
- $ fromTime = strtotime ($ rule ->getFromDate ());
408
- $ toTime = strtotime ($ rule ->getToDate ());
409
- $ toTime = $ toTime ? $ toTime + self ::SECONDS_IN_DAY - 1 : 0 ;
410
421
$ sortOrder = (int )$ rule ->getSortOrder ();
411
422
$ actionOperator = $ rule ->getSimpleAction ();
412
423
$ actionAmount = $ rule ->getDiscountAmount ();
413
424
$ actionStop = $ rule ->getStopRulesProcessing ();
414
425
415
426
$ rows = [];
416
427
foreach ($ websiteIds as $ websiteId ) {
428
+ $ scopeTz = new \DateTimeZone (
429
+ $ this ->localeDate ->getConfigTimezone (ScopeInterface::SCOPE_WEBSITE , $ websiteId )
430
+ );
431
+ $ fromTime = $ rule ->getFromDate ()
432
+ ? (new DateTime ($ rule ->getFromDate (), $ scopeTz ))->getTimestamp ()
433
+ : 0 ;
434
+ $ toTime = $ rule ->getToDate ()
435
+ ? (new DateTime ($ rule ->getToDate (), $ scopeTz ))->getTimestamp () + IndexBuilder::SECONDS_IN_DAY - 1
436
+ : 0 ;
437
+
417
438
foreach ($ customerGroupIds as $ customerGroupId ) {
418
439
$ rows [] = [
419
440
'rule_id ' => $ ruleId ,
0 commit comments