@@ -499,7 +499,7 @@ protected function createAnchorSelect(Store $store)
499
499
'cc2.parent_id = cc.entity_id AND cc.entity_id NOT IN ( ' . implode (
500
500
', ' ,
501
501
$ rootCatIds
502
- ) . ') ' ,
502
+ ) . ') AND cc2.store_id = ' . $ store -> getId () ,
503
503
[]
504
504
)->joinInner (
505
505
['ccp ' => $ this ->getTable ('catalog_category_product ' )],
@@ -586,6 +586,8 @@ protected function createAnchorSelect(Store $store)
586
586
}
587
587
588
588
/**
589
+ * Get temporary table name
590
+ *
589
591
* Get temporary table name for concurrent indexing in persistent connection
590
592
* Temp table name is NOT shared between action instances and each action has it's own temp tree index
591
593
*
@@ -629,6 +631,12 @@ protected function makeTempCategoryTreeIndex()
629
631
null ,
630
632
['nullable ' => false , 'unsigned ' => true ]
631
633
);
634
+ $ temporaryTable ->addColumn (
635
+ 'store_id ' ,
636
+ \Magento \Framework \DB \Ddl \Table::TYPE_INTEGER ,
637
+ null ,
638
+ ['nullable ' => false , 'unsigned ' => true ]
639
+ );
632
640
// Each entry will be unique.
633
641
$ temporaryTable ->addIndex (
634
642
'idx_primary ' ,
@@ -642,6 +650,11 @@ protected function makeTempCategoryTreeIndex()
642
650
['type ' => \Magento \Framework \DB \Adapter \AdapterInterface::INDEX_TYPE_INDEX ]
643
651
);
644
652
653
+ $ temporaryTable ->addIndex (
654
+ 'store_id ' ,
655
+ ['store_id ' ],
656
+ ['type ' => \Magento \Framework \DB \Adapter \AdapterInterface::INDEX_TYPE_INDEX ]
657
+ );
645
658
// Drop the temporary table in case it already exists on this (persistent?) connection.
646
659
$ this ->connection ->dropTemporaryTable ($ temporaryName );
647
660
$ this ->connection ->createTemporaryTable ($ temporaryTable );
@@ -659,11 +672,23 @@ protected function makeTempCategoryTreeIndex()
659
672
*/
660
673
protected function fillTempCategoryTreeIndex ($ temporaryName )
661
674
{
675
+ $ isActiveAttributeId = $ this ->config ->getAttribute (
676
+ \Magento \Catalog \Model \Category::ENTITY ,
677
+ 'is_active '
678
+ )->getId ();
679
+ $ categoryMetadata = $ this ->metadataPool ->getMetadata (\Magento \Catalog \Api \Data \CategoryInterface::class);
680
+ $ categoryLinkField = $ categoryMetadata ->getLinkField ();
662
681
$ selects = $ this ->prepareSelectsByRange (
663
682
$ this ->connection ->select ()
664
683
->from (
665
684
['c ' => $ this ->getTable ('catalog_category_entity ' )],
666
685
['entity_id ' , 'path ' ]
686
+ )->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 ' ]
667
692
),
668
693
'entity_id '
669
694
);
@@ -674,13 +699,13 @@ protected function fillTempCategoryTreeIndex($temporaryName)
674
699
foreach ($ this ->connection ->fetchAll ($ select ) as $ category ) {
675
700
foreach (explode ('/ ' , $ category ['path ' ]) as $ parentId ) {
676
701
if ($ parentId !== $ category ['entity_id ' ]) {
677
- $ values [] = [$ parentId , $ category ['entity_id ' ]];
702
+ $ values [] = [$ parentId , $ category ['entity_id ' ], $ category [ ' store_id ' ] ];
678
703
}
679
704
}
680
705
}
681
706
682
707
if (count ($ values ) > 0 ) {
683
- $ this ->connection ->insertArray ($ temporaryName , ['parent_id ' , 'child_id ' ], $ values );
708
+ $ this ->connection ->insertArray ($ temporaryName , ['parent_id ' , 'child_id ' , ' store_id ' ], $ values );
684
709
}
685
710
}
686
711
}
0 commit comments