Skip to content

Commit 8e199c6

Browse files
committed
MC-18954: Nightly build jobs were failing lately after un-skipping tests in MC-5777
1 parent 7973e4c commit 8e199c6

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

app/code/Magento/CatalogRule/Model/Indexer/ReindexRuleProduct.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
1111
use Magento\CatalogRule\Model\Rule;
1212
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;
1415

1516
/**
1617
* Reindex rule relations with products.
@@ -33,26 +34,26 @@ class ReindexRuleProduct
3334
private $tableSwapper;
3435

3536
/**
36-
* @var LocalizedDateToUtcConverterInterface
37+
* @var TimezoneInterface
3738
*/
38-
private $dateToUtcConverter;
39+
private $localeDate;
3940

4041
/**
4142
* @param ResourceConnection $resource
4243
* @param ActiveTableSwitcher $activeTableSwitcher
4344
* @param TableSwapper $tableSwapper
44-
* @param LocalizedDateToUtcConverterInterface $dateToUtcConverter
45+
* @param TimezoneInterface $localeDate
4546
*/
4647
public function __construct(
4748
ResourceConnection $resource,
4849
ActiveTableSwitcher $activeTableSwitcher,
4950
TableSwapper $tableSwapper,
50-
LocalizedDateToUtcConverterInterface $dateToUtcConverter
51+
TimezoneInterface $localeDate
5152
) {
5253
$this->resource = $resource;
5354
$this->activeTableSwitcher = $activeTableSwitcher;
5455
$this->tableSwapper = $tableSwapper;
55-
$this->dateToUtcConverter = $dateToUtcConverter;
56+
$this->localeDate = $localeDate;
5657
}
5758

5859
/**
@@ -96,17 +97,20 @@ public function execute(Rule $rule, $batchCount, $useAdditionalTable = false)
9697
$actionStop = $rule->getStopRulesProcessing();
9798

9899
$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) {
101110
if (empty($validationByWebsite[$websiteId])) {
102111
continue;
103112
}
104113

105-
$fromTime = strtotime($this->dateToUtcConverter->convertLocalizedDateToUtc($rule->getFromDate()));
106-
$toTime = $rule->getToDate()
107-
? strtotime($this->dateToUtcConverter->convertLocalizedDateToUtc($rule->getToDate()))
108-
: 0;
109-
110114
foreach ($customerGroupIds as $customerGroupId) {
111115
$rows[] = [
112116
'rule_id' => $ruleId,

0 commit comments

Comments
 (0)