6
6
7
7
namespace Magento \CatalogSearch \Model \Indexer ;
8
8
9
+ use Magento \Catalog \Model \Product ;
9
10
use Magento \CatalogSearch \Model \Indexer \Fulltext \Action \FullFactory ;
10
11
use Magento \CatalogSearch \Model \Indexer \Scope \State ;
11
12
use Magento \CatalogSearch \Model \Indexer \Scope \StateFactory ;
12
13
use Magento \CatalogSearch \Model \ResourceModel \Fulltext as FulltextResource ;
13
14
use Magento \Framework \App \ObjectManager ;
15
+ use Magento \Framework \Indexer \CacheContext ;
14
16
use Magento \Framework \Indexer \DimensionProviderInterface ;
15
17
use Magento \Store \Model \StoreDimensionProvider ;
16
18
use Magento \Indexer \Model \ProcessManager ;
@@ -77,6 +79,11 @@ class Fulltext implements
77
79
*/
78
80
private $ processManager ;
79
81
82
+ /**
83
+ * @var CacheContext
84
+ */
85
+ private $ cacheContext ;
86
+
80
87
/**
81
88
* @param FullFactory $fullActionFactory
82
89
* @param IndexerHandlerFactory $indexerHandlerFactory
@@ -86,6 +93,7 @@ class Fulltext implements
86
93
* @param DimensionProviderInterface $dimensionProvider
87
94
* @param array $data
88
95
* @param ProcessManager $processManager
96
+ * @param CacheContext $cacheContext|null
89
97
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
90
98
*/
91
99
public function __construct (
@@ -96,7 +104,8 @@ public function __construct(
96
104
StateFactory $ indexScopeStateFactory ,
97
105
DimensionProviderInterface $ dimensionProvider ,
98
106
array $ data ,
99
- ProcessManager $ processManager = null
107
+ ProcessManager $ processManager = null ,
108
+ CacheContext $ cacheContext = null
100
109
) {
101
110
$ this ->fullAction = $ fullActionFactory ->create (['data ' => $ data ]);
102
111
$ this ->indexerHandlerFactory = $ indexerHandlerFactory ;
@@ -106,6 +115,7 @@ public function __construct(
106
115
$ this ->indexScopeState = ObjectManager::getInstance ()->get (State::class);
107
116
$ this ->dimensionProvider = $ dimensionProvider ;
108
117
$ this ->processManager = $ processManager ?: ObjectManager::getInstance ()->get (ProcessManager::class);
118
+ $ this ->cacheContext = $ cacheContext ?? ObjectManager::getInstance ()->get (CacheContext::class);
109
119
}
110
120
111
121
/**
@@ -145,6 +155,8 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds =
145
155
$ saveHandler ->saveIndex ($ dimensions , $ this ->fullAction ->rebuildStoreIndex ($ storeId ));
146
156
147
157
$ this ->fulltextResource ->resetSearchResultsByStore ($ storeId );
158
+
159
+ $ this ->cacheContext ->registerTags ([Product::CACHE_TAG ]);
148
160
} else {
149
161
// internal implementation works only with array
150
162
$ entityIds = iterator_to_array ($ entityIds );
@@ -155,6 +167,8 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds =
155
167
$ saveHandler ->deleteIndex ($ dimensions , new \ArrayIterator ($ productIds ));
156
168
$ saveHandler ->saveIndex ($ dimensions , $ this ->fullAction ->rebuildStoreIndex ($ storeId , $ productIds ));
157
169
}
170
+
171
+ $ this ->cacheContext ->registerEntities (Product::CACHE_TAG , $ productIds );
158
172
}
159
173
}
160
174
0 commit comments