Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Updated: the code to render the images properly when using the mergeC…
Browse files Browse the repository at this point in the history
…onfigurableChildren to false (#551)
  • Loading branch information
ymaheshwari1 committed Dec 3, 2020
1 parent 7c17b00 commit 759b668
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions components/molecules/m-product-gallery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@
v-if="!isOnline"
:src="offlineImage"
/>
<SfGallery
ref="gallery"
:images="gallery"
/>
<div v-if="config.products.gallery.mergeConfigurableChildren">
<SfGallery
ref="gallery"
:images="gallery"
/>
</div>
<div v-else :key="currentIndex">
<SfGallery
ref="gallery"
:images="gallery"
/>
</div>
</div>
</template>

<script>
import config from 'config'
import isEqual from 'lodash-es/isEqual';
import { SfGallery, SfImage } from '@storefront-ui/vue';
import { onlineHelper } from '@vue-storefront/core/helpers';
Expand All @@ -22,6 +31,11 @@ export default {
SfGallery,
SfImage
},
data () {
return {
config
}
},
props: {
gallery: {
type: Array,
Expand Down Expand Up @@ -68,11 +82,15 @@ export default {
variantImage = this.gallery[0];
}
if (!config.products.gallery.mergeConfigurableChildren) {
variantImage = this.gallery[this.gallery.length - 1]
}
return variantImage;
},
currentIndex () {
const index = this.gallery.findIndex(imageObject =>
isEqual(imageObject.id, this.variantImage.id)
config.products.gallery.mergeConfigurableChildren ? isEqual(imageObject.id, this.variantImage.id) : isEqual(imageObject.desktop.url, this.variantImage.desktop.url)
);
return index === -1 ? 0 : index;
Expand Down

0 comments on commit 759b668

Please sign in to comment.