Skip to content

Commit 71fbb40

Browse files
authored
Merge branch '2.4-develop' into comm_78764_32435
2 parents c2ea86f + fd49fbc commit 71fbb40

File tree

32 files changed

+1115
-461
lines changed

32 files changed

+1115
-461
lines changed

app/code/Magento/BundleGraphQl/etc/graphql/di.xml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,4 @@
114114
</argument>
115115
</arguments>
116116
</type>
117-
<type name="Magento\BundleGraphQl\Model\Resolver\Options\Label">
118-
<arguments>
119-
<argument name="product" xsi:type="object">Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Deferred\ChildProduct</argument>
120-
</arguments>
121-
</type>
122-
<type name="Magento\BundleGraphQl\Model\Resolver\PriceRange">
123-
<arguments>
124-
<argument name="productDataProvider" xsi:type="object">Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Deferred\ChildProduct</argument>
125-
</arguments>
126-
</type>
127-
<virtualType name="Magento\BundleGraphQl\Model\Resolver\Options\Product"
128-
type="Magento\CatalogGraphQl\Model\Resolver\Product">
129-
<arguments>
130-
<argument name="productDataProvider" xsi:type="object">
131-
Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Deferred\ChildProduct
132-
</argument>
133-
</arguments>
134-
</virtualType>
135117
</config>

app/code/Magento/BundleGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type BundleItemOption @doc(description: "Defines the characteristics that compri
6969
price: Float @doc(description: "The price of the selected option.")
7070
price_type: PriceTypeEnum @doc(description: "One of FIXED, PERCENT, or DYNAMIC.")
7171
can_change_quantity: Boolean @doc(description: "Indicates whether the customer can change the number of items for this option.")
72-
product: ProductInterface @doc(description: "Contains details about this product option.") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Options\\Product")
72+
product: ProductInterface @doc(description: "Contains details about this product option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product")
7373
uid: ID! @doc(description: "The unique ID for a `BundleItemOption` object.") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Options\\BundleItemOptionUid")
7474
}
7575

app/code/Magento/Catalog/Model/ResourceModel/Product/ChildCollectionFactory.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

app/code/Magento/Catalog/Model/ResourceModel/Product/CollectionFactory.php

Lines changed: 0 additions & 53 deletions
This file was deleted.

app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function __construct(
6767
* @param StoreInterface $store
6868
* @param array $attributeNames
6969
* @param ContextInterface $context
70-
* @return int[]
70+
* @return array
7171
* @throws InputException
7272
*/
7373
public function getResult(array $criteria, StoreInterface $store, array $attributeNames, ContextInterface $context)
@@ -84,6 +84,7 @@ public function getResult(array $criteria, StoreInterface $store, array $attribu
8484
->columns(
8585
'e.entity_id'
8686
);
87+
$collection->setOrder('entity_id');
8788

8889
$categoryIds = $collection->load()->getLoadedIds();
8990

app/code/Magento/CatalogGraphQl/Model/Resolver/Categories/DataProvider/Category/CollectionProcessor/CatalogProcessor.php

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

88
namespace Magento\CatalogGraphQl\Model\Resolver\Categories\DataProvider\Category\CollectionProcessor;
99

10+
use Magento\Catalog\Api\CategoryRepositoryInterface;
1011
use Magento\Catalog\Model\ResourceModel\Category\Collection;
1112
use Magento\CatalogGraphQl\Model\Resolver\Categories\DataProvider\Category\CollectionProcessorInterface;
1213
use Magento\Framework\Api\SearchCriteriaInterface;
14+
use Magento\Framework\DB\Sql\Expression;
1315
use Magento\GraphQl\Model\Query\ContextInterface;
1416
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface as SearchCriteriaCollectionProcessor;
1517

@@ -20,16 +22,26 @@
2022
*/
2123
class CatalogProcessor implements CollectionProcessorInterface
2224
{
23-
/** @var SearchCriteriaCollectionProcessor */
25+
/**
26+
* @var SearchCriteriaCollectionProcessor
27+
*/
2428
private $collectionProcessor;
2529

30+
/**
31+
* @var CategoryRepositoryInterface
32+
*/
33+
private $categoryRepository;
34+
2635
/**
2736
* @param SearchCriteriaCollectionProcessor $collectionProcessor
37+
* @param CategoryRepositoryInterface $categoryRepository
2838
*/
2939
public function __construct(
30-
SearchCriteriaCollectionProcessor $collectionProcessor
40+
SearchCriteriaCollectionProcessor $collectionProcessor,
41+
CategoryRepositoryInterface $categoryRepository
3142
) {
3243
$this->collectionProcessor = $collectionProcessor;
44+
$this->categoryRepository = $categoryRepository;
3345
}
3446

3547
/**
@@ -50,26 +62,27 @@ public function process(
5062
): Collection {
5163
$this->collectionProcessor->process($searchCriteria, $collection);
5264
$store = $context->getExtensionAttributes()->getStore();
53-
$this->addRootCategoryFilterForStore($collection, (string) $store->getRootCategoryId());
54-
65+
$category = $this->categoryRepository->get($store->getRootCategoryId());
66+
$this->addRootCategoryFilterForStoreByPath($collection, $category->getPath());
5567
return $collection;
5668
}
5769

5870
/**
5971
* Add filtration based on the store root category id
6072
*
6173
* @param Collection $collection
62-
* @param string $rootCategoryId
74+
* @param string $storeRootCategoryPath
6375
*/
64-
private function addRootCategoryFilterForStore(Collection $collection, string $rootCategoryId) : void
76+
private function addRootCategoryFilterForStoreByPath(Collection $collection, string $storeRootCategoryPath) : void
6577
{
66-
$select = $collection->getSelect();
67-
$connection = $collection->getConnection();
68-
$select->where(
69-
$connection->quoteInto(
70-
'e.path LIKE ? OR e.entity_id=' . $connection->quote($rootCategoryId, 'int'),
71-
'%/' . $rootCategoryId . '/%'
72-
)
78+
$collection->addFieldToFilter(
79+
'path',
80+
[
81+
['eq' => $storeRootCategoryPath],
82+
['like' => new Expression(
83+
$collection->getConnection()->quoteInto('?', $storeRootCategoryPath . '/%')
84+
)]
85+
]
7386
);
7487
}
7588
}

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
9898

9999
$rootCategoryIds = $filterResult['category_ids'] ?? [];
100100

101-
$filterResult['items'] = $this->fetchCategories($rootCategoryIds, $info, $store, $context);
101+
$filterResult['items'] = $this->fetchCategories($rootCategoryIds, $info, $context);
102102
return $filterResult;
103103
}
104104

@@ -107,31 +107,22 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
107107
*
108108
* @param array $categoryIds
109109
* @param ResolveInfo $info
110-
* @param StoreInterface $store
111110
* @param ContextInterface $context
112111
* @return array
113112
*/
114113
private function fetchCategories(
115114
array $categoryIds,
116115
ResolveInfo $info,
117-
StoreInterface $store,
118116
ContextInterface $context
119117
) {
120-
$fetchedCategories = [];
121-
foreach ($categoryIds as $categoryId) {
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-
);
132-
$fetchedCategories[] = current($this->extractDataFromCategoryTree->execute($categoryTree));
133-
}
134-
135-
return $fetchedCategories;
118+
$searchCriteria = $this->searchCriteriaFactory->create();
119+
$categoryCollection = $this->categoryTree->getFlatCategoriesByRootIds(
120+
$info,
121+
$categoryIds,
122+
$searchCriteria,
123+
[],
124+
$context
125+
);
126+
return $this->extractDataFromCategoryTree->buildTree($categoryCollection, $categoryIds);
136127
}
137128
}

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

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

88
namespace Magento\CatalogGraphQl\Model\Resolver;
99

10+
use Magento\Catalog\Api\Data\CategoryInterface;
1011
use Magento\CatalogGraphQl\Model\Category\Filter\SearchCriteria;
1112
use Magento\Store\Api\Data\StoreInterface;
1213
use Magento\GraphQl\Model\Query\ContextInterface;
@@ -89,47 +90,45 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8990
$processedArgs = $this->argsSelection->process($info->fieldName, $args);
9091
$filterResults = $this->categoryFilter->getResult($processedArgs, $store, [], $context);
9192

92-
$rootCategoryIds = $filterResults['category_ids'];
93+
$topLevelCategoryIds = $filterResults['category_ids'];
9394
} catch (InputException $e) {
9495
throw new GraphQlInputException(__($e->getMessage()));
9596
}
96-
return $this->fetchCategories($rootCategoryIds, $info, $processedArgs, $store, [], $context);
97+
98+
return $this->fetchCategoriesByTopLevelIds($topLevelCategoryIds, $info, $processedArgs, [], $context);
9799
}
98100

99101
/**
100102
* Fetch category tree data
101103
*
102-
* @param array $categoryIds
104+
* @param array $topLevelCategoryIds
103105
* @param ResolveInfo $info
104-
* @param array $criteria
105-
* @param StoreInterface $store
106+
* @param array $processedArgs
106107
* @param array $attributeNames
107108
* @param ContextInterface $context
108109
* @return array
109110
* @throws LocalizedException
110111
*/
111-
private function fetchCategories(
112-
array $categoryIds,
112+
private function fetchCategoriesByTopLevelIds(
113+
array $topLevelCategoryIds,
113114
ResolveInfo $info,
114-
array $criteria,
115-
StoreInterface $store,
115+
array $processedArgs,
116116
array $attributeNames,
117117
ContextInterface $context
118118
) : array {
119-
$fetchedCategories = [];
120-
foreach ($categoryIds as $categoryId) {
121-
$searchCriteria = $this->searchCriteria->buildCriteria($criteria, $store);
122-
$categoryTree = $this->categoryTree->getFilteredTree(
123-
$info,
124-
$categoryId,
125-
$searchCriteria,
126-
$store,
127-
$attributeNames,
128-
$context
129-
);
130-
$fetchedCategories[] = current($this->extractDataFromCategoryTree->execute($categoryTree));
131-
}
132-
133-
return $fetchedCategories;
119+
// pagination must be applied to top level category results, children categories are not paginated
120+
$processedArgs['pageSize'] = 0;
121+
$searchCriteria = $this->searchCriteria->buildCriteria(
122+
$processedArgs,
123+
$context->getExtensionAttributes()->getStore()
124+
);
125+
$categoryCollection = $this->categoryTree->getFlatCategoriesByRootIds(
126+
$info,
127+
$topLevelCategoryIds,
128+
$searchCriteria,
129+
$attributeNames,
130+
$context
131+
);
132+
return $this->extractDataFromCategoryTree->buildTree($categoryCollection, $topLevelCategoryIds);
134133
}
135134
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CategoryTree implements ResolverInterface
2424
/**
2525
* Name of type in GraphQL
2626
*/
27-
const CATEGORY_INTERFACE = 'CategoryInterface';
27+
public const CATEGORY_INTERFACE = 'CategoryInterface';
2828

2929
/**
3030
* @var CategoryTreeDataProvider
@@ -72,13 +72,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7272
$this->checkCategoryIsActive->execute($rootCategoryId);
7373
}
7474
$store = $context->getExtensionAttributes()->getStore();
75-
$categoriesTree = $this->categoryTree->getTree($info, $rootCategoryId, (int)$store->getId());
75+
$categoriesTree = $this->categoryTree->getTreeCollection($info, $rootCategoryId, (int)$store->getId());
7676

77-
if (empty($categoriesTree) || ($categoriesTree->count() == 0)) {
77+
if ($categoriesTree->count() == 0) {
7878
throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist'));
7979
}
8080

81-
$result = $this->extractDataFromCategoryTree->execute($categoriesTree);
81+
$result = $this->extractDataFromCategoryTree->buildTree($categoriesTree, [$rootCategoryId]);
8282
return current($result);
8383
}
8484
}

0 commit comments

Comments
 (0)