Skip to content

Commit d2a1868

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

File tree

5 files changed

+77
-165
lines changed

5 files changed

+77
-165
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
namespace Magento\CatalogRule\Observer;
1313

1414
use Magento\Catalog\Model\Product;
15-
use Magento\CatalogRule\Model\Rule;
15+
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
1616
use Magento\Store\Model\StoreManagerInterface;
1717
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1818
use Magento\Customer\Model\Session as CustomerModelSession;
19-
use Magento\Framework\Event\Observer as EventObserver;
2019
use Magento\Customer\Api\GroupManagementInterface;
2120
use Magento\Framework\Event\ObserverInterface;
2221

@@ -90,7 +89,7 @@ public function __construct(
9089
*/
9190
public function execute(\Magento\Framework\Event\Observer $observer)
9291
{
93-
/* @var $collection ProductCollection */
92+
/** @var ProductCollection $collection */
9493
$collection = $observer->getEvent()->getCollection();
9594
$store = $this->storeManager->getStore($observer->getEvent()->getStoreId());
9695
$websiteId = $store->getWebsiteId();

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77

88
namespace Magento\CatalogRule\Observer;
99

10-
use Magento\Catalog\Model\Product;
11-
use Magento\CatalogRule\Model\Rule;
1210
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
13-
use Magento\Customer\Model\Session as CustomerModelSession;
14-
use Magento\Framework\Event\Observer as EventObserver;
1511
use Magento\Framework\Registry;
1612
use Magento\Framework\Event\ObserverInterface;
1713

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
namespace Magento\CatalogRule\Observer;
99

1010
use Magento\Framework\Event\ObserverInterface;
11-
use Magento\Catalog\Model\Product;
12-
use Magento\CatalogRule\Model\Rule;
1311
use Magento\Store\Model\StoreManagerInterface;
1412
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1513
use Magento\Customer\Model\Session as CustomerModelSession;
16-
use Magento\Framework\Event\Observer as EventObserver;
1714

1815
/**
1916
* Observer for applying catalog rules on product for frontend area

app/code/Magento/CatalogRule/Pricing/Price/CatalogRulePrice.php

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99

1010
use Magento\Catalog\Model\Product;
1111
use Magento\CatalogRule\Model\ResourceModel\Rule;
12-
use Magento\CatalogRule\Model\ResourceModel\RuleFactory;
1312
use Magento\Customer\Model\Session;
14-
use Magento\Framework\App\ObjectManager;
1513
use Magento\Framework\Pricing\Adjustment\Calculator;
1614
use Magento\Framework\Pricing\Price\AbstractPrice;
1715
use Magento\Framework\Pricing\Price\BasePriceProviderInterface;
16+
use Magento\Framework\Pricing\PriceCurrencyInterface;
1817
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
19-
use Magento\Store\Model\StoreManager;
18+
use Magento\Store\Model\StoreManagerInterface;
2019

2120
/**
2221
* Class CatalogRulePrice
@@ -31,56 +30,50 @@ class CatalogRulePrice extends AbstractPrice implements BasePriceProviderInterfa
3130
const PRICE_CODE = 'catalog_rule_price';
3231

3332
/**
34-
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
33+
* @var TimezoneInterface
3534
*/
3635
protected $dateTime;
3736

3837
/**
39-
* @var \Magento\Store\Model\StoreManager
38+
* @var StoreManagerInterface
4039
*/
4140
protected $storeManager;
4241

4342
/**
44-
* @var \Magento\Customer\Model\Session
43+
* @var Session
4544
*/
4645
protected $customerSession;
4746

4847
/**
49-
* @var \Magento\CatalogRule\Model\ResourceModel\RuleFactory
50-
* @deprecated 100.1.1
51-
*/
52-
protected $resourceRuleFactory;
53-
54-
/**
55-
* @var \Magento\CatalogRule\Model\ResourceModel\Rule
48+
* @var Rule
5649
*/
5750
private $ruleResource;
5851

5952
/**
6053
* @param Product $saleableItem
6154
* @param float $quantity
6255
* @param Calculator $calculator
63-
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
56+
* @param PriceCurrencyInterface $priceCurrency
6457
* @param TimezoneInterface $dateTime
65-
* @param StoreManager $storeManager
58+
* @param StoreManagerInterface $storeManager
6659
* @param Session $customerSession
67-
* @param RuleFactory $catalogRuleResourceFactory
60+
* @param Rule $ruleResource
6861
*/
6962
public function __construct(
7063
Product $saleableItem,
7164
$quantity,
7265
Calculator $calculator,
73-
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
66+
PriceCurrencyInterface $priceCurrency,
7467
TimezoneInterface $dateTime,
75-
StoreManager $storeManager,
68+
StoreManagerInterface $storeManager,
7669
Session $customerSession,
77-
RuleFactory $catalogRuleResourceFactory
70+
Rule $ruleResource
7871
) {
7972
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
8073
$this->dateTime = $dateTime;
8174
$this->storeManager = $storeManager;
8275
$this->customerSession = $customerSession;
83-
$this->resourceRuleFactory = $catalogRuleResourceFactory;
76+
$this->ruleResource = $ruleResource;
8477
}
8578

8679
/**
@@ -94,13 +87,12 @@ public function getValue()
9487
if ($this->product->hasData(self::PRICE_CODE)) {
9588
$this->value = (float)$this->product->getData(self::PRICE_CODE) ?: false;
9689
} else {
97-
$this->value = $this->getRuleResource()
98-
->getRulePrice(
99-
$this->dateTime->date(null, null, false),
100-
$this->storeManager->getStore()->getWebsiteId(),
101-
$this->customerSession->getCustomerGroupId(),
102-
$this->product->getId()
103-
);
90+
$this->value = $this->ruleResource->getRulePrice(
91+
$this->dateTime->date(null, null, false),
92+
$this->storeManager->getStore()->getWebsiteId(),
93+
$this->customerSession->getCustomerGroupId(),
94+
$this->product->getId()
95+
);
10496
$this->value = $this->value ? (float)$this->value : false;
10597
}
10698
if ($this->value) {
@@ -110,19 +102,4 @@ public function getValue()
110102

111103
return $this->value;
112104
}
113-
114-
/**
115-
* Retrieve rule resource
116-
*
117-
* @return Rule
118-
* @deprecated 100.1.1
119-
*/
120-
private function getRuleResource()
121-
{
122-
if (null === $this->ruleResource) {
123-
$this->ruleResource = ObjectManager::getInstance()->get(Rule::class);
124-
}
125-
126-
return $this->ruleResource;
127-
}
128105
}

0 commit comments

Comments
 (0)