Skip to content

Commit b4f9b1f

Browse files
ACPT-1327
SortAttributeReader should use CollectionFactory instead of Collection This was causing config reload to fail.
1 parent 446475f commit b4f9b1f

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

app/code/Magento/CatalogGraphQl/Model/Config/SortAttributeReader.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
namespace Magento\CatalogGraphQl\Model\Config;
88

9+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection as AttributesCollection;
10+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory as AttributesCollectionFactory;
11+
use Magento\Framework\App\ObjectManager;
912
use Magento\Framework\Config\ReaderInterface;
1013
use Magento\Framework\GraphQl\Schema\Type\Entity\MapperInterface;
11-
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection as AttributesCollection;
1214

1315
/**
1416
* Adds custom/eav attribute to catalog products sorting in the GraphQL config.
@@ -31,20 +33,23 @@ class SortAttributeReader implements ReaderInterface
3133
private $mapper;
3234

3335
/**
34-
* @var AttributesCollection
36+
* @var AttributesCollectionFactory
3537
*/
36-
private $attributesCollection;
38+
private $attributesCollectionFactory;
3739

3840
/**
3941
* @param MapperInterface $mapper
4042
* @param AttributesCollection $attributesCollection
43+
* @param AttributesCollectionFactory|null $attributesCollectionFactory
4144
*/
4245
public function __construct(
4346
MapperInterface $mapper,
44-
AttributesCollection $attributesCollection
47+
AttributesCollection $attributesCollection,
48+
?AttributesCollectionFactory $attributesCollectionFactory = null
4549
) {
4650
$this->mapper = $mapper;
47-
$this->attributesCollection = $attributesCollection;
51+
$this->attributesCollectionFactory = $attributesCollectionFactory
52+
?? ObjectManager::getInstance()->get(AttributesCollectionFactory::class);
4853
}
4954

5055
/**
@@ -58,7 +63,8 @@ public function read($scope = null) : array
5863
{
5964
$map = $this->mapper->getMappedTypes(self::ENTITY_TYPE);
6065
$config =[];
61-
$attributes = $this->attributesCollection->addSearchableAttributeFilter()->addFilter('used_for_sort_by', 1);
66+
$attributes = $this->attributesCollectionFactory->create()
67+
->addSearchableAttributeFilter()->addFilter('used_for_sort_by', 1);
6268
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
6369
foreach ($attributes as $attribute) {
6470
$attributeCode = $attribute->getAttributeCode();
@@ -73,7 +79,6 @@ public function read($scope = null) : array
7379
];
7480
}
7581
}
76-
7782
return $config;
7883
}
7984
}

0 commit comments

Comments
 (0)