@@ -26,7 +26,7 @@ class ImageEntryConverter implements EntryConverterInterface
26
26
/**
27
27
* Media Entry type code
28
28
*/
29
- const MEDIA_TYPE_CODE = 'image ' ;
29
+ public const MEDIA_TYPE_CODE = 'image ' ;
30
30
31
31
/**
32
32
* @var \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory
@@ -68,7 +68,6 @@ public function __construct(
68
68
ImageContentInterfaceFactory $ imageContentInterface = null ,
69
69
Filesystem $ filesystem = null ,
70
70
Mime $ imageMime = null
71
-
72
71
) {
73
72
$ this ->mediaGalleryEntryFactory = $ mediaGalleryEntryFactory ;
74
73
$ this ->dataObjectHelper = $ dataObjectHelper ;
@@ -89,6 +88,7 @@ public function getMediaEntryType()
89
88
* @param Product $product
90
89
* @param array $rowData
91
90
* @return ProductAttributeMediaGalleryEntryInterface $entry
91
+ * @throws FileSystemException
92
92
*/
93
93
public function convertTo (Product $ product , array $ rowData )
94
94
{
@@ -106,25 +106,17 @@ public function convertTo(Product $product, array $rowData)
106
106
if (isset ($ image ['value_id ' ])) {
107
107
$ entry ->setId ($ image ['value_id ' ]);
108
108
}
109
- $ imageFileContent = file_get_contents ($ product ->getMediaConfig ()->getMediaUrl (($ entry ->getFile ())));
109
+ $ mediaDirectory = $ this ->filesystem ->getDirectoryWrite (DirectoryList::MEDIA );
110
+ $ path = $ mediaDirectory ->getAbsolutePath ($ product ->getMediaConfig ()->getMediaPath ($ entry ->getFile ()));
111
+ $ imageFileContent = $ mediaDirectory ->getDriver ()->fileGetContents ($ path );
110
112
$ entryContent = $ this ->imageContentInterface ->create ()
111
113
->setName (basename ($ entry ->getFile ()))
112
114
->setBase64EncodedData (base64_encode ($ imageFileContent ))
113
- ->setType ($ this ->getImageMimeType ( $ product , $ entry ));
115
+ ->setType ($ this ->imageMime -> getMimeType ( $ path ));
114
116
$ entry ->setContent ($ entryContent );
115
117
return $ entry ;
116
118
}
117
119
118
- /**
119
- * @throws FileSystemException
120
- */
121
- public function getImageMimeType ($ product , $ entry )
122
- {
123
- $ directory = $ this ->filesystem ->getDirectoryRead (DirectoryList::MEDIA );
124
- $ path = $ directory ->getAbsolutePath ($ product ->getMediaConfig ()->getMediaPath ($ entry ->getFile ()));
125
- return $ this ->imageMime ->getMimeType ($ path );
126
- }
127
-
128
120
/**
129
121
* @param ProductAttributeMediaGalleryEntryInterface $entry
130
122
* @return array
0 commit comments