8
8
9
9
namespace Magento \CatalogInventory \Model \Indexer \Stock ;
10
10
11
+ use Magento \Catalog \Model \Category ;
12
+
11
13
/**
12
14
* Abstract action reindex class
13
15
*
@@ -52,6 +54,17 @@ abstract class AbstractAction
52
54
*/
53
55
protected $ _isNeedUseIdxTable = false ;
54
56
57
+ /**
58
+ * @var \Magento\Indexer\Model\CacheContext
59
+ */
60
+ private $ cacheContext ;
61
+
62
+ /**
63
+ * @var \Magento\Framework\Event\ManagerInterface
64
+ */
65
+ private $ eventManager ;
66
+
67
+
55
68
/**
56
69
* @param \Magento\Framework\App\Resource $resource
57
70
* @param \Magento\CatalogInventory\Model\Resource\Indexer\StockFactory $indexerFactory
@@ -60,11 +73,16 @@ abstract class AbstractAction
60
73
public function __construct (
61
74
\Magento \Framework \App \Resource $ resource ,
62
75
\Magento \CatalogInventory \Model \Resource \Indexer \StockFactory $ indexerFactory ,
63
- \Magento \Catalog \Model \Product \Type $ catalogProductType
76
+ \Magento \Catalog \Model \Product \Type $ catalogProductType ,
77
+ \Magento \Indexer \Model \CacheContext $ cacheContext ,
78
+ \Magento \Framework \Event \ManagerInterface $ eventManager
79
+
64
80
) {
65
81
$ this ->_resource = $ resource ;
66
82
$ this ->_indexerFactory = $ indexerFactory ;
67
83
$ this ->_catalogProductType = $ catalogProductType ;
84
+ $ this ->cacheContext = $ cacheContext ;
85
+ $ this ->eventManager = $ eventManager ;
68
86
}
69
87
70
88
/**
@@ -228,6 +246,16 @@ protected function _reindexRows($productIds = [])
228
246
}
229
247
}
230
248
249
+ $ select = $ adapter ->select ()
250
+ ->distinct (true )
251
+ ->from ($ this ->_getTable ('catalog_category_product ' ), [ 'category_id ' ])
252
+ ->where ('product_id IN(?) ' , $ processIds );
253
+
254
+ $ affectedCategories = $ adapter ->fetchCol ($ select );
255
+ $ this ->cacheContext ->registerEntities (Category::CACHE_TAG , $ affectedCategories );
256
+
257
+ $ this ->eventManager ->dispatch ('clean_cache_by_tags ' , ['object ' => $ this ->cacheContext ]);
258
+
231
259
return $ this ;
232
260
}
233
261
0 commit comments