Skip to content

Commit 2718a05

Browse files
committed
Merge remote-tracking branch 'local/ACP2E-882' into PR_1_NOV_2022
2 parents 96a55c2 + cd606cd commit 2718a05

File tree

3 files changed

+49
-28
lines changed

3 files changed

+49
-28
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/CategoriesQuery.php

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
use Magento\CatalogGraphQl\Model\Category\CategoryFilter;
1111
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree;
1212
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\ExtractDataFromCategoryTree;
13+
use Magento\Framework\Api\Search\SearchCriteriaFactory;
1314
use Magento\Framework\Exception\InputException;
1415
use Magento\Framework\GraphQl\Config\Element\Field;
1516
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1617
use Magento\Framework\GraphQl\Query\Resolver\ArgumentsProcessorInterface;
1718
use Magento\Framework\GraphQl\Query\ResolverInterface;
1819
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
20+
use Magento\GraphQl\Model\Query\ContextInterface;
21+
use Magento\Store\Api\Data\StoreInterface;
1922

2023
/**
2124
* Categories resolver, used for GraphQL category data request processing.
@@ -42,22 +45,30 @@ class CategoriesQuery implements ResolverInterface
4245
*/
4346
private $argsSelection;
4447

48+
/**
49+
* @var SearchCriteriaFactory
50+
*/
51+
private $searchCriteriaFactory;
52+
4553
/**
4654
* @param CategoryTree $categoryTree
4755
* @param ExtractDataFromCategoryTree $extractDataFromCategoryTree
4856
* @param CategoryFilter $categoryFilter
4957
* @param ArgumentsProcessorInterface $argsSelection
58+
* @param SearchCriteriaFactory $searchCriteriaFactory
5059
*/
5160
public function __construct(
5261
CategoryTree $categoryTree,
5362
ExtractDataFromCategoryTree $extractDataFromCategoryTree,
5463
CategoryFilter $categoryFilter,
55-
ArgumentsProcessorInterface $argsSelection
64+
ArgumentsProcessorInterface $argsSelection,
65+
SearchCriteriaFactory $searchCriteriaFactory
5666
) {
5767
$this->categoryTree = $categoryTree;
5868
$this->extractDataFromCategoryTree = $extractDataFromCategoryTree;
5969
$this->categoryFilter = $categoryFilter;
6070
$this->argsSelection = $argsSelection;
71+
$this->searchCriteriaFactory = $searchCriteriaFactory;
6172
}
6273

6374
/**
@@ -87,7 +98,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8798

8899
$rootCategoryIds = $filterResult['category_ids'] ?? [];
89100

90-
$filterResult['items'] = $this->fetchCategories($rootCategoryIds, $info, (int) $store->getId());
101+
$filterResult['items'] = $this->fetchCategories($rootCategoryIds, $info, $store, $context);
91102
return $filterResult;
92103
}
93104

@@ -96,17 +107,28 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
96107
*
97108
* @param array $categoryIds
98109
* @param ResolveInfo $info
99-
* @param int $storeId
110+
* @param StoreInterface $store
111+
* @param ContextInterface $context
100112
* @return array
101113
*/
102-
private function fetchCategories(array $categoryIds, ResolveInfo $info, int $storeId)
103-
{
114+
private function fetchCategories(
115+
array $categoryIds,
116+
ResolveInfo $info,
117+
StoreInterface $store,
118+
ContextInterface $context
119+
) {
104120
$fetchedCategories = [];
105121
foreach ($categoryIds as $categoryId) {
106-
$categoryTree = $this->categoryTree->getTree($info, $categoryId, $storeId);
107-
if (empty($categoryTree)) {
108-
continue;
109-
}
122+
/* Search Criteria is created for compatibility */
123+
$searchCriteria = $this->searchCriteriaFactory->create();
124+
$categoryTree = $this->categoryTree->getFilteredTree(
125+
$info,
126+
$categoryId,
127+
$searchCriteria,
128+
$store,
129+
[],
130+
$context
131+
);
110132
$fetchedCategories[] = current($this->extractDataFromCategoryTree->execute($categoryTree));
111133
}
112134

app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryList.php

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

88
namespace Magento\CatalogGraphQl\Model\Resolver;
99

10+
use Magento\CatalogGraphQl\Model\Category\Filter\SearchCriteria;
1011
use Magento\Store\Api\Data\StoreInterface;
1112
use Magento\GraphQl\Model\Query\ContextInterface;
1213
use Magento\CatalogGraphQl\Model\Category\CategoryFilter;
@@ -45,22 +46,30 @@ class CategoryList implements ResolverInterface
4546
*/
4647
private $argsSelection;
4748

49+
/**
50+
* @var SearchCriteria
51+
*/
52+
private $searchCriteria;
53+
4854
/**
4955
* @param CategoryTree $categoryTree
5056
* @param ExtractDataFromCategoryTree $extractDataFromCategoryTree
5157
* @param CategoryFilter $categoryFilter
5258
* @param ArgumentsProcessorInterface $argsSelection
59+
* @param SearchCriteria $searchCriteria
5360
*/
5461
public function __construct(
5562
CategoryTree $categoryTree,
5663
ExtractDataFromCategoryTree $extractDataFromCategoryTree,
5764
CategoryFilter $categoryFilter,
58-
ArgumentsProcessorInterface $argsSelection
65+
ArgumentsProcessorInterface $argsSelection,
66+
SearchCriteria $searchCriteria
5967
) {
6068
$this->categoryTree = $categoryTree;
6169
$this->extractDataFromCategoryTree = $extractDataFromCategoryTree;
6270
$this->categoryFilter = $categoryFilter;
6371
$this->argsSelection = $argsSelection;
72+
$this->searchCriteria = $searchCriteria;
6473
}
6574

6675
/**
@@ -105,21 +114,19 @@ private function fetchCategories(
105114
array $criteria,
106115
StoreInterface $store,
107116
array $attributeNames,
108-
$context
117+
ContextInterface $context
109118
) : array {
110119
$fetchedCategories = [];
111120
foreach ($categoryIds as $categoryId) {
121+
$searchCriteria = $this->searchCriteria->buildCriteria($criteria, $store);
112122
$categoryTree = $this->categoryTree->getFilteredTree(
113123
$info,
114124
$categoryId,
115-
$criteria,
125+
$searchCriteria,
116126
$store,
117127
$attributeNames,
118128
$context
119129
);
120-
if (empty($categoryTree)) {
121-
continue;
122-
}
123130
$fetchedCategories[] = current($this->extractDataFromCategoryTree->execute($categoryTree));
124131
}
125132

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
1818
use Magento\CatalogGraphQl\Model\AttributesJoiner;
1919
use Magento\CatalogGraphQl\Model\Category\DepthCalculator;
20-
use Magento\CatalogGraphQl\Model\Category\Filter\SearchCriteria;
2120
use Magento\CatalogGraphQl\Model\Category\LevelCalculator;
2221
use Magento\CatalogGraphQl\Model\Resolver\Categories\DataProvider\Category\CollectionProcessorInterface;
22+
use Magento\Framework\Api\Search\SearchCriteria;
2323
use Magento\Framework\EntityManager\MetadataPool;
2424
use Magento\Framework\Exception\LocalizedException;
2525
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
@@ -68,36 +68,28 @@ class CategoryTree
6868
*/
6969
private $collectionProcessor;
7070

71-
/**
72-
* @var SearchCriteria
73-
*/
74-
private $searchCriteria;
75-
7671
/**
7772
* @param CollectionFactory $collectionFactory
7873
* @param AttributesJoiner $attributesJoiner
7974
* @param DepthCalculator $depthCalculator
8075
* @param LevelCalculator $levelCalculator
8176
* @param MetadataPool $metadata
8277
* @param CollectionProcessorInterface $collectionProcessor
83-
* @param SearchCriteria $searchCriteria
8478
*/
8579
public function __construct(
8680
CollectionFactory $collectionFactory,
8781
AttributesJoiner $attributesJoiner,
8882
DepthCalculator $depthCalculator,
8983
LevelCalculator $levelCalculator,
9084
MetadataPool $metadata,
91-
CollectionProcessorInterface $collectionProcessor,
92-
SearchCriteria $searchCriteria
85+
CollectionProcessorInterface $collectionProcessor
9386
) {
9487
$this->collectionFactory = $collectionFactory;
9588
$this->attributesJoiner = $attributesJoiner;
9689
$this->depthCalculator = $depthCalculator;
9790
$this->levelCalculator = $levelCalculator;
9891
$this->metadata = $metadata;
9992
$this->collectionProcessor = $collectionProcessor;
100-
$this->searchCriteria = $searchCriteria;
10193
}
10294

10395
/**
@@ -201,23 +193,23 @@ private function joinAttributesRecursively(
201193
*
202194
* @param ResolveInfo $resolveInfo
203195
* @param int $rootCategoryId
204-
* @param array $criteria
196+
* @param SearchCriteria $searchCriteria
205197
* @param StoreInterface $store
206198
* @param array $attributeNames
207199
* @param ContextInterface $context
208200
* @return Iterator
209201
* @throws LocalizedException
210202
* @throws Exception
203+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
211204
*/
212205
public function getFilteredTree(
213206
ResolveInfo $resolveInfo,
214207
int $rootCategoryId,
215-
array $criteria,
208+
SearchCriteria $searchCriteria,
216209
StoreInterface $store,
217210
array $attributeNames,
218211
ContextInterface $context
219212
): Iterator {
220-
$searchCriteria = $this->searchCriteria->buildCriteria($criteria, $store);
221213
$collection = $this->getCollection($resolveInfo, $rootCategoryId);
222214
$this->collectionProcessor->process($collection, $searchCriteria, $attributeNames, $context);
223215
return $collection->getIterator();

0 commit comments

Comments
 (0)