9
9
use Magento \Catalog \Model \Product ;
10
10
use Magento \Catalog \Model \ResourceModel \Eav \Attribute ;
11
11
use Magento \CatalogGraphQl \Model \Resolver \Products \Attributes \Collection ;
12
+ use Magento \CatalogGraphQl \Model \Resolver \Products \Attributes \CollectionFactory ;
12
13
use Magento \EavGraphQl \Model \Resolver \Query \Type ;
13
14
use Magento \Framework \App \Config \ScopeConfigInterface ;
15
+ use Magento \Framework \App \ObjectManager ;
14
16
use Magento \Framework \Config \ReaderInterface ;
15
17
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
16
18
use Magento \Framework \GraphQl \Schema \Type \Entity \MapperInterface ;
@@ -36,9 +38,9 @@ class AttributeReader implements ReaderInterface
36
38
private Type $ typeLocator ;
37
39
38
40
/**
39
- * @var Collection
41
+ * @var CollectionFactory
40
42
*/
41
- private Collection $ collection ;
43
+ private readonly CollectionFactory $ collectionFactory ;
42
44
43
45
/**
44
46
* @var ScopeConfigInterface
@@ -48,18 +50,21 @@ class AttributeReader implements ReaderInterface
48
50
/**
49
51
* @param MapperInterface $mapper
50
52
* @param Type $typeLocator
51
- * @param Collection $collection
53
+ * @param Collection $collection @deprecated @see $collectionFactory
52
54
* @param ScopeConfigInterface $config
55
+ * @param CollectionFactory|null $collectionFactory
56
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
53
57
*/
54
58
public function __construct (
55
59
MapperInterface $ mapper ,
56
60
Type $ typeLocator ,
57
61
Collection $ collection ,
58
- ScopeConfigInterface $ config
62
+ ScopeConfigInterface $ config ,
63
+ CollectionFactory $ collectionFactory = null ,
59
64
) {
60
65
$ this ->mapper = $ mapper ;
61
66
$ this ->typeLocator = $ typeLocator ;
62
- $ this ->collection = $ collection ;
67
+ $ this ->collectionFactory = $ collectionFactory ?? ObjectManager:: getInstance ()-> get (CollectionFactory::class) ;
63
68
$ this ->config = $ config ;
64
69
}
65
70
@@ -74,12 +79,11 @@ public function __construct(
74
79
public function read ($ scope = null ) : array
75
80
{
76
81
$ config = [];
77
-
78
82
if ($ this ->config ->isSetFlag (self ::XML_PATH_INCLUDE_DYNAMIC_ATTRIBUTES , ScopeInterface::SCOPE_STORE )) {
79
83
$ typeNames = $ this ->mapper ->getMappedTypes (Product::ENTITY );
80
84
81
85
/** @var Attribute $attribute */
82
- foreach ($ this ->collection ->getAttributes () as $ attribute ) {
86
+ foreach ($ this ->collectionFactory -> create () ->getAttributes () as $ attribute ) {
83
87
$ attributeCode = $ attribute ->getAttributeCode ();
84
88
$ locatedType = $ this ->typeLocator ->getType ($ attributeCode , Product::ENTITY ) ?: 'String ' ;
85
89
$ locatedType = TypeProcessor::NORMALIZED_ANY_TYPE === $ locatedType ? 'String ' : ucfirst ($ locatedType );
0 commit comments