File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 9
9
<event name =" cms_wysiwyg_images_static_urls_allowed" >
10
10
<observer name =" catalog_wysiwyg" instance =" Magento\Catalog\Observer\CatalogCheckIsUsingStaticUrlsAllowedObserver" />
11
11
</event >
12
+ <event name =" catalog_category_change_products" >
13
+ <observer name =" category_product_indexer" instance =" Magento\Catalog\Observer\CategoryProductIndexer" />
14
+ </event >
12
15
</config >
You can’t perform that action at this time.
0 commit comments