6
6
7
7
namespace Magento \CatalogGraphQl \Model \Config ;
8
8
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 ;
9
12
use Magento \Framework \Config \ReaderInterface ;
10
13
use Magento \Framework \GraphQl \Schema \Type \Entity \MapperInterface ;
11
- use Magento \Catalog \Model \ResourceModel \Product \Attribute \Collection as AttributesCollection ;
12
14
13
15
/**
14
16
* Adds custom/eav attribute to catalog products sorting in the GraphQL config.
@@ -31,20 +33,23 @@ class SortAttributeReader implements ReaderInterface
31
33
private $ mapper ;
32
34
33
35
/**
34
- * @var AttributesCollection
36
+ * @var AttributesCollectionFactory
35
37
*/
36
- private $ attributesCollection ;
38
+ private $ attributesCollectionFactory ;
37
39
38
40
/**
39
41
* @param MapperInterface $mapper
40
42
* @param AttributesCollection $attributesCollection
43
+ * @param AttributesCollectionFactory|null $attributesCollectionFactory
41
44
*/
42
45
public function __construct (
43
46
MapperInterface $ mapper ,
44
- AttributesCollection $ attributesCollection
47
+ AttributesCollection $ attributesCollection ,
48
+ ?AttributesCollectionFactory $ attributesCollectionFactory = null
45
49
) {
46
50
$ this ->mapper = $ mapper ;
47
- $ this ->attributesCollection = $ attributesCollection ;
51
+ $ this ->attributesCollectionFactory = $ attributesCollectionFactory
52
+ ?? ObjectManager::getInstance ()->get (AttributesCollectionFactory::class);
48
53
}
49
54
50
55
/**
@@ -58,7 +63,8 @@ public function read($scope = null) : array
58
63
{
59
64
$ map = $ this ->mapper ->getMappedTypes (self ::ENTITY_TYPE );
60
65
$ 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 );
62
68
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
63
69
foreach ($ attributes as $ attribute ) {
64
70
$ attributeCode = $ attribute ->getAttributeCode ();
@@ -73,7 +79,6 @@ public function read($scope = null) : array
73
79
];
74
80
}
75
81
}
76
-
77
82
return $ config ;
78
83
}
79
84
}
0 commit comments