6
6
7
7
namespace Magento \Catalog \Model \Indexer \Category \Product ;
8
8
9
+ use Magento \Catalog \Api \Data \CategoryInterface ;
9
10
use Magento \Catalog \Api \Data \ProductInterface ;
11
+ use Magento \Catalog \Model \Category ;
10
12
use Magento \Catalog \Model \Product ;
11
13
use Magento \Framework \App \ObjectManager ;
12
14
use Magento \Framework \App \ResourceConnection ;
@@ -303,19 +305,17 @@ protected function getPathFromCategoryId($categoryId)
303
305
protected function getNonAnchorCategoriesSelect (Store $ store )
304
306
{
305
307
if (!isset ($ this ->nonAnchorSelects [$ store ->getId ()])) {
306
- $ statusAttributeId = $ this ->config ->getAttribute (
307
- Product::ENTITY ,
308
- 'status '
309
- )->getId ();
310
- $ visibilityAttributeId = $ this ->config ->getAttribute (
311
- Product::ENTITY ,
312
- 'visibility '
313
- )->getId ();
308
+ $ statusAttributeId = $ this ->config ->getAttribute (Product::ENTITY , 'status ' )->getId ();
309
+ $ visibilityAttributeId = $ this ->config ->getAttribute (Product::ENTITY , 'visibility ' )->getId ();
310
+ $ isActiveAttributeId = $ this ->config ->getAttribute (Category::ENTITY , 'is_active ' )->getId ();
314
311
315
312
$ rootPath = $ this ->getPathFromCategoryId ($ store ->getRootCategoryId ());
316
313
317
- $ metadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
318
- $ linkField = $ metadata ->getLinkField ();
314
+ $ productMetadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
315
+ $ productLinkField = $ productMetadata ->getLinkField ();
316
+ $ categoryMetadata = $ this ->metadataPool ->getMetadata (CategoryInterface::class);
317
+ $ categoryLinkField = $ categoryMetadata ->getLinkField ();
318
+
319
319
$ select = $ this ->connection ->select ()->from (
320
320
['cc ' => $ this ->getTable ('catalog_category_entity ' )],
321
321
[]
@@ -333,28 +333,37 @@ protected function getNonAnchorCategoriesSelect(Store $store)
333
333
[]
334
334
)->joinInner (
335
335
['cpsd ' => $ this ->getTable ('catalog_product_entity_int ' )],
336
- 'cpsd. ' . $ linkField . ' = cpe. ' . $ linkField . ' AND cpsd.store_id = 0 ' .
337
- ' AND cpsd.attribute_id = ' .
338
- $ statusAttributeId ,
336
+ 'cpsd. ' . $ productLinkField . ' = cpe. ' . $ productLinkField . ' AND cpsd.store_id = 0 ' .
337
+ ' AND cpsd.attribute_id = ' . $ statusAttributeId ,
339
338
[]
340
339
)->joinLeft (
341
340
['cpss ' => $ this ->getTable ('catalog_product_entity_int ' )],
342
- 'cpss. ' . $ linkField . ' = cpe. ' . $ linkField . ' AND cpss.attribute_id = cpsd.attribute_id ' .
343
- ' AND cpss.store_id = ' .
344
- $ store ->getId (),
341
+ 'cpss. ' . $ productLinkField . ' = cpe. ' . $ productLinkField .
342
+ ' AND cpss.attribute_id = cpsd.attribute_id AND cpss.store_id = ' . $ store ->getId (),
345
343
[]
346
344
)->joinInner (
347
345
['cpvd ' => $ this ->getTable ('catalog_product_entity_int ' )],
348
- 'cpvd. ' . $ linkField . ' = cpe. ' . $ linkField . ' AND cpvd.store_id = 0 ' .
349
- ' AND cpvd.attribute_id = ' .
350
- $ visibilityAttributeId ,
346
+ 'cpvd. ' . $ productLinkField . ' = cpe. ' . $ productLinkField . ' AND cpvd.store_id = 0 ' .
347
+ ' AND cpvd.attribute_id = ' . $ visibilityAttributeId ,
351
348
[]
352
349
)->joinLeft (
353
350
['cpvs ' => $ this ->getTable ('catalog_product_entity_int ' )],
354
- 'cpvs. ' . $ linkField . ' = cpe. ' . $ linkField . ' AND cpvs.attribute_id = cpvd.attribute_id ' .
355
- ' AND cpvs.store_id = ' .
356
- $ store ->getId (),
351
+ 'cpvs. ' . $ productLinkField . ' = cpe. ' . $ productLinkField .
352
+ ' AND cpvs.attribute_id = cpvd.attribute_id AND cpvs.store_id = ' . $ store ->getId (),
353
+ []
354
+ )->joinInner (
355
+ ['ccacd ' => $ this ->getTable ('catalog_category_entity_int ' )],
356
+ 'ccacd. ' . $ categoryLinkField . ' = cc. ' . $ categoryLinkField . ' AND ccacd.store_id = 0 ' .
357
+ ' AND ccacd.attribute_id = ' . $ isActiveAttributeId ,
357
358
[]
359
+ )->joinLeft (
360
+ ['ccacs ' => $ this ->getTable ('catalog_category_entity_int ' )],
361
+ 'ccacs. ' . $ categoryLinkField . ' = cc. ' . $ categoryLinkField .
362
+ ' AND ccacs.attribute_id = ccacd.attribute_id AND ccacs.store_id = ' . $ store ->getId (),
363
+ []
364
+ )->where (
365
+ $ this ->connection ->getIfNullSql ('ccacs.value ' , 'ccacd.value ' ) . ' = ? ' ,
366
+ 1
358
367
)->where (
359
368
'cc.path LIKE ' . $ this ->connection ->quote ($ rootPath . '/% ' )
360
369
)->where (
@@ -525,10 +534,8 @@ protected function hasAnchorSelect(Store $store)
525
534
protected function createAnchorSelect (Store $ store )
526
535
{
527
536
$ this ->setCurrentStore ($ store );
528
- $ isAnchorAttributeId = $ this ->config ->getAttribute (
529
- \Magento \Catalog \Model \Category::ENTITY ,
530
- 'is_anchor '
531
- )->getId ();
537
+ $ isAnchorAttributeId = $ this ->config ->getAttribute (Category::ENTITY , 'is_anchor ' )->getId ();
538
+ $ isActiveAttributeId = $ this ->config ->getAttribute (Category::ENTITY , 'is_active ' )->getId ();
532
539
$ statusAttributeId = $ this ->config ->getAttribute (Product::ENTITY , 'status ' )->getId ();
533
540
$ visibilityAttributeId = $ this ->config ->getAttribute (Product::ENTITY , 'visibility ' )->getId ();
534
541
$ rootCatIds = explode ('/ ' , $ this ->getPathFromCategoryId ($ store ->getRootCategoryId ()));
@@ -537,7 +544,7 @@ protected function createAnchorSelect(Store $store)
537
544
$ temporaryTreeTable = $ this ->makeTempCategoryTreeIndex ();
538
545
539
546
$ productMetadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
540
- $ categoryMetadata = $ this ->metadataPool ->getMetadata (\ Magento \ Catalog \ Api \ Data \ CategoryInterface::class);
547
+ $ categoryMetadata = $ this ->metadataPool ->getMetadata (CategoryInterface::class);
541
548
$ productLinkField = $ productMetadata ->getLinkField ();
542
549
$ categoryLinkField = $ categoryMetadata ->getLinkField ();
543
550
@@ -575,21 +582,18 @@ protected function createAnchorSelect(Store $store)
575
582
[]
576
583
)->joinLeft (
577
584
['cpss ' => $ this ->getTable ('catalog_product_entity_int ' )],
578
- 'cpss. ' . $ productLinkField . ' = cpe. ' . $ productLinkField . ' AND cpss.attribute_id = cpsd.attribute_id ' .
579
- ' AND cpss.store_id = ' .
580
- $ store ->getId (),
585
+ 'cpss. ' . $ productLinkField . ' = cpe. ' . $ productLinkField .
586
+ ' AND cpss.attribute_id = cpsd.attribute_id AND cpss.store_id = ' . $ store ->getId (),
581
587
[]
582
588
)->joinInner (
583
589
['cpvd ' => $ this ->getTable ('catalog_product_entity_int ' )],
584
590
'cpvd. ' . $ productLinkField . ' = cpe. ' . $ productLinkField . ' AND cpvd.store_id = 0 ' .
585
- ' AND cpvd.attribute_id = ' .
586
- $ visibilityAttributeId ,
591
+ ' AND cpvd.attribute_id = ' . $ visibilityAttributeId ,
587
592
[]
588
593
)->joinLeft (
589
594
['cpvs ' => $ this ->getTable ('catalog_product_entity_int ' )],
590
595
'cpvs. ' . $ productLinkField . ' = cpe. ' . $ productLinkField .
591
- ' AND cpvs.attribute_id = cpvd.attribute_id ' . 'AND cpvs.store_id = ' .
592
- $ store ->getId (),
596
+ ' AND cpvs.attribute_id = cpvd.attribute_id ' . 'AND cpvs.store_id = ' . $ store ->getId (),
593
597
[]
594
598
)->joinInner (
595
599
['ccad ' => $ this ->getTable ('catalog_category_entity_int ' )],
@@ -599,9 +603,21 @@ protected function createAnchorSelect(Store $store)
599
603
)->joinLeft (
600
604
['ccas ' => $ this ->getTable ('catalog_category_entity_int ' )],
601
605
'ccas. ' . $ categoryLinkField . ' = cc. ' . $ categoryLinkField
602
- . ' AND ccas.attribute_id = ccad.attribute_id AND ccas.store_id = ' .
603
- $ store ->getId (),
606
+ . ' AND ccas.attribute_id = ccad.attribute_id AND ccas.store_id = ' . $ store ->getId (),
604
607
[]
608
+ )->joinInner (
609
+ ['ccacd ' => $ this ->getTable ('catalog_category_entity_int ' )],
610
+ 'ccacd. ' . $ categoryLinkField . ' = cc. ' . $ categoryLinkField . ' AND ccacd.store_id = 0 ' .
611
+ ' AND ccacd.attribute_id = ' . $ isActiveAttributeId ,
612
+ []
613
+ )->joinLeft (
614
+ ['ccacs ' => $ this ->getTable ('catalog_category_entity_int ' )],
615
+ 'ccacs. ' . $ categoryLinkField . ' = cc. ' . $ categoryLinkField
616
+ . ' AND ccacs.attribute_id = ccacd.attribute_id AND ccacs.store_id = ' . $ store ->getId (),
617
+ []
618
+ )->where (
619
+ $ this ->connection ->getIfNullSql ('ccacs.value ' , 'ccacd.value ' ) . ' = ? ' ,
620
+ 1
605
621
)->where (
606
622
'cpw.website_id = ? ' ,
607
623
$ store ->getWebsiteId ()
@@ -711,11 +727,8 @@ protected function makeTempCategoryTreeIndex()
711
727
*/
712
728
protected function fillTempCategoryTreeIndex ($ temporaryName )
713
729
{
714
- $ isActiveAttributeId = $ this ->config ->getAttribute (
715
- \Magento \Catalog \Model \Category::ENTITY ,
716
- 'is_active '
717
- )->getId ();
718
- $ categoryMetadata = $ this ->metadataPool ->getMetadata (\Magento \Catalog \Api \Data \CategoryInterface::class);
730
+ $ isActiveAttributeId = $ this ->config ->getAttribute (Category::ENTITY , 'is_active ' )->getId ();
731
+ $ categoryMetadata = $ this ->metadataPool ->getMetadata (CategoryInterface::class);
719
732
$ categoryLinkField = $ categoryMetadata ->getLinkField ();
720
733
$ selects = $ this ->prepareSelectsByRange (
721
734
$ this ->connection ->select ()
0 commit comments