From c2f6b110a2fa626a4775a47945e50f62293da5ca Mon Sep 17 00:00:00 2001 From: Vadym Honcharuk Date: Fri, 27 Nov 2020 14:59:42 +0200 Subject: [PATCH] Fixes #1937 preventing displaying all products from catalog on deleted virtual category --- src/module-elasticsuite-virtual-category/Model/Rule.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/module-elasticsuite-virtual-category/Model/Rule.php b/src/module-elasticsuite-virtual-category/Model/Rule.php index cc75b92c6..4b307cf77 100644 --- a/src/module-elasticsuite-virtual-category/Model/Rule.php +++ b/src/module-elasticsuite-virtual-category/Model/Rule.php @@ -139,6 +139,7 @@ public function __toString(): string public function getCategorySearchQuery($category, $excludedCategories = []): ?QueryInterface { $query = null; + $rootCategory = null; if (!is_object($category)) { $category = $this->categoryFactory->create()->setStoreId($this->getStoreId())->load($category); @@ -146,8 +147,11 @@ public function getCategorySearchQuery($category, $excludedCategories = []): ?Qu if (!in_array($category->getId(), $excludedCategories)) { $excludedCategories[] = $category->getId(); - - if ((bool) $category->getIsVirtualCategory() && $category->getIsActive()) { + if ($category->getVirtualCategoryRoot() !== null && !empty($category->getVirtualCategoryRoot())) { + $rootCategoryId = $category->getVirtualCategoryRoot(); + $rootCategory = $this->categoryFactory->create()->setStoreId($this->getStoreId())->load($rootCategoryId); + } + if ((bool) $category->getIsVirtualCategory() && $category->getIsActive() && !is_null($rootCategory->getId())) { $query = $this->getVirtualCategoryQuery($category, $excludedCategories, $category->getData('virtual_category_root')); } elseif ($category->getId() && $category->getIsActive()) { $query = $this->getStandardCategoryQuery($category, $excludedCategories);