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 ;
@@ -312,19 +314,17 @@ protected function getPathFromCategoryId($categoryId)
312
314
protected function getNonAnchorCategoriesSelect (Store $ store )
313
315
{
314
316
if (!isset ($ this ->nonAnchorSelects [$ store ->getId ()])) {
315
- $ statusAttributeId = $ this ->config ->getAttribute (
316
- Product::ENTITY ,
317
- 'status '
318
- )->getId ();
319
- $ visibilityAttributeId = $ this ->config ->getAttribute (
320
- Product::ENTITY ,
321
- 'visibility '
322
- )->getId ();
317
+ $ statusAttributeId = $ this ->config ->getAttribute (Product::ENTITY , 'status ' )->getId ();
318
+ $ visibilityAttributeId = $ this ->config ->getAttribute (Product::ENTITY , 'visibility ' )->getId ();
319
+ $ isActiveAttributeId = $ this ->config ->getAttribute (Category::ENTITY , 'is_active ' )->getId ();
323
320
324
321
$ rootPath = $ this ->getPathFromCategoryId ($ store ->getRootCategoryId ());
325
322
326
- $ metadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
327
- $ linkField = $ metadata ->getLinkField ();
323
+ $ productMetadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
324
+ $ productLinkField = $ productMetadata ->getLinkField ();
325
+ $ categoryMetadata = $ this ->metadataPool ->getMetadata (CategoryInterface::class);
326
+ $ categoryLinkField = $ categoryMetadata ->getLinkField ();
327
+
328
328
$ select = $ this ->connection ->select ()->from (
329
329
['cc ' => $ this ->getTable ('catalog_category_entity ' )],
330
330
[]
@@ -342,28 +342,37 @@ protected function getNonAnchorCategoriesSelect(Store $store)
342
342
[]
343
343
)->joinInner (
344
344
['cpsd ' => $ this ->getTable ('catalog_product_entity_int ' )],
345
- 'cpsd. ' . $ linkField . ' = cpe. ' . $ linkField . ' AND cpsd.store_id = 0 ' .
346
- ' AND cpsd.attribute_id = ' .
347
- $ statusAttributeId ,
345
+ 'cpsd. ' . $ productLinkField . ' = cpe. ' . $ productLinkField . ' AND cpsd.store_id = 0 ' .
346
+ ' AND cpsd.attribute_id = ' . $ statusAttributeId ,
348
347
[]
349
348
)->joinLeft (
350
349
['cpss ' => $ this ->getTable ('catalog_product_entity_int ' )],
351
- 'cpss. ' . $ linkField . ' = cpe. ' . $ linkField . ' AND cpss.attribute_id = cpsd.attribute_id ' .
352
- ' AND cpss.store_id = ' .
353
- $ store ->getId (),
350
+ 'cpss. ' . $ productLinkField . ' = cpe. ' . $ productLinkField .
351
+ ' AND cpss.attribute_id = cpsd.attribute_id AND cpss.store_id = ' . $ store ->getId (),
354
352
[]
355
353
)->joinInner (
356
354
['cpvd ' => $ this ->getTable ('catalog_product_entity_int ' )],
357
- 'cpvd. ' . $ linkField . ' = cpe. ' . $ linkField . ' AND cpvd.store_id = 0 ' .
358
- ' AND cpvd.attribute_id = ' .
359
- $ visibilityAttributeId ,
355
+ 'cpvd. ' . $ productLinkField . ' = cpe. ' . $ productLinkField . ' AND cpvd.store_id = 0 ' .
356
+ ' AND cpvd.attribute_id = ' . $ visibilityAttributeId ,
360
357
[]
361
358
)->joinLeft (
362
359
['cpvs ' => $ this ->getTable ('catalog_product_entity_int ' )],
363
- 'cpvs. ' . $ linkField . ' = cpe. ' . $ linkField . ' AND cpvs.attribute_id = cpvd.attribute_id ' .
364
- ' AND cpvs.store_id = ' .
365
- $ store ->getId (),
360
+ 'cpvs. ' . $ productLinkField . ' = cpe. ' . $ productLinkField .
361
+ ' AND cpvs.attribute_id = cpvd.attribute_id AND cpvs.store_id = ' . $ store ->getId (),
362
+ []
363
+ )->joinInner (
364
+ ['ccacd ' => $ this ->getTable ('catalog_category_entity_int ' )],
365
+ 'ccacd. ' . $ categoryLinkField . ' = cc. ' . $ categoryLinkField . ' AND ccacd.store_id = 0 ' .
366
+ ' AND ccacd.attribute_id = ' . $ isActiveAttributeId ,
366
367
[]
368
+ )->joinLeft (
369
+ ['ccacs ' => $ this ->getTable ('catalog_category_entity_int ' )],
370
+ 'ccacs. ' . $ categoryLinkField . ' = cc. ' . $ categoryLinkField .
371
+ ' AND ccacs.attribute_id = ccacd.attribute_id AND ccacs.store_id = ' . $ store ->getId (),
372
+ []
373
+ )->where (
374
+ $ this ->connection ->getIfNullSql ('ccacs.value ' , 'ccacd.value ' ) . ' = ? ' ,
375
+ 1
367
376
)->where (
368
377
'cc.path LIKE ' . $ this ->connection ->quote ($ rootPath . '/% ' )
369
378
)->where (
@@ -530,10 +539,8 @@ protected function hasAnchorSelect(Store $store)
530
539
protected function createAnchorSelect (Store $ store )
531
540
{
532
541
$ this ->setCurrentStore ($ store );
533
- $ isAnchorAttributeId = $ this ->config ->getAttribute (
534
- \Magento \Catalog \Model \Category::ENTITY ,
535
- 'is_anchor '
536
- )->getId ();
542
+ $ isAnchorAttributeId = $ this ->config ->getAttribute (Category::ENTITY , 'is_anchor ' )->getId ();
543
+ $ isActiveAttributeId = $ this ->config ->getAttribute (Category::ENTITY , 'is_active ' )->getId ();
537
544
$ statusAttributeId = $ this ->config ->getAttribute (Product::ENTITY , 'status ' )->getId ();
538
545
$ visibilityAttributeId = $ this ->config ->getAttribute (Product::ENTITY , 'visibility ' )->getId ();
539
546
$ rootCatIds = explode ('/ ' , $ this ->getPathFromCategoryId ($ store ->getRootCategoryId ()));
@@ -542,7 +549,7 @@ protected function createAnchorSelect(Store $store)
542
549
$ temporaryTreeTable = $ this ->makeTempCategoryTreeIndex ();
543
550
544
551
$ productMetadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
545
- $ categoryMetadata = $ this ->metadataPool ->getMetadata (\ Magento \ Catalog \ Api \ Data \ CategoryInterface::class);
552
+ $ categoryMetadata = $ this ->metadataPool ->getMetadata (CategoryInterface::class);
546
553
$ productLinkField = $ productMetadata ->getLinkField ();
547
554
$ categoryLinkField = $ categoryMetadata ->getLinkField ();
548
555
@@ -580,21 +587,18 @@ protected function createAnchorSelect(Store $store)
580
587
[]
581
588
)->joinLeft (
582
589
['cpss ' => $ this ->getTable ('catalog_product_entity_int ' )],
583
- 'cpss. ' . $ productLinkField . ' = cpe. ' . $ productLinkField . ' AND cpss.attribute_id = cpsd.attribute_id ' .
584
- ' AND cpss.store_id = ' .
585
- $ store ->getId (),
590
+ 'cpss. ' . $ productLinkField . ' = cpe. ' . $ productLinkField .
591
+ ' AND cpss.attribute_id = cpsd.attribute_id AND cpss.store_id = ' . $ store ->getId (),
586
592
[]
587
593
)->joinInner (
588
594
['cpvd ' => $ this ->getTable ('catalog_product_entity_int ' )],
589
595
'cpvd. ' . $ productLinkField . ' = cpe. ' . $ productLinkField . ' AND cpvd.store_id = 0 ' .
590
- ' AND cpvd.attribute_id = ' .
591
- $ visibilityAttributeId ,
596
+ ' AND cpvd.attribute_id = ' . $ visibilityAttributeId ,
592
597
[]
593
598
)->joinLeft (
594
599
['cpvs ' => $ this ->getTable ('catalog_product_entity_int ' )],
595
600
'cpvs. ' . $ productLinkField . ' = cpe. ' . $ productLinkField .
596
- ' AND cpvs.attribute_id = cpvd.attribute_id ' . 'AND cpvs.store_id = ' .
597
- $ store ->getId (),
601
+ ' AND cpvs.attribute_id = cpvd.attribute_id ' . 'AND cpvs.store_id = ' . $ store ->getId (),
598
602
[]
599
603
)->joinInner (
600
604
['ccad ' => $ this ->getTable ('catalog_category_entity_int ' )],
@@ -604,9 +608,21 @@ protected function createAnchorSelect(Store $store)
604
608
)->joinLeft (
605
609
['ccas ' => $ this ->getTable ('catalog_category_entity_int ' )],
606
610
'ccas. ' . $ categoryLinkField . ' = cc. ' . $ categoryLinkField
607
- . ' AND ccas.attribute_id = ccad.attribute_id AND ccas.store_id = ' .
608
- $ store ->getId (),
611
+ . ' AND ccas.attribute_id = ccad.attribute_id AND ccas.store_id = ' . $ store ->getId (),
609
612
[]
613
+ )->joinInner (
614
+ ['ccacd ' => $ this ->getTable ('catalog_category_entity_int ' )],
615
+ 'ccacd. ' . $ categoryLinkField . ' = cc. ' . $ categoryLinkField . ' AND ccacd.store_id = 0 ' .
616
+ ' AND ccacd.attribute_id = ' . $ isActiveAttributeId ,
617
+ []
618
+ )->joinLeft (
619
+ ['ccacs ' => $ this ->getTable ('catalog_category_entity_int ' )],
620
+ 'ccacs. ' . $ categoryLinkField . ' = cc. ' . $ categoryLinkField
621
+ . ' AND ccacs.attribute_id = ccacd.attribute_id AND ccacs.store_id = ' . $ store ->getId (),
622
+ []
623
+ )->where (
624
+ $ this ->connection ->getIfNullSql ('ccacs.value ' , 'ccacd.value ' ) . ' = ? ' ,
625
+ 1
610
626
)->where (
611
627
'cpw.website_id = ? ' ,
612
628
$ store ->getWebsiteId ()
@@ -712,11 +728,8 @@ protected function makeTempCategoryTreeIndex()
712
728
*/
713
729
protected function fillTempCategoryTreeIndex ($ temporaryName )
714
730
{
715
- $ isActiveAttributeId = $ this ->config ->getAttribute (
716
- \Magento \Catalog \Model \Category::ENTITY ,
717
- 'is_active '
718
- )->getId ();
719
- $ categoryMetadata = $ this ->metadataPool ->getMetadata (\Magento \Catalog \Api \Data \CategoryInterface::class);
731
+ $ isActiveAttributeId = $ this ->config ->getAttribute (Category::ENTITY , 'is_active ' )->getId ();
732
+ $ categoryMetadata = $ this ->metadataPool ->getMetadata (CategoryInterface::class);
720
733
$ categoryLinkField = $ categoryMetadata ->getLinkField ();
721
734
$ selects = $ this ->prepareSelectsByRange (
722
735
$ this ->connection ->select ()
0 commit comments