Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f43a51e

Browse files
authored
Remove product images duplication (#18380)
| Q | A |-----------------|----- | Branch? | 1.14 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | fixes #16771 | License | MIT <!-- - Bug fixes must be submitted against the 1.14 or 2.0 branch - Features and deprecations must be submitted against the 2.1 branch - Make sure that the correct base branch is set To be sure you are not breaking any Backward Compatibilities, check the documentation: https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html -->
2 parents dd8c814 + 444230c commit f43a51e

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/Sylius/Bundle/ShopBundle/Resources/private/js/sylius-variant-images.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,18 @@ $.fn.extend({
8383
}
8484
},
8585
});
86+
87+
const mainImage = $('a.ui.fluid.image > img');
88+
mainImage.click((e) => {
89+
e.preventDefault();
90+
91+
const mainImageSrcExploded = e.target.src.split('/');
92+
93+
const thumbnails = $('[data-lightbox="sylius-product-image"]');
94+
thumbnails.each((index, element) => {
95+
const imageSrcExploded = $(element).find('img').attr('src').split('/');
96+
if (mainImageSrcExploded[mainImageSrcExploded.length - 1] === imageSrcExploded[imageSrcExploded.length - 1]) {
97+
element.click();
98+
}
99+
});
100+
});

src/Sylius/Bundle/ShopBundle/Resources/views/Product/Show/_images.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{% endif %}
1717

1818
<div data-product-image="{{ path }}" data-product-link="{{ original_path }}"></div>
19-
<a href="{{ original_path }}" class="ui fluid image" data-lightbox="sylius-product-image">
19+
<a href="{{ original_path }}" class="ui fluid image"{% if product.images|length < 2%} data-lightbox="sylius-product-image"{% endif %}>
2020
<img src="{{ path }}" id="main-image" alt="{{ product.name }}" {{ sylius_test_html_attribute('main-image') }} />
2121
</a>
2222
{% if product.images|length > 1 %}

0 commit comments

Comments
 (0)