6
6
namespace Magento \Catalog \Model \Indexer \Product \Category \Action ;
7
7
8
8
use Magento \Catalog \Model \Category ;
9
+ use Magento \Catalog \Model \Config ;
9
10
use Magento \Catalog \Model \Product ;
10
11
use Magento \Framework \App \ObjectManager ;
12
+ use Magento \Framework \App \ResourceConnection ;
13
+ use Magento \Framework \DB \Query \Generator as QueryGenerator ;
14
+ use Magento \Framework \EntityManager \MetadataPool ;
15
+ use Magento \Framework \Event \ManagerInterface as EventManagerInterface ;
11
16
use Magento \Framework \Indexer \CacheContext ;
17
+ use Magento \Store \Model \StoreManagerInterface ;
12
18
13
19
/**
14
- * Reindex products categories.
15
20
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16
21
*/
17
22
class Rows extends \Magento \Catalog \Model \Indexer \Category \Product \AbstractAction
@@ -29,32 +34,31 @@ class Rows extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractActio
29
34
private $ cacheContext ;
30
35
31
36
/**
32
- * @var \Magento\Framework\Event\ManagerInterface |null
37
+ * @var EventManagerInterface |null
33
38
*/
34
39
private $ eventManager ;
35
40
36
41
/**
37
- * @param \Magento\Framework\App\ ResourceConnection $resource
38
- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
39
- * @param \Magento\Catalog\Model\ Config $config
40
- * @param \Magento\Framework\DB\Query\Generator |null $queryGenerator
41
- * @param \Magento\Framework\EntityManager\ MetadataPool|null $metadataPool
42
+ * @param ResourceConnection $resource
43
+ * @param StoreManagerInterface $storeManager
44
+ * @param Config $config
45
+ * @param QueryGenerator |null $queryGenerator
46
+ * @param MetadataPool|null $metadataPool
42
47
* @param CacheContext|null $cacheContext
43
- * @param \Magento\Framework\Event\ManagerInterface |null $eventManager
48
+ * @param EventManagerInterface |null $eventManager
44
49
*/
45
50
public function __construct (
46
- \ Magento \ Framework \ App \ ResourceConnection $ resource ,
47
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
48
- \ Magento \ Catalog \ Model \ Config $ config ,
49
- \ Magento \ Framework \ DB \ Query \ Generator $ queryGenerator = null ,
50
- \ Magento \ Framework \ EntityManager \ MetadataPool $ metadataPool = null ,
51
+ ResourceConnection $ resource ,
52
+ StoreManagerInterface $ storeManager ,
53
+ Config $ config ,
54
+ QueryGenerator $ queryGenerator = null ,
55
+ MetadataPool $ metadataPool = null ,
51
56
CacheContext $ cacheContext = null ,
52
- \ Magento \ Framework \ Event \ ManagerInterface $ eventManager = null
57
+ EventManagerInterface $ eventManager = null
53
58
) {
54
59
parent ::__construct ($ resource , $ storeManager , $ config , $ queryGenerator , $ metadataPool );
55
60
$ this ->cacheContext = $ cacheContext ?: ObjectManager::getInstance ()->get (CacheContext::class);
56
- $ this ->eventManager = $ eventManager ?:
57
- ObjectManager::getInstance ()->get (\Magento \Framework \Event \ManagerInterface::class);
61
+ $ this ->eventManager = $ eventManager ?: ObjectManager::getInstance ()->get (EventManagerInterface::class);
58
62
}
59
63
60
64
/**
@@ -152,10 +156,12 @@ private function registerCategories(array $categoryIds)
152
156
*/
153
157
protected function removeEntries ()
154
158
{
155
- $ this ->connection ->delete (
156
- $ this ->getMainTable (),
157
- ['product_id IN (?) ' => $ this ->limitationByProducts ]
158
- );
159
+ foreach ($ this ->storeManager ->getStores () as $ store ) {
160
+ $ this ->connection ->delete (
161
+ $ this ->getIndexTable ($ store ->getId ()),
162
+ ['product_id IN (?) ' => $ this ->limitationByProducts ]
163
+ );
164
+ };
159
165
}
160
166
161
167
/**
@@ -167,7 +173,6 @@ protected function removeEntries()
167
173
protected function getNonAnchorCategoriesSelect (\Magento \Store \Model \Store $ store )
168
174
{
169
175
$ select = parent ::getNonAnchorCategoriesSelect ($ store );
170
-
171
176
return $ select ->where ('ccp.product_id IN (?) OR relation.child_id IN (?) ' , $ this ->limitationByProducts );
172
177
}
173
178
@@ -206,19 +211,24 @@ protected function isRangingNeeded()
206
211
}
207
212
208
213
/**
209
- * Returns a list of category ids which are assigned to product ids in the index.
214
+ * Returns a list of category ids which are assigned to product ids in the index
210
215
*
211
- * @param array $productIds
212
216
* @return \Magento\Framework\Indexer\CacheContext
213
217
*/
214
218
private function getCategoryIdsFromIndex (array $ productIds )
215
219
{
216
- $ categoryIds = $ this ->connection ->fetchCol (
217
- $ this ->connection ->select ()
218
- ->from ($ this ->getMainTable (), ['category_id ' ])
219
- ->where ('product_id IN (?) ' , $ productIds )
220
- ->distinct ()
221
- );
220
+ $ categoryIds = [];
221
+ foreach ($ this ->storeManager ->getStores () as $ store ) {
222
+ $ categoryIds = array_merge (
223
+ $ categoryIds ,
224
+ $ this ->connection ->fetchCol (
225
+ $ this ->connection ->select ()
226
+ ->from ($ this ->getIndexTable ($ store ->getId ()), ['category_id ' ])
227
+ ->where ('product_id IN (?) ' , $ productIds )
228
+ ->distinct ()
229
+ )
230
+ );
231
+ };
222
232
$ parentCategories = $ categoryIds ;
223
233
foreach ($ categoryIds as $ categoryId ) {
224
234
$ parentIds = explode ('/ ' , $ this ->getPathFromCategoryId ($ categoryId ));
0 commit comments