18
18
use Magento \Elasticsearch \Model \Adapter \FieldMapper \Product \FieldProviderInterface ;
19
19
use Magento \Framework \Api \SearchCriteriaBuilder ;
20
20
use Magento \Catalog \Model \ResourceModel \Category \Collection ;
21
+ use Magento \Catalog \Model \ResourceModel \Category \CollectionFactory ;
21
22
use Magento \Framework \App \ObjectManager ;
22
23
use Magento \Store \Model \StoreManagerInterface ;
23
24
@@ -29,9 +30,9 @@ class DynamicField implements FieldProviderInterface
29
30
/**
30
31
* Category collection.
31
32
*
32
- * @var Collection
33
+ * @var CollectionFactory
33
34
*/
34
- private $ categoryCollection ;
35
+ private $ categoryCollectionFactory ;
35
36
36
37
/**
37
38
* Customer group repository.
@@ -41,8 +42,6 @@ class DynamicField implements FieldProviderInterface
41
42
private $ groupRepository ;
42
43
43
44
/**
44
- * Search criteria builder.
45
- *
46
45
* @var SearchCriteriaBuilder
47
46
*/
48
47
private $ searchCriteriaBuilder ;
@@ -79,8 +78,10 @@ class DynamicField implements FieldProviderInterface
79
78
* @param SearchCriteriaBuilder $searchCriteriaBuilder
80
79
* @param FieldNameResolver $fieldNameResolver
81
80
* @param AttributeProvider $attributeAdapterProvider
82
- * @param Collection $categoryCollection
81
+ * @param Collection $categoryCollection @deprecated @see $categoryCollectionFactory
83
82
* @param StoreManagerInterface|null $storeManager
83
+ * @param CollectionFactory|null $categoryCollectionFactory
84
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
84
85
*/
85
86
public function __construct (
86
87
FieldTypeConverterInterface $ fieldTypeConverter ,
@@ -90,15 +91,17 @@ public function __construct(
90
91
FieldNameResolver $ fieldNameResolver ,
91
92
AttributeProvider $ attributeAdapterProvider ,
92
93
Collection $ categoryCollection ,
93
- ?StoreManagerInterface $ storeManager = null
94
+ ?StoreManagerInterface $ storeManager = null ,
95
+ ?CollectionFactory $ categoryCollectionFactory = null
94
96
) {
95
97
$ this ->groupRepository = $ groupRepository ;
96
98
$ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
97
99
$ this ->fieldTypeConverter = $ fieldTypeConverter ;
98
100
$ this ->indexTypeConverter = $ indexTypeConverter ;
99
101
$ this ->fieldNameResolver = $ fieldNameResolver ;
100
102
$ this ->attributeAdapterProvider = $ attributeAdapterProvider ;
101
- $ this ->categoryCollection = $ categoryCollection ;
103
+ $ this ->categoryCollectionFactory = $ categoryCollectionFactory
104
+ ?: ObjectManager::getInstance ()->get (CollectionFactory::class);
102
105
$ this ->storeManager = $ storeManager ?: ObjectManager::getInstance ()->get (StoreManagerInterface::class);
103
106
}
104
107
@@ -108,7 +111,7 @@ public function __construct(
108
111
public function getFields (array $ context = []): array
109
112
{
110
113
$ allAttributes = [];
111
- $ categoryIds = $ this ->categoryCollection ->getAllIds ();
114
+ $ categoryIds = $ this ->categoryCollectionFactory -> create () ->getAllIds ();
112
115
$ positionAttribute = $ this ->attributeAdapterProvider ->getByAttributeCode ('position ' );
113
116
$ categoryNameAttribute = $ this ->attributeAdapterProvider ->getByAttributeCode ('category_name ' );
114
117
foreach ($ categoryIds as $ categoryId ) {
0 commit comments