@@ -123,6 +123,11 @@ abstract class AbstractAction
123
123
*/
124
124
private $ queryGenerator ;
125
125
126
+ /**
127
+ * @var int
128
+ */
129
+ private $ currentStoreId = 0 ;
130
+
126
131
/**
127
132
* @param ResourceConnection $resource
128
133
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
@@ -164,6 +169,7 @@ protected function reindex()
164
169
{
165
170
foreach ($ this ->storeManager ->getStores () as $ store ) {
166
171
if ($ this ->getPathFromCategoryId ($ store ->getRootCategoryId ())) {
172
+ $ this ->currentStoreId = $ store ->getId ();
167
173
$ this ->reindexRootCategory ($ store );
168
174
$ this ->reindexAnchorCategories ($ store );
169
175
$ this ->reindexNonAnchorCategories ($ store );
@@ -499,7 +505,7 @@ protected function createAnchorSelect(Store $store)
499
505
'cc2.parent_id = cc.entity_id AND cc.entity_id NOT IN ( ' . implode (
500
506
', ' ,
501
507
$ rootCatIds
502
- ) . ') AND cc2.store_id = ' . $ store -> getId () ,
508
+ ) . ') ' ,
503
509
[]
504
510
)->joinInner (
505
511
['ccp ' => $ this ->getTable ('catalog_category_product ' )],
@@ -631,12 +637,6 @@ protected function makeTempCategoryTreeIndex()
631
637
null ,
632
638
['nullable ' => false , 'unsigned ' => true ]
633
639
);
634
- $ temporaryTable ->addColumn (
635
- 'store_id ' ,
636
- \Magento \Framework \DB \Ddl \Table::TYPE_INTEGER ,
637
- null ,
638
- ['nullable ' => false , 'unsigned ' => true ]
639
- );
640
640
// Each entry will be unique.
641
641
$ temporaryTable ->addIndex (
642
642
'idx_primary ' ,
@@ -649,12 +649,6 @@ protected function makeTempCategoryTreeIndex()
649
649
['child_id ' ],
650
650
['type ' => \Magento \Framework \DB \Adapter \AdapterInterface::INDEX_TYPE_INDEX ]
651
651
);
652
-
653
- $ temporaryTable ->addIndex (
654
- 'store_id ' ,
655
- ['store_id ' ],
656
- ['type ' => \Magento \Framework \DB \Adapter \AdapterInterface::INDEX_TYPE_INDEX ]
657
- );
658
652
// Drop the temporary table in case it already exists on this (persistent?) connection.
659
653
$ this ->connection ->dropTemporaryTable ($ temporaryName );
660
654
$ this ->connection ->createTemporaryTable ($ temporaryTable );
@@ -684,11 +678,19 @@ protected function fillTempCategoryTreeIndex($temporaryName)
684
678
['c ' => $ this ->getTable ('catalog_category_entity ' )],
685
679
['entity_id ' , 'path ' ]
686
680
)->joinInner (
687
- ['ccei ' => $ this ->getTable ('catalog_category_entity_int ' )],
688
- 'ccei. ' . $ categoryLinkField . ' = c. ' . $ categoryLinkField .
689
- ' AND ccei.attribute_id = ' . $ isActiveAttributeId .
690
- ' AND ccei.value = 1 ' ,
691
- ['store_id ' ]
681
+ ['ccacd ' => $ this ->getTable ('catalog_category_entity_int ' )],
682
+ 'ccacd. ' . $ categoryLinkField . ' = c. ' . $ categoryLinkField . ' AND ccacd.store_id = 0 ' .
683
+ ' AND ccacd.attribute_id = ' . $ isActiveAttributeId ,
684
+ []
685
+ )->joinLeft (
686
+ ['ccacs ' => $ this ->getTable ('catalog_category_entity_int ' )],
687
+ 'ccacs. ' . $ categoryLinkField . ' = c. ' . $ categoryLinkField
688
+ . ' AND ccacs.attribute_id = ccacd.attribute_id AND ccacs.store_id = ' .
689
+ $ this ->currentStoreId ,
690
+ []
691
+ )->where (
692
+ $ this ->connection ->getIfNullSql ('ccacs.value ' , 'ccacd.value ' ) . ' = ? ' ,
693
+ 1
692
694
),
693
695
'entity_id '
694
696
);
@@ -699,13 +701,13 @@ protected function fillTempCategoryTreeIndex($temporaryName)
699
701
foreach ($ this ->connection ->fetchAll ($ select ) as $ category ) {
700
702
foreach (explode ('/ ' , $ category ['path ' ]) as $ parentId ) {
701
703
if ($ parentId !== $ category ['entity_id ' ]) {
702
- $ values [] = [$ parentId , $ category ['entity_id ' ], $ category [ ' store_id ' ] ];
704
+ $ values [] = [$ parentId , $ category ['entity_id ' ]];
703
705
}
704
706
}
705
707
}
706
708
707
709
if (count ($ values ) > 0 ) {
708
- $ this ->connection ->insertArray ($ temporaryName , ['parent_id ' , 'child_id ' , ' store_id ' ], $ values );
710
+ $ this ->connection ->insertArray ($ temporaryName , ['parent_id ' , 'child_id ' ], $ values );
709
711
}
710
712
}
711
713
}
0 commit comments