Skip to content

Commit 794242d

Browse files
bsuravechdamcou
authored andcommitted
Product Category Data - Include in Menu Configuration (#864)
1 parent 6772f39 commit 794242d

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

Helper/Entity/CategoryHelper.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Algolia\AlgoliaSearch\Exception\CategoryEmptyException;
66
use Algolia\AlgoliaSearch\Exception\CategoryNotActiveException;
7-
use Algolia\AlgoliaSearch\Exception\CategoryNotIncludedInMenuException;
87
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
98
use Algolia\AlgoliaSearch\Helper\Image;
109
use Magento\Catalog\Model\Category;
@@ -213,10 +212,6 @@ public function canCategoryBeReindexed($category, $storeId)
213212
throw new CategoryEmptyException();
214213
}
215214

216-
if ($this->configHelper->showCatsNotIncludedInNavigation($storeId) === false && !$category->getIncludeInMenu()) {
217-
throw new CategoryNotIncludedInMenuException();
218-
}
219-
220215
return true;
221216
}
222217

@@ -490,7 +485,7 @@ private function getCategoryById($categoryId)
490485

491486
public function isCategoryVisibleInMenu($categoryId, $storeId)
492487
{
493-
$key = $categoryId . ' - ' . $storeId;
488+
$key = $categoryId . '-' . $storeId;
494489
if (isset($this->isCategoryVisibleInMenuCache[$key])) {
495490
return $this->isCategoryVisibleInMenuCache[$key];
496491
}
@@ -504,28 +499,33 @@ public function isCategoryVisibleInMenu($categoryId, $storeId)
504499
return $this->isCategoryVisibleInMenuCache[$key];
505500
}
506501

507-
public function getCoreCategories()
502+
public function getCoreCategories($filterNotIncludedCategories = true)
508503
{
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];
511508
}
512509

513510
$collection = $this->categoryCollectionFactory->create()
514511
->distinct(true)
515512
->addNameToResult()
516513
->addIsActiveFilter()
517514
->addAttributeToSelect('name')
518-
->addAttributeToFilter('include_in_menu', '1')
519515
->addAttributeToFilter('level', ['gt' => 1]);
520516

521-
$this->coreCategories = [];
517+
if ($filterNotIncludedCategories) {
518+
$collection->addAttributeToFilter('include_in_menu', '1');
519+
}
520+
521+
$this->coreCategories[$key] = [];
522522

523523
/** @var \Magento\Catalog\Model\Category $category */
524524
foreach ($collection as $category) {
525-
$this->coreCategories[$category->getId()] = $category;
525+
$this->coreCategories[$key][$category->getId()] = $category;
526526
}
527527

528-
return $this->coreCategories;
528+
return $this->coreCategories[$key];
529529
}
530530

531531
private function getCorrectIdColumn()

Helper/Entity/ProductHelper.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
447447

448448
public function getAllCategories($categoryIds)
449449
{
450-
$categories = $this->categoryHelper->getCoreCategories();
450+
$categories = $this->categoryHelper->getCoreCategories(false);
451451

452452
$selectedCategories = [];
453453
foreach ($categoryIds as $id) {
@@ -653,13 +653,6 @@ private function addCategoryData($customData, Product $product)
653653
$path = [];
654654

655655
foreach ($category->getPathIds() as $treeCategoryId) {
656-
if (!$this->configHelper->showCatsNotIncludedInNavigation($storeId)
657-
&& !$this->categoryHelper->isCategoryVisibleInMenu($treeCategoryId, $storeId)) {
658-
// If the category should not be included in menu - skip it
659-
$path[] = null;
660-
continue;
661-
}
662-
663656
$name = $this->categoryHelper->getCategoryName($treeCategoryId, $storeId);
664657
if ($name) {
665658
$categoryIds[] = $treeCategoryId;

0 commit comments

Comments
 (0)