7
7
8
8
namespace Magento \MediaStorage \Service ;
9
9
10
+ use Generator ;
10
11
use Magento \Catalog \Helper \Image as ImageHelper ;
11
12
use Magento \Catalog \Model \Product \Image \ParamsBuilder ;
12
13
use Magento \Catalog \Model \View \Asset \ImageFactory as AssertImageFactory ;
13
14
use Magento \Framework \App \Area ;
15
+ use Magento \Framework \App \ObjectManager ;
14
16
use Magento \Framework \Exception \NotFoundException ;
15
17
use Magento \Framework \Filesystem ;
16
18
use Magento \Framework \Image ;
19
21
use Magento \Framework \App \State ;
20
22
use Magento \Framework \View \ConfigInterface as ViewConfig ;
21
23
use \Magento \Catalog \Model \ResourceModel \Product \Image as ProductImage ;
24
+ use Magento \Store \Model \StoreManagerInterface ;
22
25
use Magento \Theme \Model \Config \Customization as ThemeCustomizationConfig ;
23
26
use Magento \Theme \Model \ResourceModel \Theme \Collection ;
24
27
use Magento \Framework \App \Filesystem \DirectoryList ;
25
28
use Magento \MediaStorage \Helper \File \Storage \Database ;
29
+ use Magento \Theme \Model \Theme ;
26
30
27
31
/**
28
32
* Image resize service.
@@ -90,6 +94,10 @@ class ImageResize
90
94
* @var Database
91
95
*/
92
96
private $ fileStorageDatabase ;
97
+ /**
98
+ * @var StoreManagerInterface
99
+ */
100
+ private $ storeManager ;
93
101
94
102
/**
95
103
* @param State $appState
@@ -103,6 +111,8 @@ class ImageResize
103
111
* @param Collection $themeCollection
104
112
* @param Filesystem $filesystem
105
113
* @param Database $fileStorageDatabase
114
+ * @param StoreManagerInterface $storeManager
115
+ * @throws \Magento\Framework\Exception\FileSystemException
106
116
* @internal param ProductImage $gallery
107
117
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
108
118
*/
@@ -117,7 +127,8 @@ public function __construct(
117
127
ThemeCustomizationConfig $ themeCustomizationConfig ,
118
128
Collection $ themeCollection ,
119
129
Filesystem $ filesystem ,
120
- Database $ fileStorageDatabase = null
130
+ Database $ fileStorageDatabase = null ,
131
+ StoreManagerInterface $ storeManager = null
121
132
) {
122
133
$ this ->appState = $ appState ;
123
134
$ this ->imageConfig = $ imageConfig ;
@@ -131,7 +142,8 @@ public function __construct(
131
142
$ this ->mediaDirectory = $ filesystem ->getDirectoryWrite (DirectoryList::MEDIA );
132
143
$ this ->filesystem = $ filesystem ;
133
144
$ this ->fileStorageDatabase = $ fileStorageDatabase ?:
134
- \Magento \Framework \App \ObjectManager::getInstance ()->get (Database::class);
145
+ ObjectManager::getInstance ()->get (Database::class);
146
+ $ this ->storeManager = $ storeManager ?? ObjectManager::getInstance ()->get (StoreManagerInterface::class);
135
147
}
136
148
137
149
/**
@@ -163,10 +175,10 @@ public function resizeFromImageName(string $originalImageName)
163
175
* Create resized images of different sizes from themes.
164
176
*
165
177
* @param array|null $themes
166
- * @return \ Generator
178
+ * @return Generator
167
179
* @throws NotFoundException
168
180
*/
169
- public function resizeFromThemes (array $ themes = null ): \ Generator
181
+ public function resizeFromThemes (array $ themes = null ): Generator
170
182
{
171
183
$ count = $ this ->productImage ->getCountUsedProductImages ();
172
184
if (!$ count ) {
@@ -226,7 +238,8 @@ private function getThemesInUse(): array
226
238
private function getViewImages (array $ themes ): array
227
239
{
228
240
$ viewImages = [];
229
- /** @var \Magento\Theme\Model\Theme $theme */
241
+ $ stores = $ this ->storeManager ->getStores (true );
242
+ /** @var Theme $theme */
230
243
foreach ($ themes as $ theme ) {
231
244
$ config = $ this ->viewConfig ->getViewConfig (
232
245
[
@@ -236,9 +249,12 @@ private function getViewImages(array $themes): array
236
249
);
237
250
$ images = $ config ->getMediaEntities ('Magento_Catalog ' , ImageHelper::MEDIA_TYPE_CONFIG_NODE );
238
251
foreach ($ images as $ imageId => $ imageData ) {
239
- $ uniqIndex = $ this ->getUniqueImageIndex ($ imageData );
240
- $ imageData ['id ' ] = $ imageId ;
241
- $ viewImages [$ uniqIndex ] = $ imageData ;
252
+ foreach ($ stores as $ store ) {
253
+ $ data = $ this ->paramsBuilder ->build ($ imageData , (int ) $ store ->getId ());
254
+ $ uniqIndex = $ this ->getUniqueImageIndex ($ data );
255
+ $ data ['id ' ] = $ imageId ;
256
+ $ viewImages [$ uniqIndex ] = $ data ;
257
+ }
242
258
}
243
259
}
244
260
return $ viewImages ;
@@ -280,13 +296,13 @@ private function makeImage(string $originalImagePath, array $imageParams): Image
280
296
/**
281
297
* Resize image.
282
298
*
283
- * @param array $viewImage
299
+ * @param array $imageParams
284
300
* @param string $originalImagePath
285
301
* @param string $originalImageName
286
302
*/
287
- private function resize (array $ viewImage , string $ originalImagePath , string $ originalImageName )
303
+ private function resize (array $ imageParams , string $ originalImagePath , string $ originalImageName )
288
304
{
289
- $ imageParams = $ this -> paramsBuilder -> build ( $ viewImage );
305
+ unset( $ imageParams [ ' id ' ] );
290
306
$ image = $ this ->makeImage ($ originalImagePath , $ imageParams );
291
307
$ imageAsset = $ this ->assertImageFactory ->create (
292
308
[
0 commit comments