Skip to content

Fixes #1937 preventing displaying all products from catalog on deleted virtual category#2007

Open
vahonc wants to merge 2 commits into
Smile-SA:2.9.xfrom
vahonc:1937-displaying-all-products-on-deleted-virtual-category
Open

Fixes #1937 preventing displaying all products from catalog on deleted virtual category#2007
vahonc wants to merge 2 commits into
Smile-SA:2.9.xfrom
vahonc:1937-displaying-all-products-on-deleted-virtual-category

Conversation

@vahonc
Copy link
Copy Markdown
Collaborator

@vahonc vahonc commented Nov 27, 2020

No description provided.

public function getCategorySearchQuery($category, $excludedCategories = []): ?QueryInterface
{
$query = null;
$rootCategory = null;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't a reason to initialize that variable since it is systematically overwritten in your additional condition.

Comment on lines +150 to +156
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)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of the approach since it integrates part of the logic of checking the existence of the root category in \Smile\ElasticsuiteVirtualCategory\Model\Rule::getVirtualRootCategory.
I would change the logic of \Smile\ElasticsuiteVirtualCategory\Model\Rule::getVirtualCategoryQuery so that it returns a null query if \Smile\ElasticsuiteVirtualCategory\Model\Rule::getVirtualRootCategory returns null and change this section of code in \Smile\ElasticsuiteVirtualCategory\Model\Rule::getCategorySearchQuery
with something like this :

            if ($category->getIsActive()) {
                if ((bool) $category->getIsVirtualCategory()) {
                  $query = $this->getVirtualCategoryQuery($category, $excludedCategories, $category->getData('virtual_category_root'));
                }
                if (!$query) {
                  if ($category->getId() {
                    $query = $this->getStandardCategoryQuery($category, $excludedCategories);
                  }
                }
            }
            if ($query && $category->hasChildren()) {
                $query = $this->addChildrenQueries($query, $category, $excludedCategories);
            }

But it's not perfect, and still a bit more complex.

On an additional note, your fix will apply when visiting the virtual category, but won't have any effect on parent categories, so we might want to address the problem as a whole by looking at what would happen in \Smile\ElasticsuiteVirtualCategory\Model\Rule::addChildrenQueries

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conclusion: we need to discuss this.

@rbayet rbayet assigned vahonc and unassigned romainruaud Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants