|
| 1 | +From c964bc3248811dc63df6205a1246d383ad4c6e4a Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jacob Brown < [email protected]> |
| 3 | +Date: Wed, 3 Apr 2024 14:07:21 -0500 |
| 4 | +Subject: [PATCH] ACPT-1854: AttributeReader should use Factory for Collection |
| 5 | + |
| 6 | +--- |
| 7 | + .../Model/Config/AttributeReader.php | 18 +++++++++++------- |
| 8 | + 1 file changed, 11 insertions(+), 7 deletions(-) |
| 9 | + |
| 10 | +diff --git a/vendor/magento/module-catalog-graph-ql/Model/Config/AttributeReader.php b/vendor/magento/module-catalog-graph-ql/Model/Config/AttributeReader.php |
| 11 | +index ecd83bf61ef0..05acb97e4bd7 100644 |
| 12 | +--- a/vendor/magento/module-catalog-graph-ql/Model/Config/AttributeReader.php |
| 13 | ++++ b/vendor/magento/module-catalog-graph-ql/Model/Config/AttributeReader.php |
| 14 | +@@ -9,8 +9,10 @@ |
| 15 | + use Magento\Catalog\Model\Product; |
| 16 | + use Magento\Catalog\Model\ResourceModel\Eav\Attribute; |
| 17 | + use Magento\CatalogGraphQl\Model\Resolver\Products\Attributes\Collection; |
| 18 | ++use Magento\CatalogGraphQl\Model\Resolver\Products\Attributes\CollectionFactory; |
| 19 | + use Magento\EavGraphQl\Model\Resolver\Query\Type; |
| 20 | + use Magento\Framework\App\Config\ScopeConfigInterface; |
| 21 | ++use Magento\Framework\App\ObjectManager; |
| 22 | + use Magento\Framework\Config\ReaderInterface; |
| 23 | + use Magento\Framework\GraphQl\Exception\GraphQlInputException; |
| 24 | + use Magento\Framework\GraphQl\Schema\Type\Entity\MapperInterface; |
| 25 | +@@ -36,9 +38,9 @@ class AttributeReader implements ReaderInterface |
| 26 | + private Type $typeLocator; |
| 27 | + |
| 28 | + /** |
| 29 | +- * @var Collection |
| 30 | ++ * @var CollectionFactory |
| 31 | + */ |
| 32 | +- private Collection $collection; |
| 33 | ++ private CollectionFactory $collectionFactory; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var ScopeConfigInterface |
| 37 | +@@ -48,18 +50,21 @@ class AttributeReader implements ReaderInterface |
| 38 | + /** |
| 39 | + * @param MapperInterface $mapper |
| 40 | + * @param Type $typeLocator |
| 41 | +- * @param Collection $collection |
| 42 | ++ * @param Collection $collection @deprecated @see $collectionFactory |
| 43 | + * @param ScopeConfigInterface $config |
| 44 | ++ * @param CollectionFactory|null $collectionFactory |
| 45 | ++ * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 46 | + */ |
| 47 | + public function __construct( |
| 48 | + MapperInterface $mapper, |
| 49 | + Type $typeLocator, |
| 50 | + Collection $collection, |
| 51 | +- ScopeConfigInterface $config |
| 52 | ++ ScopeConfigInterface $config, |
| 53 | ++ CollectionFactory $collectionFactory = null, |
| 54 | + ) { |
| 55 | + $this->mapper = $mapper; |
| 56 | + $this->typeLocator = $typeLocator; |
| 57 | +- $this->collection = $collection; |
| 58 | ++ $this->collectionFactory = $collectionFactory ?? ObjectManager::getInstance()->get(CollectionFactory::class); |
| 59 | + $this->config = $config; |
| 60 | + } |
| 61 | + |
| 62 | +@@ -74,12 +79,11 @@ public function __construct( |
| 63 | + public function read($scope = null) : array |
| 64 | + { |
| 65 | + $config = []; |
| 66 | +- |
| 67 | + if ($this->config->isSetFlag(self::XML_PATH_INCLUDE_DYNAMIC_ATTRIBUTES, ScopeInterface::SCOPE_STORE)) { |
| 68 | + $typeNames = $this->mapper->getMappedTypes(Product::ENTITY); |
| 69 | + |
| 70 | + /** @var Attribute $attribute */ |
| 71 | +- foreach ($this->collection->getAttributes() as $attribute) { |
| 72 | ++ foreach ($this->collectionFactory->create()->getAttributes() as $attribute) { |
| 73 | + $attributeCode = $attribute->getAttributeCode(); |
| 74 | + $locatedType = $this->typeLocator->getType($attributeCode, Product::ENTITY) ?: 'String'; |
| 75 | + $locatedType = TypeProcessor::NORMALIZED_ANY_TYPE === $locatedType ? 'String' : ucfirst($locatedType); |
0 commit comments