6
6
7
7
namespace Magento \ConfigurableProduct \Model ;
8
8
9
+ use Magento \Catalog \Api \Data \ProductAttributeMediaGalleryEntryInterfaceFactory ;
9
10
use Magento \Catalog \Api \Data \ProductInterface ;
10
11
use Magento \Catalog \Api \Data \ProductInterfaceFactory ;
11
12
use Magento \Catalog \Api \ProductRepositoryInterface ;
15
16
use Magento \ConfigurableProduct \Helper \Product \Options \Factory ;
16
17
use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \Configurable ;
17
18
use Magento \Framework \Api \DataObjectHelper ;
19
+ use Magento \Framework \App \ObjectManager ;
18
20
use Magento \Framework \Exception \InputException ;
19
21
use Magento \Framework \Exception \NoSuchEntityException ;
20
22
use Magento \Framework \Exception \StateException ;
@@ -61,6 +63,11 @@ class LinkManagement implements LinkManagementInterface
61
63
*/
62
64
private ProductRepository $ mediaGallery ;
63
65
66
+ /**
67
+ * @var ProductAttributeMediaGalleryEntryInterfaceFactory|mixed
68
+ */
69
+ private ProductAttributeMediaGalleryEntryInterfaceFactory $ myModelFactory ;
70
+
64
71
/**
65
72
* Constructor
66
73
*
@@ -70,6 +77,7 @@ class LinkManagement implements LinkManagementInterface
70
77
* @param DataObjectHelper $dataObjectHelper
71
78
* @param AttributeFactory|null $attributeFactory
72
79
* @param ProductRepository|null $mediaGalleryProcessor
80
+ * @param ProductAttributeMediaGalleryEntryInterfaceFactory|null $myModelFactory
73
81
* @param Factory|null $optionsFactory
74
82
*/
75
83
public function __construct (
@@ -79,17 +87,20 @@ public function __construct(
79
87
DataObjectHelper $ dataObjectHelper ,
80
88
?AttributeFactory $ attributeFactory = null ,
81
89
?ProductRepository $ mediaGalleryProcessor = null ,
90
+ ?ProductAttributeMediaGalleryEntryInterfaceFactory $ myModelFactory = null ,
82
91
?Factory $ optionsFactory = null
83
92
) {
84
93
$ this ->productRepository = $ productRepository ;
85
94
$ this ->productFactory = $ productFactory ;
86
95
$ this ->configurableType = $ configurableType ;
87
96
$ this ->dataObjectHelper = $ dataObjectHelper ;
88
- $ this ->attributeFactory = $ attributeFactory ?: \ Magento \ Framework \ App \ ObjectManager::getInstance ()
97
+ $ this ->attributeFactory = $ attributeFactory ?: ObjectManager::getInstance ()
89
98
->get (AttributeFactory::class);
90
- $ this ->mediaGallery = $ mediaGalleryProcessor ?: \ Magento \ Framework \ App \ ObjectManager::getInstance ()
99
+ $ this ->mediaGallery = $ mediaGalleryProcessor ?: ObjectManager::getInstance ()
91
100
->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 ()
93
104
->get (Factory::class);
94
105
}
95
106
@@ -129,6 +140,30 @@ public function getChildren($sku)
129
140
return $ childrenList ;
130
141
}
131
142
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
+
132
167
/**
133
168
* @inheritdoc
134
169
* @throws InputException
0 commit comments