Skip to content

Commit 15075d7

Browse files
Merge branch '2.4-develop' into cron-log
2 parents 3a7761f + f89a447 commit 15075d7

File tree

38 files changed

+1825
-309
lines changed

38 files changed

+1825
-309
lines changed

app/code/Magento/Catalog/Block/Product/NewProduct.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ class NewProduct extends \Magento\Catalog\Block\Product\AbstractProduct implemen
1818
/**
1919
* Default value for products count that will be shown
2020
*/
21-
const DEFAULT_PRODUCTS_COUNT = 10;
21+
public const DEFAULT_PRODUCTS_COUNT = 10;
22+
23+
/**
24+
* Block cache tag
25+
*/
26+
public const CACHE_TAG = 'cat_p_new';
2227

2328
/**
24-
* Products count
25-
*
2629
* @var int
2730
*/
2831
protected $_productsCount;
@@ -33,15 +36,11 @@ class NewProduct extends \Magento\Catalog\Block\Product\AbstractProduct implemen
3336
protected $httpContext;
3437

3538
/**
36-
* Catalog product visibility
37-
*
3839
* @var \Magento\Catalog\Model\Product\Visibility
3940
*/
4041
protected $_catalogProductVisibility;
4142

4243
/**
43-
* Product collection factory
44-
*
4544
* @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
4645
*/
4746
protected $_productCollectionFactory;
@@ -199,6 +198,6 @@ public function getProductsCount()
199198
*/
200199
public function getIdentities()
201200
{
202-
return [\Magento\Catalog\Model\Product::CACHE_TAG];
201+
return [self::CACHE_TAG];
203202
}
204203
}

app/code/Magento/Catalog/Model/Indexer/Product/Full.php

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
namespace Magento\Catalog\Model\Indexer\Product;
88

9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\Indexer\ActionInterface;
11+
use Magento\Framework\Indexer\ConfigInterface;
1012
use Magento\Framework\Indexer\IndexerRegistry;
1113

1214
/**
@@ -24,26 +26,35 @@ class Full implements ActionInterface
2426
*/
2527
private $indexerList;
2628

29+
/**
30+
* @var ConfigInterface
31+
*/
32+
private $config;
33+
2734
/**
2835
* Initialize dependencies
2936
*
3037
* @param IndexerRegistry $indexerRegistry
3138
* @param string[] $indexerList
39+
* @param ConfigInterface|null $config
3240
*/
3341
public function __construct(
3442
IndexerRegistry $indexerRegistry,
35-
array $indexerList
43+
array $indexerList,
44+
?ConfigInterface $config = null
3645
) {
3746
$this->indexerRegistry = $indexerRegistry;
3847
$this->indexerList = $indexerList;
48+
$this->config = $config
49+
?? ObjectManager::getInstance()->get(ConfigInterface::class);
3950
}
4051

4152
/**
42-
* {@inheritdoc}
53+
* @inheritdoc
4354
*/
4455
public function executeFull()
4556
{
46-
foreach ($this->indexerList as $indexerName) {
57+
foreach ($this->getIndexerList() as $indexerName) {
4758
$indexer = $this->indexerRegistry->get($indexerName);
4859
if (!$indexer->isScheduled()) {
4960
$indexer->reindexAll();
@@ -52,12 +63,12 @@ public function executeFull()
5263
}
5364

5465
/**
55-
* {@inheritdoc}
66+
* @inheritdoc
5667
*/
5768
public function executeList(array $ids)
5869
{
5970
if (!empty($ids)) {
60-
foreach ($this->indexerList as $indexerName) {
71+
foreach ($this->getIndexerList() as $indexerName) {
6172
$indexer = $this->indexerRegistry->get($indexerName);
6273
if (!$indexer->isScheduled()) {
6374
$indexer->reindexList($ids);
@@ -67,17 +78,34 @@ public function executeList(array $ids)
6778
}
6879

6980
/**
70-
* {@inheritDoc}
81+
* @inheritDoc
7182
*/
7283
public function executeRow($id)
7384
{
7485
if (!empty($id)) {
75-
foreach ($this->indexerList as $indexerName) {
86+
foreach ($this->getIndexerList() as $indexerName) {
7687
$indexer = $this->indexerRegistry->get($indexerName);
7788
if (!$indexer->isScheduled()) {
7889
$indexer->reindexRow($id);
7990
}
8091
}
8192
}
8293
}
94+
95+
/**
96+
* Returns indexers in the order according to dependency tree
97+
*
98+
* @return array
99+
*/
100+
private function getIndexerList(): array
101+
{
102+
$indexers = [];
103+
foreach (array_keys($this->config->getIndexers()) as $indexerId) {
104+
if (in_array($indexerId, $this->indexerList, true)) {
105+
$indexers[] = $indexerId;
106+
}
107+
}
108+
109+
return $indexers;
110+
}
83111
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,7 @@ private function getProductCategoryIdentities(array $categoryIds): array
23802380
* Get identities
23812381
*
23822382
* @return array
2383+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
23832384
*/
23842385
public function getIdentities()
23852386
{
@@ -2406,6 +2407,12 @@ public function getIdentities()
24062407
$identities[] = self::CACHE_TAG;
24072408
}
24082409

2410+
$isProductNew = $this->getOrigData('news_from_date') != $this->getData('news_from_date')
2411+
|| $this->isObjectNew();
2412+
if ($isProductNew && ($isStatusChanged || $this->getStatus() == Status::STATUS_ENABLED)) {
2413+
$identities[] = \Magento\Catalog\Block\Product\NewProduct::CACHE_TAG;
2414+
}
2415+
24092416
return array_unique($identities);
24102417
}
24112418

0 commit comments

Comments
 (0)