Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: product image normalizer now properly checks for gallery index #17690

Merged
merged 13 commits into from
Jul 31, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ describe('ProductImageNormalizer', () => {
imageType: ImageType.PRIMARY,
url: 'https://hybris.com/test3.jpg',
},
{
altText: 'Test alt text',
format: 'cartIcon',
galleryIndex: null as any,
imageType: ImageType.PRIMARY,
url: '/test6',
},
{
altText: 'Test alt text',
format: 'product',
Expand Down Expand Up @@ -83,6 +90,13 @@ describe('ProductImageNormalizer', () => {
imageType: ImageType.PRIMARY,
url: 'https://hybris.com/test3.jpg',
},
cartIcon: {
altText: 'Test alt text',
format: 'cartIcon',
galleryIndex: null as any,
imageType: ImageType.PRIMARY,
url: baseUrl + '/test6',
},
},
GALLERY: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ProductImageNormalizer implements Converter<Occ.Product, Product> {
const images: Images = {};
if (source) {
for (const image of source) {
const isList = image.hasOwnProperty('galleryIndex');
const isList = this.hasGalleryIndex(image);
if (image.imageType) {
if (!images.hasOwnProperty(image.imageType)) {
images[image.imageType] = isList ? [] : {};
Expand Down Expand Up @@ -98,4 +98,9 @@ export class ProductImageNormalizer implements Converter<Occ.Product, Product> {
'') + url
);
}

private hasGalleryIndex(image: Occ.Image) {
const galleryIndex = image.galleryIndex ?? false;
return galleryIndex !== false;
znikola marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading