From aec4a11b14c3da5e0f92d57d7e27476ba28209c2 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 7 Oct 2020 23:48:45 +0100 Subject: [PATCH] Pass excluded categories by reference --- .../Api/Data/VirtualRuleInterface.php | 2 +- .../Model/Rule.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/module-elasticsuite-virtual-category/Api/Data/VirtualRuleInterface.php b/src/module-elasticsuite-virtual-category/Api/Data/VirtualRuleInterface.php index b438465bf..e921b44e6 100644 --- a/src/module-elasticsuite-virtual-category/Api/Data/VirtualRuleInterface.php +++ b/src/module-elasticsuite-virtual-category/Api/Data/VirtualRuleInterface.php @@ -33,7 +33,7 @@ interface VirtualRuleInterface * * @return \Smile\ElasticsuiteCore\Search\Request\QueryInterface */ - public function getCategorySearchQuery($category, $excludedCategories = []); + public function getCategorySearchQuery($category, &$excludedCategories = []); /** * Retrieve search queries of children categories. diff --git a/src/module-elasticsuite-virtual-category/Model/Rule.php b/src/module-elasticsuite-virtual-category/Model/Rule.php index cc75b92c6..00dfe73dd 100644 --- a/src/module-elasticsuite-virtual-category/Model/Rule.php +++ b/src/module-elasticsuite-virtual-category/Model/Rule.php @@ -136,7 +136,7 @@ public function __toString(): string * * @return QueryInterface|null */ - public function getCategorySearchQuery($category, $excludedCategories = []): ?QueryInterface + public function getCategorySearchQuery($category, &$excludedCategories = []): ?QueryInterface { $query = null; @@ -247,7 +247,7 @@ private function getVirtualRootCategory(CategoryInterface $category): ?CategoryI * * @return QueryInterface */ - private function getStandardCategoryQuery(CategoryInterface $category, $excludedCategories = []): QueryInterface + private function getStandardCategoryQuery(CategoryInterface $category, &$excludedCategories = []): QueryInterface { return $this->getStandardCategoriesQuery([$category->getId()], $excludedCategories); } @@ -260,7 +260,7 @@ private function getStandardCategoryQuery(CategoryInterface $category, $excluded * * @return QueryInterface */ - private function getStandardCategoriesQuery(array $categoryIds, $excludedCategories): QueryInterface + private function getStandardCategoriesQuery(array $categoryIds, &$excludedCategories): QueryInterface { $conditionsParams = ['data' => ['attribute' => 'category_ids', 'operator' => '()', 'value' => $categoryIds]]; $categoryCondition = $this->productConditionsFactory->create($conditionsParams); @@ -279,7 +279,7 @@ private function getStandardCategoriesQuery(array $categoryIds, $excludedCategor */ private function getVirtualCategoryQuery( CategoryInterface $category, - $excludedCategories = [], + &$excludedCategories = [], $virtualCategoryRoot = null ): ?QueryInterface { $query = $category->getVirtualRule()->getConditions()->getSearchQuery($excludedCategories, $virtualCategoryRoot); @@ -309,7 +309,7 @@ private function getVirtualCategoryQuery( * * @return \Smile\ElasticsuiteCore\Search\Request\QueryInterface */ - private function addChildrenQueries($query, CategoryInterface $category, $excludedCategories = []): QueryInterface + private function addChildrenQueries($query, CategoryInterface $category, &$excludedCategories = []): QueryInterface { $childrenCategories = $this->getChildrenCategories($category, $excludedCategories); $childrenCategoriesIds = []; @@ -348,7 +348,7 @@ private function addChildrenQueries($query, CategoryInterface $category, $exclud * * @return Collection */ - private function getChildrenCategories(CategoryInterface $category, $excludedCategories = []): Collection + private function getChildrenCategories(CategoryInterface $category, &$excludedCategories = []): Collection { $storeId = $category->getStoreId(); $categoryCollection = $this->categoryCollectionFactory->create()->setStoreId($storeId);