Skip to content

Commit

Permalink
Fixes Smile-SA#1937 preventing displaying all products from catalog o…
Browse files Browse the repository at this point in the history
…n deleted virtual category
  • Loading branch information
vahonc committed Nov 27, 2020
1 parent 5aa4575 commit c2f6b11
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/module-elasticsuite-virtual-category/Model/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,19 @@ 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);
}

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())) {

This comment has been minimized.

Copy link
@amenk

amenk Nov 29, 2020

I believe here $rootCategory can still be null so ->getId() would fail?

This comment has been minimized.

Copy link
@vahonc

vahonc Dec 4, 2020

Author Owner

Yes if $rootCategory will be a null then ->getId() would fail

In this case, to be more correctly, we can update code smth like this:

if ($category->getIsVirtualCategory() && $category->getVirtualCategoryRoot() !== null && !empty($category->getVirtualCategoryRoot())) {
                $rootCategoryId = $category->getVirtualCategoryRoot();
                $rootCategory = $this->categoryFactory->create()->setStoreId($this->getStoreId())->load($rootCategoryId);
                $catId = $rootCategory->getId();
            }
            if ((bool) $category->getIsVirtualCategory() && $category->getIsActive() && isset($catId)) {

What do you think?

This comment has been minimized.

Copy link
@amenk

amenk Dec 5, 2020

yes, seems to make sense

$query = $this->getVirtualCategoryQuery($category, $excludedCategories, $category->getData('virtual_category_root'));
} elseif ($category->getId() && $category->getIsActive()) {
$query = $this->getStandardCategoryQuery($category, $excludedCategories);
Expand Down

0 comments on commit c2f6b11

Please sign in to comment.