1818use Magento \Elasticsearch \Model \Adapter \FieldMapper \Product \FieldProviderInterface ;
1919use Magento \Framework \Api \SearchCriteriaBuilder ;
2020use Magento \Catalog \Model \ResourceModel \Category \Collection ;
21+ use Magento \Catalog \Model \ResourceModel \Category \CollectionFactory ;
2122use Magento \Framework \App \ObjectManager ;
2223use Magento \Store \Model \StoreManagerInterface ;
2324
@@ -29,9 +30,9 @@ class DynamicField implements FieldProviderInterface
2930 /**
3031 * Category collection.
3132 *
32- * @var Collection
33+ * @var CollectionFactory
3334 */
34- private $ categoryCollection ;
35+ private $ categoryCollectionFactory ;
3536
3637 /**
3738 * Customer group repository.
@@ -41,8 +42,6 @@ class DynamicField implements FieldProviderInterface
4142 private $ groupRepository ;
4243
4344 /**
44- * Search criteria builder.
45- *
4645 * @var SearchCriteriaBuilder
4746 */
4847 private $ searchCriteriaBuilder ;
@@ -79,8 +78,10 @@ class DynamicField implements FieldProviderInterface
7978 * @param SearchCriteriaBuilder $searchCriteriaBuilder
8079 * @param FieldNameResolver $fieldNameResolver
8180 * @param AttributeProvider $attributeAdapterProvider
82- * @param Collection $categoryCollection
81+ * @param Collection $categoryCollection @deprecated @see $categoryCollectionFactory
8382 * @param StoreManagerInterface|null $storeManager
83+ * @param CollectionFactory|null $categoryCollectionFactory
84+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
8485 */
8586 public function __construct (
8687 FieldTypeConverterInterface $ fieldTypeConverter ,
@@ -90,15 +91,17 @@ public function __construct(
9091 FieldNameResolver $ fieldNameResolver ,
9192 AttributeProvider $ attributeAdapterProvider ,
9293 Collection $ categoryCollection ,
93- ?StoreManagerInterface $ storeManager = null
94+ ?StoreManagerInterface $ storeManager = null ,
95+ ?CollectionFactory $ categoryCollectionFactory = null
9496 ) {
9597 $ this ->groupRepository = $ groupRepository ;
9698 $ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
9799 $ this ->fieldTypeConverter = $ fieldTypeConverter ;
98100 $ this ->indexTypeConverter = $ indexTypeConverter ;
99101 $ this ->fieldNameResolver = $ fieldNameResolver ;
100102 $ this ->attributeAdapterProvider = $ attributeAdapterProvider ;
101- $ this ->categoryCollection = $ categoryCollection ;
103+ $ this ->categoryCollectionFactory = $ categoryCollectionFactory
104+ ?: ObjectManager::getInstance ()->get (CollectionFactory::class);
102105 $ this ->storeManager = $ storeManager ?: ObjectManager::getInstance ()->get (StoreManagerInterface::class);
103106 }
104107
@@ -108,7 +111,7 @@ public function __construct(
108111 public function getFields (array $ context = []): array
109112 {
110113 $ allAttributes = [];
111- $ categoryIds = $ this ->categoryCollection ->getAllIds ();
114+ $ categoryIds = $ this ->categoryCollectionFactory -> create () ->getAllIds ();
112115 $ positionAttribute = $ this ->attributeAdapterProvider ->getByAttributeCode ('position ' );
113116 $ categoryNameAttribute = $ this ->attributeAdapterProvider ->getByAttributeCode ('category_name ' );
114117 foreach ($ categoryIds as $ categoryId ) {
0 commit comments