File tree Expand file tree Collapse file tree 4 files changed +28
-24
lines changed Expand file tree Collapse file tree 4 files changed +28
-24
lines changed Original file line number Diff line number Diff line change @@ -207,8 +207,8 @@ public function isMainImage($image)
207
207
*/
208
208
public function getImageAttribute ($ imageId , $ attributeName , $ default = null )
209
209
{
210
- $ attributes =
211
- $ this -> getConfigView () ->getMediaAttributes ('Magento_Catalog ' , Image::MEDIA_TYPE_CONFIG_NODE , $ imageId );
210
+ $ attributes = $ this -> getConfigView ()
211
+ ->getMediaAttributes ('Magento_Catalog ' , Image::MEDIA_TYPE_CONFIG_NODE , $ imageId );
212
212
return $ attributes [$ attributeName ] ?? $ default ;
213
213
}
214
214
@@ -239,23 +239,4 @@ private function getGalleryImagesConfig()
239
239
240
240
return $ this ->getData ('gallery_images_config ' );
241
241
}
242
-
243
- /**
244
- * Get main product image
245
- *
246
- * @param string $size
247
- * @return string
248
- */
249
- public function getMainProductImage ($ size = 'medium_image_url ' )
250
- {
251
- foreach ($ this ->getGalleryImages () as $ image ) {
252
- $ image = $ image ->getData ($ size );
253
-
254
- if (!$ image ) {
255
- return $ this ->_imageHelper ->getDefaultPlaceholderUrl ('image ' );
256
- }
257
-
258
- return $ image ;
259
- }
260
- }
261
242
}
Original file line number Diff line number Diff line change 6
6
namespace Magento \Catalog \Helper ;
7
7
8
8
use Magento \Framework \App \Helper \AbstractHelper ;
9
+ use Magento \Framework \View \Element \Block \ArgumentInterface ;
9
10
10
11
/**
11
12
* Catalog image helper
14
15
* @SuppressWarnings(PHPMD.TooManyFields)
15
16
* @since 100.0.2
16
17
*/
17
- class Image extends AbstractHelper
18
+ class Image extends AbstractHelper implements ArgumentInterface
18
19
{
19
20
/**
20
21
* Media config node
Original file line number Diff line number Diff line change 121
121
</arguments >
122
122
</block >
123
123
</container >
124
- <block class =" Magento\Catalog\Block\Product\View\Gallery" name =" product.info.media.image" template =" Magento_Catalog::product/view/gallery.phtml" />
124
+ <block class =" Magento\Catalog\Block\Product\View\Gallery" name =" product.info.media.image" template =" Magento_Catalog::product/view/gallery.phtml" >
125
+ <arguments >
126
+ <argument name =" imageHelper" xsi : type =" object" >Magento\Catalog\Helper\Image</argument >
127
+ </arguments >
128
+ </block >
125
129
<container name =" skip_gallery_after.wrapper" htmlTag =" div" htmlClass =" action-skip-wrapper" >
126
130
<block class =" Magento\Framework\View\Element\Template" after =" product.info.media.image" name =" skip_gallery_after" template =" Magento_Theme::html/skip.phtml" >
127
131
<arguments >
Original file line number Diff line number Diff line change 13
13
*/
14
14
?>
15
15
16
+ <?php
17
+ $ images = $ block ->getGalleryImages ()->getItems ();
18
+ $ mainImage = current (array_filter ($ images , function ($ img ) use ($ block ) {
19
+ return $ block ->isMainImage ($ img );
20
+ }));
21
+
22
+ if (!empty ($ images ) && empty ($ mainImage )) {
23
+ $ mainImage = $ block ->getGalleryImages ()->getFirstItem ();
24
+ }
25
+
26
+ $ helper = $ block ->getData ('imageHelper ' );
27
+ $ mainImageData = $ mainImage ?
28
+ $ mainImage ->getData ('medium_image_url ' ) :
29
+ $ helper ->getDefaultPlaceholderUrl ('image ' );
30
+
31
+ ?>
32
+
16
33
<div class="gallery-placeholder _block-content-loading" data-gallery-role="gallery-placeholder">
17
34
<img
35
+ alt="main product photo"
18
36
class="gallery-placeholder__image"
19
- src="<?= /* @escapeNotVerified */ $ block -> getMainProductImage () ?> "
37
+ src="<?= /* @noEscape */ $ mainImageData ?> "
20
38
/>
21
39
</div>
22
40
You can’t perform that action at this time.
0 commit comments