4
4
5
5
use Algolia \AlgoliaSearch \Exception \CategoryEmptyException ;
6
6
use Algolia \AlgoliaSearch \Exception \CategoryNotActiveException ;
7
- use Algolia \AlgoliaSearch \Exception \CategoryNotIncludedInMenuException ;
8
7
use Algolia \AlgoliaSearch \Helper \ConfigHelper ;
9
8
use Algolia \AlgoliaSearch \Helper \Image ;
10
9
use Magento \Catalog \Model \Category ;
@@ -213,10 +212,6 @@ public function canCategoryBeReindexed($category, $storeId)
213
212
throw new CategoryEmptyException ();
214
213
}
215
214
216
- if ($ this ->configHelper ->showCatsNotIncludedInNavigation ($ storeId ) === false && !$ category ->getIncludeInMenu ()) {
217
- throw new CategoryNotIncludedInMenuException ();
218
- }
219
-
220
215
return true ;
221
216
}
222
217
@@ -490,7 +485,7 @@ private function getCategoryById($categoryId)
490
485
491
486
public function isCategoryVisibleInMenu ($ categoryId , $ storeId )
492
487
{
493
- $ key = $ categoryId . ' - ' . $ storeId ;
488
+ $ key = $ categoryId . '- ' . $ storeId ;
494
489
if (isset ($ this ->isCategoryVisibleInMenuCache [$ key ])) {
495
490
return $ this ->isCategoryVisibleInMenuCache [$ key ];
496
491
}
@@ -504,28 +499,33 @@ public function isCategoryVisibleInMenu($categoryId, $storeId)
504
499
return $ this ->isCategoryVisibleInMenuCache [$ key ];
505
500
}
506
501
507
- public function getCoreCategories ()
502
+ public function getCoreCategories ($ filterNotIncludedCategories = true )
508
503
{
509
- if (isset ($ this ->coreCategories )) {
510
- return $ this ->coreCategories ;
504
+ $ key = $ filterNotIncludedCategories ? 'filtered ' : 'non_filtered ' ;
505
+
506
+ if (isset ($ this ->coreCategories [$ key ])) {
507
+ return $ this ->coreCategories [$ key ];
511
508
}
512
509
513
510
$ collection = $ this ->categoryCollectionFactory ->create ()
514
511
->distinct (true )
515
512
->addNameToResult ()
516
513
->addIsActiveFilter ()
517
514
->addAttributeToSelect ('name ' )
518
- ->addAttributeToFilter ('include_in_menu ' , '1 ' )
519
515
->addAttributeToFilter ('level ' , ['gt ' => 1 ]);
520
516
521
- $ this ->coreCategories = [];
517
+ if ($ filterNotIncludedCategories ) {
518
+ $ collection ->addAttributeToFilter ('include_in_menu ' , '1 ' );
519
+ }
520
+
521
+ $ this ->coreCategories [$ key ] = [];
522
522
523
523
/** @var \Magento\Catalog\Model\Category $category */
524
524
foreach ($ collection as $ category ) {
525
- $ this ->coreCategories [$ category ->getId ()] = $ category ;
525
+ $ this ->coreCategories [$ key ][ $ category ->getId ()] = $ category ;
526
526
}
527
527
528
- return $ this ->coreCategories ;
528
+ return $ this ->coreCategories [ $ key ] ;
529
529
}
530
530
531
531
private function getCorrectIdColumn ()
0 commit comments