Skip to content

Commit 558da0f

Browse files
committed
MC-18254: Catalog rule indexer works incorrectly if Magento timezone offset is greater then system timezone offset
1 parent 5911255 commit 558da0f

File tree

10 files changed

+14
-160
lines changed

10 files changed

+14
-160
lines changed

app/code/Magento/Catalog/Model/Product/Type/Price.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ class Price
9393
*/
9494
private $tierPriceExtensionFactory;
9595

96-
/**
97-
* @var \Magento\CatalogRule\Model\RuleDateFormatterInterface
98-
*/
99-
private $ruleDateFormatter;
100-
10196
/**
10297
* Constructor
10398
*
@@ -111,7 +106,6 @@ class Price
111106
* @param \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory
112107
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
113108
* @param ProductTierPriceExtensionFactory|null $tierPriceExtensionFactory
114-
* @param \Magento\CatalogRule\Model\RuleDateFormatterInterface|null $ruleDateFormatter
115109
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
116110
*/
117111
public function __construct(
@@ -124,8 +118,7 @@ public function __construct(
124118
GroupManagementInterface $groupManagement,
125119
\Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory,
126120
\Magento\Framework\App\Config\ScopeConfigInterface $config,
127-
ProductTierPriceExtensionFactory $tierPriceExtensionFactory = null,
128-
\Magento\CatalogRule\Model\RuleDateFormatterInterface $ruleDateFormatter = null
121+
ProductTierPriceExtensionFactory $tierPriceExtensionFactory = null
129122
) {
130123
$this->_ruleFactory = $ruleFactory;
131124
$this->_storeManager = $storeManager;
@@ -138,8 +131,6 @@ public function __construct(
138131
$this->config = $config;
139132
$this->tierPriceExtensionFactory = $tierPriceExtensionFactory ?: ObjectManager::getInstance()
140133
->get(ProductTierPriceExtensionFactory::class);
141-
$this->ruleDateFormatter = $ruleDateFormatter ?: ObjectManager::getInstance()
142-
->get(\Magento\CatalogRule\Model\RuleDateFormatterInterface::class);
143134
}
144135

145136
/**
@@ -605,10 +596,7 @@ public function calculatePrice(
605596
) {
606597
\Magento\Framework\Profiler::start('__PRODUCT_CALCULATE_PRICE__');
607598
if ($wId instanceof Store) {
608-
$sId = $wId->getId();
609599
$wId = $wId->getWebsiteId();
610-
} else {
611-
$sId = $this->_storeManager->getWebsite($wId)->getDefaultGroup()->getDefaultStoreId();
612600
}
613601

614602
$finalPrice = $basePrice;
@@ -622,7 +610,7 @@ public function calculatePrice(
622610
);
623611

624612
if ($rulePrice === false) {
625-
$date = $this->ruleDateFormatter->getDate($sId);
613+
$date = $this->_localeDate->date(null, null, false);
626614
$rulePrice = $this->_ruleFactory->create()->getRulePrice($date, $wId, $gId, $productId);
627615
}
628616

app/code/Magento/CatalogRule/Model/ResourceModel/Product/CollectionProcessor.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
1212
use Magento\CatalogRule\Pricing\Price\CatalogRulePrice;
13-
use Magento\Framework\App\ObjectManager;
1413

1514
/**
1615
* Add catalog rule prices to collection
@@ -44,34 +43,25 @@ class CollectionProcessor
4443
*/
4544
private $localeDate;
4645

47-
/**
48-
* @var \Magento\CatalogRule\Model\RuleDateFormatterInterface
49-
*/
50-
private $ruleDateFormatter;
51-
5246
/**
5347
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
5448
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
5549
* @param \Magento\Customer\Model\Session $customerSession
5650
* @param \Magento\Framework\Stdlib\DateTime $dateTime
5751
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
58-
* @param \Magento\CatalogRule\Model\RuleDateFormatterInterface|null $ruleDateFormatter
5952
*/
6053
public function __construct(
6154
\Magento\Store\Model\StoreManagerInterface $storeManager,
6255
\Magento\Framework\App\ResourceConnection $resourceConnection,
6356
\Magento\Customer\Model\Session $customerSession,
6457
\Magento\Framework\Stdlib\DateTime $dateTime,
65-
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
66-
\Magento\CatalogRule\Model\RuleDateFormatterInterface $ruleDateFormatter = null
58+
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
6759
) {
6860
$this->storeManager = $storeManager;
6961
$this->resource = $resourceConnection;
7062
$this->customerSession = $customerSession;
7163
$this->dateTime = $dateTime;
7264
$this->localeDate = $localeDate;
73-
$this->ruleDateFormatter = $ruleDateFormatter ?: ObjectManager::getInstance()
74-
->get(\Magento\CatalogRule\Model\RuleDateFormatterInterface::class);
7565
}
7666

7767
/**
@@ -100,7 +90,7 @@ public function addPriceData(ProductCollection $productCollection, $joinColumn =
10090
),
10191
$connection->quoteInto(
10292
'catalog_rule.rule_date = ?',
103-
$this->dateTime->formatDate($this->ruleDateFormatter->getDate($store->getId()), false)
93+
$this->dateTime->formatDate($this->localeDate->date(null, null, false), false)
10494
),
10595
]
10696
),

app/code/Magento/CatalogRule/Model/ResourceModel/Product/LinkedProductSelectBuilderByCatalogRulePrice.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ class LinkedProductSelectBuilderByCatalogRulePrice implements LinkedProductSelec
5555
*/
5656
private $baseSelectProcessor;
5757

58-
/**
59-
* @var \Magento\CatalogRule\Model\RuleDateFormatterInterface
60-
*/
61-
private $ruleDateFormatter;
62-
6358
/**
6459
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
6560
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
@@ -68,7 +63,6 @@ class LinkedProductSelectBuilderByCatalogRulePrice implements LinkedProductSelec
6863
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
6964
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
7065
* @param BaseSelectProcessorInterface $baseSelectProcessor
71-
* @param \Magento\CatalogRule\Model\RuleDateFormatterInterface|null $ruleDateFormatter
7266
*/
7367
public function __construct(
7468
\Magento\Store\Model\StoreManagerInterface $storeManager,
@@ -77,8 +71,7 @@ public function __construct(
7771
\Magento\Framework\Stdlib\DateTime $dateTime,
7872
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
7973
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
80-
BaseSelectProcessorInterface $baseSelectProcessor = null,
81-
\Magento\CatalogRule\Model\RuleDateFormatterInterface $ruleDateFormatter = null
74+
BaseSelectProcessorInterface $baseSelectProcessor = null
8275
) {
8376
$this->storeManager = $storeManager;
8477
$this->resource = $resourceConnection;
@@ -88,17 +81,14 @@ public function __construct(
8881
$this->metadataPool = $metadataPool;
8982
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
9083
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
91-
$this->ruleDateFormatter = $ruleDateFormatter ?: ObjectManager::getInstance()
92-
->get(\Magento\CatalogRule\Model\RuleDateFormatterInterface::class);
9384
}
9485

9586
/**
9687
* @inheritdoc
9788
*/
9889
public function build($productId)
9990
{
100-
$timestamp = $this->ruleDateFormatter->getTimeStamp($this->storeManager->getStore());
101-
$currentDate = $this->dateTime->formatDate($timestamp, false);
91+
$currentDate = $this->dateTime->formatDate($this->localeDate->date(null, null, false), false);
10292
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
10393
$productTable = $this->resource->getTableName('catalog_product_entity');
10494

app/code/Magento/CatalogRule/Model/RuleDateFormatter.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

app/code/Magento/CatalogRule/Model/RuleDateFormatterInterface.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

app/code/Magento/CatalogRule/Observer/PrepareCatalogProductCollectionPricesObserver.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Magento\Framework\Event\Observer as EventObserver;
2020
use Magento\Customer\Api\GroupManagementInterface;
2121
use Magento\Framework\Event\ObserverInterface;
22-
use Magento\Framework\App\ObjectManager;
2322

2423
/**
2524
* Observer for applying catalog rules on product collection
@@ -59,37 +58,28 @@ class PrepareCatalogProductCollectionPricesObserver implements ObserverInterface
5958
*/
6059
protected $groupManagement;
6160

62-
/**
63-
* @var \Magento\CatalogRule\Model\RuleDateFormatterInterface
64-
*/
65-
private $ruleDateFormatter;
66-
6761
/**
6862
* @param RulePricesStorage $rulePricesStorage
6963
* @param \Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory
7064
* @param StoreManagerInterface $storeManager
7165
* @param TimezoneInterface $localeDate
7266
* @param CustomerModelSession $customerSession
7367
* @param GroupManagementInterface $groupManagement
74-
* @param \Magento\CatalogRule\Model\RuleDateFormatterInterface|null $ruleDateFormatter
7568
*/
7669
public function __construct(
7770
RulePricesStorage $rulePricesStorage,
7871
\Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory,
7972
StoreManagerInterface $storeManager,
8073
TimezoneInterface $localeDate,
8174
CustomerModelSession $customerSession,
82-
GroupManagementInterface $groupManagement,
83-
\Magento\CatalogRule\Model\RuleDateFormatterInterface $ruleDateFormatter = null
75+
GroupManagementInterface $groupManagement
8476
) {
8577
$this->rulePricesStorage = $rulePricesStorage;
8678
$this->resourceRuleFactory = $resourceRuleFactory;
8779
$this->storeManager = $storeManager;
8880
$this->localeDate = $localeDate;
8981
$this->customerSession = $customerSession;
9082
$this->groupManagement = $groupManagement;
91-
$this->ruleDateFormatter = $ruleDateFormatter ?: ObjectManager::getInstance()
92-
->get(\Magento\CatalogRule\Model\RuleDateFormatterInterface::class);
9383
}
9484

9585
/**
@@ -116,7 +106,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
116106
if ($observer->getEvent()->hasDate()) {
117107
$date = new \DateTime($observer->getEvent()->getDate());
118108
} else {
119-
$date = (new \DateTime())->setTimestamp($this->ruleDateFormatter->getTimeStamp($store));
109+
$date = $this->localeDate->date(null, null, false);
120110
}
121111

122112
$productIds = [];

app/code/Magento/CatalogRule/Observer/ProcessAdminFinalPriceObserver.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Magento\Framework\Event\Observer as EventObserver;
1515
use Magento\Framework\Registry;
1616
use Magento\Framework\Event\ObserverInterface;
17-
use Magento\Framework\App\ObjectManager;
1817

1918
/**
2019
* Observer for applying catalog rules on product for admin area
@@ -43,31 +42,22 @@ class ProcessAdminFinalPriceObserver implements ObserverInterface
4342
*/
4443
protected $rulePricesStorage;
4544

46-
/**
47-
* @var \Magento\CatalogRule\Model\RuleDateFormatterInterface
48-
*/
49-
private $ruleDateFormatter;
50-
5145
/**
5246
* @param RulePricesStorage $rulePricesStorage
5347
* @param Registry $coreRegistry
5448
* @param \Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory
5549
* @param TimezoneInterface $localeDate
56-
* @param \Magento\CatalogRule\Model\RuleDateFormatterInterface|null $ruleDateFormatter
5750
*/
5851
public function __construct(
5952
RulePricesStorage $rulePricesStorage,
6053
Registry $coreRegistry,
6154
\Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory,
62-
TimezoneInterface $localeDate,
63-
\Magento\CatalogRule\Model\RuleDateFormatterInterface $ruleDateFormatter = null
55+
TimezoneInterface $localeDate
6456
) {
6557
$this->rulePricesStorage = $rulePricesStorage;
6658
$this->coreRegistry = $coreRegistry;
6759
$this->resourceRuleFactory = $resourceRuleFactory;
6860
$this->localeDate = $localeDate;
69-
$this->ruleDateFormatter = $ruleDateFormatter ?: ObjectManager::getInstance()
70-
->get(\Magento\CatalogRule\Model\RuleDateFormatterInterface::class);
7161
}
7262

7363
/**
@@ -79,8 +69,7 @@ public function __construct(
7969
public function execute(\Magento\Framework\Event\Observer $observer)
8070
{
8171
$product = $observer->getEvent()->getProduct();
82-
$storeId = $product->getStoreId();
83-
$date = $this->ruleDateFormatter->getDate($storeId);
72+
$date = $this->localeDate->date(null, null, false);
8473
$key = false;
8574

8675
$ruleData = $this->coreRegistry->registry('rule_data');

app/code/Magento/CatalogRule/Observer/ProcessFrontFinalPriceObserver.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1515
use Magento\Customer\Model\Session as CustomerModelSession;
1616
use Magento\Framework\Event\Observer as EventObserver;
17-
use Magento\Framework\App\ObjectManager;
1817

1918
/**
2019
* Observer for applying catalog rules on product for frontend area
@@ -48,34 +47,25 @@ class ProcessFrontFinalPriceObserver implements ObserverInterface
4847
*/
4948
protected $rulePricesStorage;
5049

51-
/**
52-
* @var \Magento\CatalogRule\Model\RuleDateFormatterInterface
53-
*/
54-
private $ruleDateFormatter;
55-
5650
/**
5751
* @param RulePricesStorage $rulePricesStorage
5852
* @param \Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory
5953
* @param StoreManagerInterface $storeManager
6054
* @param TimezoneInterface $localeDate
6155
* @param CustomerModelSession $customerSession
62-
* @param \Magento\CatalogRule\Model\RuleDateFormatterInterface|null $ruleDateFormatter
6356
*/
6457
public function __construct(
6558
RulePricesStorage $rulePricesStorage,
6659
\Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory,
6760
StoreManagerInterface $storeManager,
6861
TimezoneInterface $localeDate,
69-
CustomerModelSession $customerSession,
70-
\Magento\CatalogRule\Model\RuleDateFormatterInterface $ruleDateFormatter = null
62+
CustomerModelSession $customerSession
7163
) {
7264
$this->rulePricesStorage = $rulePricesStorage;
7365
$this->resourceRuleFactory = $resourceRuleFactory;
7466
$this->storeManager = $storeManager;
7567
$this->localeDate = $localeDate;
7668
$this->customerSession = $customerSession;
77-
$this->ruleDateFormatter = $ruleDateFormatter ?: ObjectManager::getInstance()
78-
->get(\Magento\CatalogRule\Model\RuleDateFormatterInterface::class);
7969
}
8070

8171
/**
@@ -93,7 +83,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
9383
if ($observer->hasDate()) {
9484
$date = new \DateTime($observer->getEvent()->getDate());
9585
} else {
96-
$date = $this->ruleDateFormatter->getDate($storeId);
86+
$date = $this->localeDate->date(null, null, false);
9787
}
9888

9989
if ($observer->hasWebsiteId()) {

0 commit comments

Comments
 (0)