Skip to content

Commit c7a3c18

Browse files
committed
Merge remote-tracking branch 'tango/MC-18254-2' into PR-08-233
2 parents 90df53c + 0689b39 commit c7a3c18

File tree

11 files changed

+89
-323
lines changed

11 files changed

+89
-323
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: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
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;
22-
use Magento\Framework\App\ObjectManager;
2321

2422
/**
2523
* Observer for applying catalog rules on product collection
@@ -59,37 +57,28 @@ class PrepareCatalogProductCollectionPricesObserver implements ObserverInterface
5957
*/
6058
protected $groupManagement;
6159

62-
/**
63-
* @var \Magento\CatalogRule\Model\RuleDateFormatterInterface
64-
*/
65-
private $ruleDateFormatter;
66-
6760
/**
6861
* @param RulePricesStorage $rulePricesStorage
6962
* @param \Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory
7063
* @param StoreManagerInterface $storeManager
7164
* @param TimezoneInterface $localeDate
7265
* @param CustomerModelSession $customerSession
7366
* @param GroupManagementInterface $groupManagement
74-
* @param \Magento\CatalogRule\Model\RuleDateFormatterInterface|null $ruleDateFormatter
7567
*/
7668
public function __construct(
7769
RulePricesStorage $rulePricesStorage,
7870
\Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory,
7971
StoreManagerInterface $storeManager,
8072
TimezoneInterface $localeDate,
8173
CustomerModelSession $customerSession,
82-
GroupManagementInterface $groupManagement,
83-
\Magento\CatalogRule\Model\RuleDateFormatterInterface $ruleDateFormatter = null
74+
GroupManagementInterface $groupManagement
8475
) {
8576
$this->rulePricesStorage = $rulePricesStorage;
8677
$this->resourceRuleFactory = $resourceRuleFactory;
8778
$this->storeManager = $storeManager;
8879
$this->localeDate = $localeDate;
8980
$this->customerSession = $customerSession;
9081
$this->groupManagement = $groupManagement;
91-
$this->ruleDateFormatter = $ruleDateFormatter ?: ObjectManager::getInstance()
92-
->get(\Magento\CatalogRule\Model\RuleDateFormatterInterface::class);
9382
}
9483

9584
/**
@@ -100,7 +89,7 @@ public function __construct(
10089
*/
10190
public function execute(\Magento\Framework\Event\Observer $observer)
10291
{
103-
/* @var $collection ProductCollection */
92+
/** @var ProductCollection $collection */
10493
$collection = $observer->getEvent()->getCollection();
10594
$store = $this->storeManager->getStore($observer->getEvent()->getStoreId());
10695
$websiteId = $store->getWebsiteId();
@@ -116,7 +105,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
116105
if ($observer->getEvent()->hasDate()) {
117106
$date = new \DateTime($observer->getEvent()->getDate());
118107
} else {
119-
$date = (new \DateTime())->setTimestamp($this->ruleDateFormatter->getTimeStamp($store));
108+
$date = $this->localeDate->date(null, null, false);
120109
}
121110

122111
$productIds = [];

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@
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;
17-
use Magento\Framework\App\ObjectManager;
1813

1914
/**
2015
* Observer for applying catalog rules on product for admin area
@@ -43,31 +38,22 @@ class ProcessAdminFinalPriceObserver implements ObserverInterface
4338
*/
4439
protected $rulePricesStorage;
4540

46-
/**
47-
* @var \Magento\CatalogRule\Model\RuleDateFormatterInterface
48-
*/
49-
private $ruleDateFormatter;
50-
5141
/**
5242
* @param RulePricesStorage $rulePricesStorage
5343
* @param Registry $coreRegistry
5444
* @param \Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory
5545
* @param TimezoneInterface $localeDate
56-
* @param \Magento\CatalogRule\Model\RuleDateFormatterInterface|null $ruleDateFormatter
5746
*/
5847
public function __construct(
5948
RulePricesStorage $rulePricesStorage,
6049
Registry $coreRegistry,
6150
\Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory,
62-
TimezoneInterface $localeDate,
63-
\Magento\CatalogRule\Model\RuleDateFormatterInterface $ruleDateFormatter = null
51+
TimezoneInterface $localeDate
6452
) {
6553
$this->rulePricesStorage = $rulePricesStorage;
6654
$this->coreRegistry = $coreRegistry;
6755
$this->resourceRuleFactory = $resourceRuleFactory;
6856
$this->localeDate = $localeDate;
69-
$this->ruleDateFormatter = $ruleDateFormatter ?: ObjectManager::getInstance()
70-
->get(\Magento\CatalogRule\Model\RuleDateFormatterInterface::class);
7157
}
7258

7359
/**
@@ -79,8 +65,7 @@ public function __construct(
7965
public function execute(\Magento\Framework\Event\Observer $observer)
8066
{
8167
$product = $observer->getEvent()->getProduct();
82-
$storeId = $product->getStoreId();
83-
$date = $this->ruleDateFormatter->getDate($storeId);
68+
$date = $this->localeDate->date(null, null, false);
8469
$key = false;
8570

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

0 commit comments

Comments
 (0)