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.
@@ -79,8 +80,9 @@ class DynamicField implements FieldProviderInterface
7980 * @param SearchCriteriaBuilder $searchCriteriaBuilder
8081 * @param FieldNameResolver $fieldNameResolver
8182 * @param AttributeProvider $attributeAdapterProvider
82- * @param Collection $categoryCollection
83+ * @param Collection $categoryCollection @deprecated @see $categoryCollectionFactory
8384 * @param StoreManagerInterface|null $storeManager
85+ * * @param CollectionFactory|null $categoryCollectionFactory
8486 */
8587 public function __construct (
8688 FieldTypeConverterInterface $ fieldTypeConverter ,
@@ -90,15 +92,16 @@ public function __construct(
9092 FieldNameResolver $ fieldNameResolver ,
9193 AttributeProvider $ attributeAdapterProvider ,
9294 Collection $ categoryCollection ,
93- ?StoreManagerInterface $ storeManager = null
95+ ?StoreManagerInterface $ storeManager = null ,
96+ ?CollectionFactory $ categoryCollectionFactory = null
9497 ) {
9598 $ this ->groupRepository = $ groupRepository ;
9699 $ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
97100 $ this ->fieldTypeConverter = $ fieldTypeConverter ;
98101 $ this ->indexTypeConverter = $ indexTypeConverter ;
99102 $ this ->fieldNameResolver = $ fieldNameResolver ;
100103 $ this ->attributeAdapterProvider = $ attributeAdapterProvider ;
101- $ this ->categoryCollection = $ categoryCollection ;
104+ $ this ->categoryCollectionFactory = $ categoryCollectionFactory ?: 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