13
13
use Magento \Framework \DB \Query \Generator as QueryGenerator ;
14
14
use Magento \Framework \DB \Select ;
15
15
use Magento \Framework \EntityManager \MetadataPool ;
16
+ use Magento \Store \Api \Data \StoreInterface ;
16
17
use Magento \Store \Model \Store ;
17
18
18
19
// phpcs:disable Magento2.Classes.AbstractApi
@@ -126,9 +127,9 @@ abstract class AbstractAction
126
127
private $ queryGenerator ;
127
128
128
129
/**
129
- * @var int
130
+ * @var StoreInterface
130
131
*/
131
- private $ currentStoreId = 0 ;
132
+ private $ currentStore ;
132
133
133
134
/**
134
135
* @param ResourceConnection $resource
@@ -171,7 +172,7 @@ protected function reindex()
171
172
{
172
173
foreach ($ this ->storeManager ->getStores () as $ store ) {
173
174
if ($ this ->getPathFromCategoryId ($ store ->getRootCategoryId ())) {
174
- $ this ->currentStoreId = $ store-> getId () ;
175
+ $ this ->currentStore = $ store ;
175
176
$ this ->reindexRootCategory ($ store );
176
177
$ this ->reindexAnchorCategories ($ store );
177
178
$ this ->reindexNonAnchorCategories ($ store );
@@ -379,13 +380,13 @@ private function addFilteringByChildProductsToSelect(Select $select, Store $stor
379
380
[]
380
381
)->joinLeft (
381
382
['child_cpsd ' => $ this ->getTable ('catalog_product_entity_int ' )],
382
- 'child_cpsd. ' . $ linkField . ' = ' . 'relation_product_entity. ' . $ linkField
383
+ 'child_cpsd. ' . $ linkField . ' = ' . 'relation_product_entity. ' . $ linkField
383
384
. ' AND child_cpsd.store_id = 0 '
384
385
. ' AND child_cpsd.attribute_id = ' . $ statusAttributeId ,
385
386
[]
386
387
)->joinLeft (
387
388
['child_cpss ' => $ this ->getTable ('catalog_product_entity_int ' )],
388
- 'child_cpss. ' . $ linkField . ' = ' . 'relation_product_entity. ' . $ linkField . ''
389
+ 'child_cpss. ' . $ linkField . ' = ' . 'relation_product_entity. ' . $ linkField . ''
389
390
. ' AND child_cpss.attribute_id = child_cpsd.attribute_id '
390
391
. ' AND child_cpss.store_id = ' . $ store ->getId (),
391
392
[]
@@ -493,6 +494,7 @@ protected function createAnchorSelect(Store $store)
493
494
$ rootCatIds = explode ('/ ' , $ this ->getPathFromCategoryId ($ store ->getRootCategoryId ()));
494
495
array_pop ($ rootCatIds );
495
496
497
+ $ this ->currentStore = $ store ;
496
498
$ temporaryTreeTable = $ this ->makeTempCategoryTreeIndex ();
497
499
498
500
$ productMetadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
@@ -690,7 +692,7 @@ protected function fillTempCategoryTreeIndex($temporaryName)
690
692
['ccacs ' => $ this ->getTable ('catalog_category_entity_int ' )],
691
693
'ccacs. ' . $ categoryLinkField . ' = c. ' . $ categoryLinkField
692
694
. ' AND ccacs.attribute_id = ccacd.attribute_id AND ccacs.store_id = ' .
693
- $ this ->currentStoreId ,
695
+ $ this ->currentStore -> getId () ,
694
696
[]
695
697
)->where (
696
698
$ this ->connection ->getIfNullSql ('ccacs.value ' , 'ccacd.value ' ) . ' = ? ' ,
@@ -702,8 +704,14 @@ protected function fillTempCategoryTreeIndex($temporaryName)
702
704
foreach ($ selects as $ select ) {
703
705
$ values = [];
704
706
705
- foreach ($ this ->connection ->fetchAll ($ select ) as $ category ) {
706
- foreach (explode ('/ ' , $ category ['path ' ]) as $ parentId ) {
707
+ $ categories = $ this ->connection ->fetchAll ($ select );
708
+ foreach ($ categories as $ category ) {
709
+ $ categoriesTree = explode ('/ ' , $ category ['path ' ]);
710
+ foreach ($ categoriesTree as $ parentId ) {
711
+ if (!in_array ($ this ->currentStore ->getRootCategoryId (), $ categoriesTree , true )) {
712
+ break ;
713
+ }
714
+
707
715
if ($ parentId !== $ category ['entity_id ' ]) {
708
716
$ values [] = [$ parentId , $ category ['entity_id ' ]];
709
717
}
0 commit comments