66
77namespace Magento \ConfigurableProduct \Model ;
88
9+ use Magento \Catalog \Api \Data \ProductAttributeMediaGalleryEntryInterfaceFactory ;
910use Magento \Catalog \Api \Data \ProductInterface ;
1011use Magento \Catalog \Api \Data \ProductInterfaceFactory ;
1112use Magento \Catalog \Api \ProductRepositoryInterface ;
1516use Magento \ConfigurableProduct \Helper \Product \Options \Factory ;
1617use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \Configurable ;
1718use Magento \Framework \Api \DataObjectHelper ;
19+ use Magento \Framework \App \ObjectManager ;
1820use Magento \Framework \Exception \InputException ;
1921use Magento \Framework \Exception \NoSuchEntityException ;
2022use Magento \Framework \Exception \StateException ;
@@ -61,6 +63,11 @@ class LinkManagement implements LinkManagementInterface
6163 */
6264 private ProductRepository $ mediaGallery ;
6365
66+ /**
67+ * @var ProductAttributeMediaGalleryEntryInterfaceFactory|mixed
68+ */
69+ private ProductAttributeMediaGalleryEntryInterfaceFactory $ myModelFactory ;
70+
6471 /**
6572 * Constructor
6673 *
@@ -70,6 +77,7 @@ class LinkManagement implements LinkManagementInterface
7077 * @param DataObjectHelper $dataObjectHelper
7178 * @param AttributeFactory|null $attributeFactory
7279 * @param ProductRepository|null $mediaGalleryProcessor
80+ * @param ProductAttributeMediaGalleryEntryInterfaceFactory|null $myModelFactory
7381 * @param Factory|null $optionsFactory
7482 */
7583 public function __construct (
@@ -79,17 +87,20 @@ public function __construct(
7987 DataObjectHelper $ dataObjectHelper ,
8088 ?AttributeFactory $ attributeFactory = null ,
8189 ?ProductRepository $ mediaGalleryProcessor = null ,
90+ ?ProductAttributeMediaGalleryEntryInterfaceFactory $ myModelFactory = null ,
8291 ?Factory $ optionsFactory = null
8392 ) {
8493 $ this ->productRepository = $ productRepository ;
8594 $ this ->productFactory = $ productFactory ;
8695 $ this ->configurableType = $ configurableType ;
8796 $ this ->dataObjectHelper = $ dataObjectHelper ;
88- $ this ->attributeFactory = $ attributeFactory ?: \ Magento \ Framework \ App \ ObjectManager::getInstance ()
97+ $ this ->attributeFactory = $ attributeFactory ?: ObjectManager::getInstance ()
8998 ->get (AttributeFactory::class);
90- $ this ->mediaGallery = $ mediaGalleryProcessor ?: \ Magento \ Framework \ App \ ObjectManager::getInstance ()
99+ $ this ->mediaGallery = $ mediaGalleryProcessor ?: ObjectManager::getInstance ()
91100 ->get (ProductRepository::class);
92- $ this ->optionsFactory = $ optionsFactory ?: \Magento \Framework \App \ObjectManager::getInstance ()
101+ $ this ->myModelFactory = $ myModelFactory ?: ObjectManager::getInstance ()
102+ ->get (ProductAttributeMediaGalleryEntryInterfaceFactory::class);
103+ $ this ->optionsFactory = $ optionsFactory ?: ObjectManager::getInstance ()
93104 ->get (Factory::class);
94105 }
95106
@@ -129,6 +140,30 @@ public function getChildren($sku)
129140 return $ childrenList ;
130141 }
131142
143+ /**
144+ * Get media entries
145+ *
146+ * @param array $images
147+ * @return array
148+ * @deprecated This approach is designed only for images
149+ * @see ProductInterface::getMediaGalleryEntries
150+ */
151+ public function getMediaEntries (array $ images ): array
152+ {
153+ $ media = $ this ->myModelFactory ->create ();
154+ $ mediaGalleryEntries =[];
155+ foreach ($ images as $ image ) {
156+ $ media ->setId ($ image ["value_id " ]);
157+ $ media ->setMediaType ($ image ["media_type " ]);
158+ $ media ->setLabel ($ image ["label " ]);
159+ $ media ->setPosition ($ image ["position " ]);
160+ $ media ->setDisabled ($ image ["disabled " ]);
161+ $ media ->setFile ($ image ["file " ]);
162+ $ mediaGalleryEntries []=$ media ->getData ();
163+ }
164+ return $ mediaGalleryEntries ;
165+ }
166+
132167 /**
133168 * @inheritdoc
134169 * @throws InputException
0 commit comments