Skip to content

Commit 26c49c8

Browse files
author
Mariana Lashch
committed
Merge branch 'MAGETWO-93038' into mpi-PR-2008
2 parents 19bec6f + 48356c0 commit 26c49c8

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Observer;
9+
10+
use Magento\Catalog\Model\Indexer\Category\Product\Processor;
11+
use Magento\Framework\Event\Observer;
12+
use Magento\Framework\Event\ObserverInterface;
13+
14+
/**
15+
* Checks if a category has changed products and depends on indexer configuration
16+
* marks `Category Products` indexer as invalid or reindexes affected products.
17+
*/
18+
class CategoryProductIndexer implements ObserverInterface
19+
{
20+
/**
21+
* @var Processor
22+
*/
23+
private $processor;
24+
25+
/**
26+
* @param Processor $processor
27+
*/
28+
public function __construct(Processor $processor)
29+
{
30+
$this->processor = $processor;
31+
}
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
public function execute(Observer $observer)
37+
{
38+
$productIds = $observer->getEvent()->getProductIds();
39+
if (!empty($productIds) && $this->processor->isIndexerScheduled()) {
40+
$this->processor->markIndexerAsInvalid();
41+
}
42+
}
43+
}

app/code/Magento/Catalog/etc/adminhtml/events.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@
99
<event name="cms_wysiwyg_images_static_urls_allowed">
1010
<observer name="catalog_wysiwyg" instance="Magento\Catalog\Observer\CatalogCheckIsUsingStaticUrlsAllowedObserver" />
1111
</event>
12+
<event name="catalog_category_change_products">
13+
<observer name="category_product_indexer" instance="Magento\Catalog\Observer\CategoryProductIndexer"/>
14+
</event>
1215
</config>

0 commit comments

Comments
 (0)