Skip to content

Commit 56e56ce

Browse files
authored
Merge pull request #4014 from magento-performance/MC-15440
MC-15440
2 parents 7e6e098 + ffaf00c commit 56e56ce

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

app/code/Magento/Catalog/Block/Product/View/Gallery.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ public function isMainImage($image)
207207
*/
208208
public function getImageAttribute($imageId, $attributeName, $default = null)
209209
{
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);
212212
return $attributes[$attributeName] ?? $default;
213213
}
214214

app/code/Magento/Catalog/Helper/Image.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Catalog\Helper;
77

88
use Magento\Framework\App\Helper\AbstractHelper;
9+
use Magento\Framework\View\Element\Block\ArgumentInterface;
910

1011
/**
1112
* Catalog image helper
@@ -14,7 +15,7 @@
1415
* @SuppressWarnings(PHPMD.TooManyFields)
1516
* @since 100.0.2
1617
*/
17-
class Image extends AbstractHelper
18+
class Image extends AbstractHelper implements ArgumentInterface
1819
{
1920
/**
2021
* Media config node
@@ -764,7 +765,7 @@ protected function getImageFile()
764765
protected function parseSize($string)
765766
{
766767
$size = explode('x', strtolower($string));
767-
if (sizeof($size) == 2) {
768+
if (count($size) == 2) {
768769
return ['width' => $size[0] > 0 ? $size[0] : null, 'height' => $size[1] > 0 ? $size[1] : null];
769770
}
770771
return false;

app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<block class="Magento\Catalog\Block\Product\View\Gallery" name="product.info.media.image" template="Magento_Catalog::product/view/gallery.phtml">
125125
<arguments>
126126
<argument name="gallery_options" xsi:type="object">Magento\Catalog\Block\Product\View\GalleryOptions</argument>
127+
<argument name="imageHelper" xsi:type="object">Magento\Catalog\Helper\Image</argument>
127128
</arguments>
128129
</block>
129130
<container name="skip_gallery_after.wrapper" htmlTag="div" htmlClass="action-skip-wrapper">

app/code/Magento/Catalog/view/frontend/templates/product/view/gallery.phtml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,32 @@
1212
* @var $block \Magento\Catalog\Block\Product\View\Gallery
1313
*/
1414
?>
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+
1533
<div class="gallery-placeholder _block-content-loading" data-gallery-role="gallery-placeholder">
16-
<div data-role="loader" class="loading-mask">
17-
<div class="loader">
18-
<img src="<?= /* @escapeNotVerified */ $block->getViewFileUrl('images/loader-1.gif') ?>"
19-
alt="<?= /* @escapeNotVerified */ __('Loading...') ?>">
20-
</div>
21-
</div>
34+
<img
35+
alt="main product photo"
36+
class="gallery-placeholder__image"
37+
src="<?= /* @noEscape */ $mainImageData ?>"
38+
/>
2239
</div>
23-
<!--Fix for jumping content. Loader must be the same size as gallery.-->
24-
<script>
25-
var config = {
26-
"width": <?= /* @escapeNotVerified */ $block->getImageAttribute('product_page_image_medium', 'width') ?>,
27-
"thumbheight": <?php /* @escapeNotVerified */ echo $block->getImageAttribute('product_page_image_small', 'height')
28-
?: $block->getImageAttribute('product_page_image_small', 'width'); ?>,
29-
"navtype": "<?= /* @escapeNotVerified */ $block->getVar("gallery/navtype") ?>",
30-
"height": <?= /* @escapeNotVerified */ $block->getImageAttribute('product_page_image_medium', 'height') ?>
31-
},
32-
thumbBarHeight = 0,
33-
loader = document.querySelectorAll('[data-gallery-role="gallery-placeholder"] [data-role="loader"]')[0];
34-
35-
if (config.navtype === 'horizontal') {
36-
thumbBarHeight = config.thumbheight;
37-
}
3840

39-
loader.style.paddingBottom = ( config.height / config.width * 100) + "%";
40-
</script>
4141
<script type="text/x-magento-init">
4242
{
4343
"[data-gallery-role=gallery-placeholder]": {

lib/web/mage/gallery/gallery.less

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -977,12 +977,9 @@
977977

978978
// While first time init
979979
.gallery-placeholder {
980-
.loading-mask {
981-
padding: 0 0 50%;
982-
position: static;
983-
}
984-
.loader img {
985-
position: absolute;
980+
&__image {
981+
display: block;
982+
margin: auto;
986983
}
987984
}
988985

@@ -1003,6 +1000,7 @@
10031000
display: block;
10041001
}
10051002
}
1003+
10061004
.fotorama__product-video--loaded {
10071005
.fotorama__img, .fotorama__img--full {
10081006
display: none !important;

0 commit comments

Comments
 (0)