From 64263d88e57490b197706550a5e8797a34010cc8 Mon Sep 17 00:00:00 2001 From: Roman Hanin Date: Fri, 4 Nov 2022 16:52:21 -0500 Subject: [PATCH 01/14] B2B-2463: Improve custom attributes metadata fetching for category models in graphql --- .../Model/Category/AttributeRepository.php | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Category/AttributeRepository.php b/app/code/Magento/Catalog/Model/Category/AttributeRepository.php index 3243bf718e66..8a2a3de4ccd1 100644 --- a/app/code/Magento/Catalog/Model/Category/AttributeRepository.php +++ b/app/code/Magento/Catalog/Model/Category/AttributeRepository.php @@ -29,6 +29,11 @@ class AttributeRepository implements CategoryAttributeRepositoryInterface */ private $eavConfig; + /** + * @var array + */ + private $metadataCache; + /** * @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder * @param \Magento\Framework\Api\FilterBuilder $filterBuilder @@ -75,18 +80,21 @@ public function get($attributeCode) */ public function getCustomAttributesMetadata($dataObjectClassName = null) { - $defaultAttributeSetId = $this->eavConfig - ->getEntityType(\Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE) - ->getDefaultAttributeSetId(); - $searchCriteria = $this->searchCriteriaBuilder->addFilters( - [ - $this->filterBuilder - ->setField('attribute_set_id') - ->setValue($defaultAttributeSetId) - ->create(), - ] - ); - - return $this->getList($searchCriteria->create())->getItems(); + if (empty($this->metadataCache[$dataObjectClassName])) { + $defaultAttributeSetId = $this->eavConfig + ->getEntityType(\Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE) + ->getDefaultAttributeSetId(); + $searchCriteria = $this->searchCriteriaBuilder->addFilters( + [ + $this->filterBuilder + ->setField('attribute_set_id') + ->setValue($defaultAttributeSetId) + ->create(), + ] + ); + $this->metadataCache[$dataObjectClassName] = $this->getList($searchCriteria->create()) + ->getItems(); + } + return $this->metadataCache[$dataObjectClassName]; } } From 0146e858de49d3685e1b728e2fd1206025447e44 Mon Sep 17 00:00:00 2001 From: Roman Hanin Date: Fri, 4 Nov 2022 18:04:16 -0500 Subject: [PATCH 02/14] B2B-2463: Improve custom attributes metadata fetching for category models in graphql --- app/code/Magento/Catalog/Model/Category/AttributeRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/Category/AttributeRepository.php b/app/code/Magento/Catalog/Model/Category/AttributeRepository.php index 8a2a3de4ccd1..d630502bc3f3 100644 --- a/app/code/Magento/Catalog/Model/Category/AttributeRepository.php +++ b/app/code/Magento/Catalog/Model/Category/AttributeRepository.php @@ -80,7 +80,7 @@ public function get($attributeCode) */ public function getCustomAttributesMetadata($dataObjectClassName = null) { - if (empty($this->metadataCache[$dataObjectClassName])) { + if (!isset($this->metadataCache[$dataObjectClassName])) { $defaultAttributeSetId = $this->eavConfig ->getEntityType(\Magento\Catalog\Api\Data\CategoryAttributeInterface::ENTITY_TYPE_CODE) ->getDefaultAttributeSetId(); From 17ffdc71d460bbb2b559f0c4bab5f3ce559146e3 Mon Sep 17 00:00:00 2001 From: Roman Hanin Date: Fri, 4 Nov 2022 20:32:17 -0500 Subject: [PATCH 03/14] B2B-2463: Improve custom attributes metadata fetching for category models in graphql - static test fixes --- .../Magento/Catalog/Model/Category/AttributeRepository.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Category/AttributeRepository.php b/app/code/Magento/Catalog/Model/Category/AttributeRepository.php index d630502bc3f3..29e8ec51254f 100644 --- a/app/code/Magento/Catalog/Model/Category/AttributeRepository.php +++ b/app/code/Magento/Catalog/Model/Category/AttributeRepository.php @@ -53,7 +53,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) { @@ -64,7 +64,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr } /** - * {@inheritdoc} + * @inheritdoc */ public function get($attributeCode) { @@ -75,7 +75,8 @@ public function get($attributeCode) } /** - * {@inheritdoc} + * @inheritdoc + * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function getCustomAttributesMetadata($dataObjectClassName = null) From d21b909013b9eceed3a859fdc7c71d612acdcd50 Mon Sep 17 00:00:00 2001 From: Roman Hanin Date: Mon, 7 Nov 2022 09:14:18 -0600 Subject: [PATCH 04/14] B2B-2463: Improve custom attributes metadata fetching for category models in graphql - static test fixes --- app/code/Magento/Catalog/Model/Category/AttributeRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Model/Category/AttributeRepository.php b/app/code/Magento/Catalog/Model/Category/AttributeRepository.php index 29e8ec51254f..65443e223e85 100644 --- a/app/code/Magento/Catalog/Model/Category/AttributeRepository.php +++ b/app/code/Magento/Catalog/Model/Category/AttributeRepository.php @@ -76,7 +76,7 @@ public function get($attributeCode) /** * @inheritdoc - * + * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function getCustomAttributesMetadata($dataObjectClassName = null) From 07e37e35cbf8fb19aaef5eb6f41273f7fe133ac5 Mon Sep 17 00:00:00 2001 From: Dan Mooney Date: Wed, 9 Nov 2022 11:48:16 -0600 Subject: [PATCH 05/14] B2B-2464: Improve category children loading - Flattener only is concerned with custom_attributes - This fix is to prevent getChildren from being needlessly called via buildOutputDataArray (note that children is reset to empty array after that call) --- .../Magento/CatalogGraphQl/Model/Category/Hydrator.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Category/Hydrator.php b/app/code/Magento/CatalogGraphQl/Model/Category/Hydrator.php index 675118b95310..ebfd5a53ab6e 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Category/Hydrator.php +++ b/app/code/Magento/CatalogGraphQl/Model/Category/Hydrator.php @@ -57,11 +57,13 @@ public function __construct( */ public function hydrateCategory(Category $category, $basicFieldsOnly = false) : array { - if ($basicFieldsOnly) { - $categoryData = $category->getData(); - } else { - $categoryData = $this->dataObjectProcessor->buildOutputDataArray($category, CategoryInterface::class); + if (!$basicFieldsOnly) { + // initialize custom attributes (to be consequently included in subsequent getData call below) + $category->getCustomAttributes(); } + + $categoryData = $category->getData(); + $categoryData['id'] = $category->getId(); $categoryData['uid'] = $this->uidEncoder->encode((string) $category->getId()); $categoryData['children'] = []; From 6caac7496515e5054a76ed66dbecbfcd92e37752 Mon Sep 17 00:00:00 2001 From: Dan Mooney Date: Wed, 9 Nov 2022 15:46:49 -0600 Subject: [PATCH 06/14] B2B-2464: Improve category children loading - Only fetch necessary category entity id; all other fields are unused and discarded --- .../CatalogGraphQl/Model/Category/CategoryFilter.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php b/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php index 4350b6dd8526..fdae99bcbf19 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php +++ b/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php @@ -14,6 +14,7 @@ use Magento\CatalogGraphQl\Model\Resolver\Categories\DataProvider\Category\CollectionProcessorInterface; use Magento\CatalogGraphQl\Model\Category\Filter\SearchCriteria; use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface; +use Magento\Framework\DB\Select; use Magento\Framework\Exception\InputException; use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\GraphQl\Model\Query\ContextInterface; @@ -98,6 +99,14 @@ public function getResult(array $criteria, StoreInterface $store, array $attribu /** @var CategorySearchResultsInterface $searchResult */ $categories = $this->categorySearchResultsFactory->create(); $categories->setSearchCriteria($searchCriteria); + + // only fetch necessary category entity id + $collection + ->getSelect() + ->reset(Select::COLUMNS) + ->columns( + 'e.entity_id' + ); $categories->setItems($collection->getItems()); $categories->setTotalCount($collection->getSize()); From 053b7f38f405e8f08a9a51bb5e864f6de7e5d31b Mon Sep 17 00:00:00 2001 From: Dan Mooney Date: Thu, 10 Nov 2022 13:00:05 -0600 Subject: [PATCH 07/14] B2B-2464: Improve category children loading - Add exclude list for buildOutputDataArray --- .../CatalogGraphQl/Model/Category/Hydrator.php | 16 +++++++++++----- .../Framework/Reflection/DataObjectProcessor.php | 7 ++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Category/Hydrator.php b/app/code/Magento/CatalogGraphQl/Model/Category/Hydrator.php index ebfd5a53ab6e..6f2bdca514b9 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Category/Hydrator.php +++ b/app/code/Magento/CatalogGraphQl/Model/Category/Hydrator.php @@ -57,13 +57,19 @@ public function __construct( */ public function hydrateCategory(Category $category, $basicFieldsOnly = false) : array { - if (!$basicFieldsOnly) { - // initialize custom attributes (to be consequently included in subsequent getData call below) - $category->getCustomAttributes(); + if ($basicFieldsOnly) { + $categoryData = $category->getData(); + } else { + $categoryData = $this->dataObjectProcessor->buildOutputDataArray( + $category, + CategoryInterface::class, + [ + 'getChildren', + 'getExtensionAttributes', + ] + ); } - $categoryData = $category->getData(); - $categoryData['id'] = $category->getId(); $categoryData['uid'] = $this->uidEncoder->encode((string) $category->getId()); $categoryData['children'] = []; diff --git a/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php b/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php index 967826be09ce..f427c610c12c 100644 --- a/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php +++ b/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php @@ -75,16 +75,21 @@ public function __construct( * * @param mixed $dataObject * @param string $dataObjectType + * @param array $excludedMethods - list of methods to exclude from being called * @return array * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function buildOutputDataArray($dataObject, $dataObjectType) + public function buildOutputDataArray($dataObject, $dataObjectType, array $excludedMethods = []) { $methods = $this->methodsMapProcessor->getMethodsMap($dataObjectType); $outputData = []; foreach (array_keys($methods) as $methodName) { + if (in_array($methodName, $excludedMethods)) { + continue; + } + if (!$this->methodsMapProcessor->isMethodValidForDataField($dataObjectType, $methodName)) { continue; } From 87308cd39c6a6267fb825e6d01aeb36cd69497f4 Mon Sep 17 00:00:00 2001 From: Dan Mooney Date: Fri, 11 Nov 2022 12:46:57 -0600 Subject: [PATCH 08/14] B2B-2464: Improve category children loading - Revert optional parameter addition to avoid minor version change --- .../CatalogGraphQl/Model/Category/Hydrator.php | 6 +----- .../Reflection/DataObjectProcessor.php | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Category/Hydrator.php b/app/code/Magento/CatalogGraphQl/Model/Category/Hydrator.php index 6f2bdca514b9..fc234c1de4e4 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Category/Hydrator.php +++ b/app/code/Magento/CatalogGraphQl/Model/Category/Hydrator.php @@ -62,11 +62,7 @@ public function hydrateCategory(Category $category, $basicFieldsOnly = false) : } else { $categoryData = $this->dataObjectProcessor->buildOutputDataArray( $category, - CategoryInterface::class, - [ - 'getChildren', - 'getExtensionAttributes', - ] + CategoryInterface::class ); } diff --git a/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php b/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php index f427c610c12c..94023d129d1d 100644 --- a/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php +++ b/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php @@ -46,6 +46,11 @@ class DataObjectProcessor */ private $processors; + /** + * @var array[] + */ + private $excludedMethodsClassMap; + /** * @param MethodsMap $methodsMapProcessor * @param TypeCaster $typeCaster @@ -53,6 +58,7 @@ class DataObjectProcessor * @param CustomAttributesProcessor $customAttributesProcessor * @param ExtensionAttributesProcessor $extensionAttributesProcessor * @param array $processors + * @param array $excludedMethodsClassMap */ public function __construct( MethodsMap $methodsMapProcessor, @@ -60,7 +66,8 @@ public function __construct( FieldNamer $fieldNamer, CustomAttributesProcessor $customAttributesProcessor, ExtensionAttributesProcessor $extensionAttributesProcessor, - array $processors = [] + array $processors = [], + array $excludedMethodsClassMap = [] ) { $this->methodsMapProcessor = $methodsMapProcessor; $this->typeCaster = $typeCaster; @@ -68,6 +75,7 @@ public function __construct( $this->extensionAttributesProcessor = $extensionAttributesProcessor; $this->customAttributesProcessor = $customAttributesProcessor; $this->processors = $processors; + $this->excludedMethodsClassMap = $excludedMethodsClassMap; } /** @@ -75,18 +83,19 @@ public function __construct( * * @param mixed $dataObject * @param string $dataObjectType - * @param array $excludedMethods - list of methods to exclude from being called * @return array * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function buildOutputDataArray($dataObject, $dataObjectType, array $excludedMethods = []) + public function buildOutputDataArray($dataObject, $dataObjectType) { $methods = $this->methodsMapProcessor->getMethodsMap($dataObjectType); $outputData = []; + $excludedMethodsForDataObjectType = $this->excludedMethodsClassMap[$dataObjectType] ?? []; + foreach (array_keys($methods) as $methodName) { - if (in_array($methodName, $excludedMethods)) { + if (in_array($methodName, $excludedMethodsForDataObjectType)) { continue; } From d85ce24642ecd54400de3aa2ab78cb5206db989d Mon Sep 17 00:00:00 2001 From: Dan Mooney Date: Fri, 11 Nov 2022 13:52:26 -0600 Subject: [PATCH 09/14] B2B-2464: Improve category children loading - Add virtual type for exclusionary processing of category lists --- .../Magento/CatalogGraphQl/etc/graphql/di.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/code/Magento/CatalogGraphQl/etc/graphql/di.xml b/app/code/Magento/CatalogGraphQl/etc/graphql/di.xml index 369f4bfb2303..e03e8d1b0784 100644 --- a/app/code/Magento/CatalogGraphQl/etc/graphql/di.xml +++ b/app/code/Magento/CatalogGraphQl/etc/graphql/di.xml @@ -191,6 +191,13 @@ + + + + Magento\CatalogGraphQl\Category\DataObjectProcessor + + + @@ -207,4 +214,16 @@ + + + + + getChildren + + + + From 22e68394306504836b424cb2b75e04bb95e668f6 Mon Sep 17 00:00:00 2001 From: Dan Mooney Date: Fri, 11 Nov 2022 14:21:34 -0600 Subject: [PATCH 10/14] B2B-2464: Improve category children loading - Use fetchCol to avoid creation of collection models --- .../Model/Category/CategoryFilter.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php b/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php index fdae99bcbf19..f876eea5400e 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php +++ b/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php @@ -101,19 +101,16 @@ public function getResult(array $criteria, StoreInterface $store, array $attribu $categories->setSearchCriteria($searchCriteria); // only fetch necessary category entity id - $collection - ->getSelect() + $select = $collection->getSelect(); + $select ->reset(Select::COLUMNS) ->columns( 'e.entity_id' ); - $categories->setItems($collection->getItems()); - $categories->setTotalCount($collection->getSize()); + $categoryIds = array_map('intval', $collection->getConnection()->fetchCol($select)); - $categoryIds = []; - foreach ($categories->getItems() as $category) { - $categoryIds[] = (int)$category->getId(); - } + $categories->setItems($categoryIds); + $categories->setTotalCount(count($categoryIds)); $totalPages = 0; if ($categories->getTotalCount() > 0 && $searchCriteria->getPageSize() > 0) { From c61610155c6e1c41af43baca3a557a6930c4ff7e Mon Sep 17 00:00:00 2001 From: Dan Mooney Date: Fri, 11 Nov 2022 15:47:19 -0600 Subject: [PATCH 11/14] B2B-2464: Improve category children loading - Format --- app/code/Magento/CatalogGraphQl/etc/graphql/di.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/etc/graphql/di.xml b/app/code/Magento/CatalogGraphQl/etc/graphql/di.xml index e03e8d1b0784..0e0fa9d95580 100644 --- a/app/code/Magento/CatalogGraphQl/etc/graphql/di.xml +++ b/app/code/Magento/CatalogGraphQl/etc/graphql/di.xml @@ -193,9 +193,7 @@ - - Magento\CatalogGraphQl\Category\DataObjectProcessor - + Magento\CatalogGraphQl\Category\DataObjectProcessor Date: Fri, 11 Nov 2022 16:33:35 -0600 Subject: [PATCH 12/14] B2B-2464: Improve category children loading --- .../Model/Category/CategoryFilter.php | 39 ++++--------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php b/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php index f876eea5400e..3c0f209c4b4e 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php +++ b/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php @@ -7,9 +7,6 @@ namespace Magento\CatalogGraphQl\Model\Category; -use Magento\Catalog\Api\CategoryRepositoryInterface; -use Magento\Catalog\Api\Data\CategorySearchResultsInterface; -use Magento\Catalog\Api\Data\CategorySearchResultsInterfaceFactory; use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory; use Magento\CatalogGraphQl\Model\Resolver\Categories\DataProvider\Category\CollectionProcessorInterface; use Magento\CatalogGraphQl\Model\Category\Filter\SearchCriteria; @@ -40,16 +37,6 @@ class CategoryFilter */ private $extensionAttributesJoinProcessor; - /** - * @var CategorySearchResultsInterfaceFactory - */ - private $categorySearchResultsFactory; - - /** - * @var CategoryRepositoryInterface - */ - private $categoryRepository; - /** * @var SearchCriteria */ @@ -59,23 +46,17 @@ class CategoryFilter * @param CollectionFactory $categoryCollectionFactory * @param CollectionProcessorInterface $collectionProcessor * @param JoinProcessorInterface $extensionAttributesJoinProcessor - * @param CategorySearchResultsInterfaceFactory $categorySearchResultsFactory - * @param CategoryRepositoryInterface $categoryRepository * @param SearchCriteria $searchCriteria */ public function __construct( CollectionFactory $categoryCollectionFactory, CollectionProcessorInterface $collectionProcessor, JoinProcessorInterface $extensionAttributesJoinProcessor, - CategorySearchResultsInterfaceFactory $categorySearchResultsFactory, - CategoryRepositoryInterface $categoryRepository, SearchCriteria $searchCriteria ) { $this->categoryCollectionFactory = $categoryCollectionFactory; $this->collectionProcessor = $collectionProcessor; $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor; - $this->categorySearchResultsFactory = $categorySearchResultsFactory; - $this->categoryRepository = $categoryRepository; $this->searchCriteria = $searchCriteria; } @@ -96,27 +77,21 @@ public function getResult(array $criteria, StoreInterface $store, array $attribu $this->extensionAttributesJoinProcessor->process($collection); $this->collectionProcessor->process($collection, $searchCriteria, $attributeNames, $context); - /** @var CategorySearchResultsInterface $searchResult */ - $categories = $this->categorySearchResultsFactory->create(); - $categories->setSearchCriteria($searchCriteria); - // only fetch necessary category entity id - $select = $collection->getSelect(); - $select + $collection + ->getSelect() ->reset(Select::COLUMNS) ->columns( 'e.entity_id' ); - $categoryIds = array_map('intval', $collection->getConnection()->fetchCol($select)); - $categories->setItems($categoryIds); - $categories->setTotalCount(count($categoryIds)); + $categoryIds = $collection->getLoadedIds(); $totalPages = 0; - if ($categories->getTotalCount() > 0 && $searchCriteria->getPageSize() > 0) { - $totalPages = ceil($categories->getTotalCount() / $searchCriteria->getPageSize()); + if ($collection->getSize() > 0 && $searchCriteria->getPageSize() > 0) { + $totalPages = ceil($collection->getSize() / $searchCriteria->getPageSize()); } - if ($searchCriteria->getCurrentPage() > $totalPages && $categories->getTotalCount() > 0) { + if ($searchCriteria->getCurrentPage() > $totalPages && $collection->getSize() > 0) { throw new GraphQlInputException( __( 'currentPage value %1 specified is greater than the %2 page(s) available.', @@ -127,7 +102,7 @@ public function getResult(array $criteria, StoreInterface $store, array $attribu return [ 'category_ids' => $categoryIds, - 'total_count' => $categories->getTotalCount(), + 'total_count' => $collection->getSize(), 'page_info' => [ 'total_pages' => $totalPages, 'page_size' => $searchCriteria->getPageSize(), From a12627e4715673d4a329fd7a3273e70038fe8bd7 Mon Sep 17 00:00:00 2001 From: Roman Hanin Date: Fri, 11 Nov 2022 16:38:27 -0600 Subject: [PATCH 13/14] B2B-2464: Improve category children loading --- .../Magento/CatalogGraphQl/Model/Category/CategoryFilter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php b/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php index 3c0f209c4b4e..d8b90b454b4a 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php +++ b/app/code/Magento/CatalogGraphQl/Model/Category/CategoryFilter.php @@ -85,7 +85,7 @@ public function getResult(array $criteria, StoreInterface $store, array $attribu 'e.entity_id' ); - $categoryIds = $collection->getLoadedIds(); + $categoryIds = $collection->load()->getLoadedIds(); $totalPages = 0; if ($collection->getSize() > 0 && $searchCriteria->getPageSize() > 0) { From 10d1009c4b372b594dc35c500b048be65b679e3d Mon Sep 17 00:00:00 2001 From: Dan Mooney Date: Tue, 15 Nov 2022 14:05:06 -0600 Subject: [PATCH 14/14] B2B-2464: Improve category children loading - Add test coverage for new $excludedMethodsClassMap dependency --- .../Test/Unit/DataObjectProcessorTest.php | 92 +++++++++++++------ 1 file changed, 66 insertions(+), 26 deletions(-) diff --git a/lib/internal/Magento/Framework/Reflection/Test/Unit/DataObjectProcessorTest.php b/lib/internal/Magento/Framework/Reflection/Test/Unit/DataObjectProcessorTest.php index 8e55d4395d20..620b3684b4ab 100644 --- a/lib/internal/Magento/Framework/Reflection/Test/Unit/DataObjectProcessorTest.php +++ b/lib/internal/Magento/Framework/Reflection/Test/Unit/DataObjectProcessorTest.php @@ -26,6 +26,11 @@ class DataObjectProcessorTest extends TestCase */ private $dataObjectProcessor; + /** + * @var MethodsMap + */ + private $methodsMapProcessor; + /** * @var ExtensionAttributesProcessor|MockObject */ @@ -34,7 +39,7 @@ class DataObjectProcessorTest extends TestCase protected function setUp(): void { $objectManager = new ObjectManager($this); - $methodsMapProcessor = $objectManager->getObject( + $this->methodsMapProcessor = $objectManager->getObject( MethodsMap::class, [ 'fieldNamer' => $objectManager->getObject(FieldNamer::class), @@ -48,7 +53,7 @@ protected function setUp(): void ->willReturn(['unserializedData']); $objectManager->setBackwardCompatibleProperty( - $methodsMapProcessor, + $this->methodsMapProcessor, 'serializer', $serializerMock ); @@ -56,27 +61,32 @@ protected function setUp(): void $this->extensionAttributesProcessorMock = $this->getMockBuilder(ExtensionAttributesProcessor::class) ->disableOriginalConstructor() ->getMock(); + } + + /** + * @param array $extensionAttributes + * @param array $excludedMethodsClassMap + * @param array $expectedOutput + * @dataProvider buildOutputDataArrayDataProvider + */ + public function testBuildOutputDataArray( + array $extensionAttributes, + array $excludedMethodsClassMap, + array $expectedOutput + ) { + $objectManager = new ObjectManager($this); $this->dataObjectProcessor = $objectManager->getObject( DataObjectProcessor::class, [ - 'methodsMapProcessor' => $methodsMapProcessor, + 'methodsMapProcessor' => $this->methodsMapProcessor, 'typeCaster' => $objectManager->getObject(TypeCaster::class), 'fieldNamer' => $objectManager->getObject(FieldNamer::class), - 'extensionAttributesProcessor' => $this->extensionAttributesProcessorMock + 'extensionAttributesProcessor' => $this->extensionAttributesProcessorMock, + 'excludedMethodsClassMap' => $excludedMethodsClassMap, ] ); - } - /** - * @param array $extensionAttributes - * @param array $expectedOutputDataArray - * - * @dataProvider buildOutputDataArrayDataProvider - */ - public function testBuildOutputDataArray($extensionAttributes, $expectedOutputDataArray) - { - $objectManager = new ObjectManager($this); /** @var TestDataObject $testDataObject */ $testDataObject = $objectManager->getObject( TestDataObject::class, @@ -87,13 +97,19 @@ public function testBuildOutputDataArray($extensionAttributes, $expectedOutputDa ] ); - $this->extensionAttributesProcessorMock->expects($this->once()) + if (in_array('getExtensionAttributes', $excludedMethodsClassMap[TestDataInterface::class] ?? [])) { + $expectedTimes = $this->never(); + } else { + $expectedTimes = $this->once(); + } + + $this->extensionAttributesProcessorMock->expects($expectedTimes) ->method('buildOutputDataArray') ->willReturn($extensionAttributes); $outputData = $this->dataObjectProcessor ->buildOutputDataArray($testDataObject, TestDataInterface::class); - $this->assertEquals($expectedOutputDataArray, $outputData); + $this->assertEquals($expectedOutput, $outputData); } /** @@ -101,26 +117,50 @@ public function testBuildOutputDataArray($extensionAttributes, $expectedOutputDa */ public function buildOutputDataArrayDataProvider() { - $expectedOutputDataArray = [ + $expectedOutput = [ 'id' => '1', 'address' => 'someAddress', 'default_shipping' => 'true', 'required_billing' => 'false', ]; - $extensionAttributeArray = [ + + $extensionAttributes = [ 'attribute1' => 'value1', - 'attribute2' => 'value2' + 'attribute2' => 'value2', ]; return [ - 'No Attributes' => [[], $expectedOutputDataArray], - 'With Attributes' => [ - $extensionAttributeArray, + 'No Extension Attributes or Excluded Methods' => [ + [], + [], + $expectedOutput, + ], + 'With Extension Attributes' => [ + $extensionAttributes, + [], array_merge( - $expectedOutputDataArray, - ['extension_attributes' => $extensionAttributeArray] - ) - ] + $expectedOutput, + ['extension_attributes' => $extensionAttributes] + ), + ], + 'With Excluded Method' => [ + [], + [ + TestDataInterface::class => [ + 'getAddress', + ], + ], + array_diff_key($expectedOutput, array_flip(['address'])), + ], + 'With getExtensionAttributes as Excluded Method' => [ + $extensionAttributes, + [ + TestDataInterface::class => [ + 'getExtensionAttributes', + ], + ], + $expectedOutput, + ], ]; } }