From 3e758b08540a665c0c40a4d46206beda77e18115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Zari=C4=87?= <11561723+znikola@users.noreply.github.com> Date: Thu, 27 Jul 2023 11:42:25 +0200 Subject: [PATCH 1/9] fix: product image normalizer now properly checks for gallery index --- .../product/converters/product-image-normalizer.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts b/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts index a80e80e29a1..58e2282ecc9 100644 --- a/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts +++ b/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts @@ -37,7 +37,7 @@ export class ProductImageNormalizer implements Converter { 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 ? [] : {}; @@ -98,4 +98,9 @@ export class ProductImageNormalizer implements Converter { '') + url ); } + + private hasGalleryIndex(image: Occ.Image) { + const galleryIndex = image.galleryIndex ?? false; + return galleryIndex !== false; + } } From 5d06eea7c065504437585b20a440a933ed6c1bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Zari=C4=87?= <11561723+znikola@users.noreply.github.com> Date: Fri, 28 Jul 2023 09:13:01 +0200 Subject: [PATCH 2/9] Update projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts Co-authored-by: Brian Gamboc-Javiniar --- .../occ/adapters/product/converters/product-image-normalizer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts b/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts index 58e2282ecc9..3539ea28880 100644 --- a/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts +++ b/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts @@ -101,6 +101,6 @@ export class ProductImageNormalizer implements Converter { private hasGalleryIndex(image: Occ.Image) { const galleryIndex = image.galleryIndex ?? false; - return galleryIndex !== false; + return !isNaN(Number(image.galleryIndex)); } } From 48051d2290bf6a3614078d62187588672f21c38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Zari=C4=87?= <11561723+znikola@users.noreply.github.com> Date: Fri, 28 Jul 2023 09:15:18 +0200 Subject: [PATCH 3/9] move one-liner to normalize --- .../product/converters/product-image-normalizer.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts b/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts index 3539ea28880..b0bc2c930e6 100644 --- a/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts +++ b/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts @@ -37,7 +37,7 @@ export class ProductImageNormalizer implements Converter { const images: Images = {}; if (source) { for (const image of source) { - const isList = this.hasGalleryIndex(image); + const isList = isNaN(Number(image.galleryIndex)); if (image.imageType) { if (!images.hasOwnProperty(image.imageType)) { images[image.imageType] = isList ? [] : {}; @@ -98,9 +98,4 @@ export class ProductImageNormalizer implements Converter { '') + url ); } - - private hasGalleryIndex(image: Occ.Image) { - const galleryIndex = image.galleryIndex ?? false; - return !isNaN(Number(image.galleryIndex)); - } } From 2b3ac300ef54c17484df7d0153f306c343928846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Zari=C4=87?= <11561723+znikola@users.noreply.github.com> Date: Fri, 28 Jul 2023 09:23:23 +0200 Subject: [PATCH 4/9] fix --- .../occ/adapters/product/converters/product-image-normalizer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts b/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts index b0bc2c930e6..e95c0da8749 100644 --- a/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts +++ b/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts @@ -37,7 +37,7 @@ export class ProductImageNormalizer implements Converter { const images: Images = {}; if (source) { for (const image of source) { - const isList = isNaN(Number(image.galleryIndex)); + const isList = !isNaN(Number(image.galleryIndex)); if (image.imageType) { if (!images.hasOwnProperty(image.imageType)) { images[image.imageType] = isList ? [] : {}; From 17f9582fdaedf71af0e7b3dc37fb6392f2388ee4 Mon Sep 17 00:00:00 2001 From: I506207 Date: Mon, 31 Jul 2023 00:45:38 -0400 Subject: [PATCH 5/9] revert back to Nik's old solution --- .../product/converters/product-image-normalizer.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts b/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts index e95c0da8749..58e2282ecc9 100644 --- a/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts +++ b/projects/core/src/occ/adapters/product/converters/product-image-normalizer.ts @@ -37,7 +37,7 @@ export class ProductImageNormalizer implements Converter { const images: Images = {}; if (source) { for (const image of source) { - const isList = !isNaN(Number(image.galleryIndex)); + const isList = this.hasGalleryIndex(image); if (image.imageType) { if (!images.hasOwnProperty(image.imageType)) { images[image.imageType] = isList ? [] : {}; @@ -98,4 +98,9 @@ export class ProductImageNormalizer implements Converter { '') + url ); } + + private hasGalleryIndex(image: Occ.Image) { + const galleryIndex = image.galleryIndex ?? false; + return galleryIndex !== false; + } } From 6a589d0ce6dca39deec3f934b52b831f234f140b Mon Sep 17 00:00:00 2001 From: I506207 Date: Mon, 31 Jul 2023 01:26:54 -0400 Subject: [PATCH 6/9] add to unit test --- .../converters/product-image-normalizer.spec.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/projects/core/src/occ/adapters/product/converters/product-image-normalizer.spec.ts b/projects/core/src/occ/adapters/product/converters/product-image-normalizer.spec.ts index 35f8214bdfc..08db9541e18 100644 --- a/projects/core/src/occ/adapters/product/converters/product-image-normalizer.spec.ts +++ b/projects/core/src/occ/adapters/product/converters/product-image-normalizer.spec.ts @@ -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', @@ -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: [ { @@ -124,6 +138,7 @@ describe('ProductImageNormalizer', () => { it('should convert product image', () => { const result = service.convert(product); + console.log('result', result); expect(result).toEqual(convertedProduct); }); }); From 8e115b5ab9c92616f7388be9197659c81e20d757 Mon Sep 17 00:00:00 2001 From: I506207 Date: Mon, 31 Jul 2023 01:28:13 -0400 Subject: [PATCH 7/9] remove log... --- .../adapters/product/converters/product-image-normalizer.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/core/src/occ/adapters/product/converters/product-image-normalizer.spec.ts b/projects/core/src/occ/adapters/product/converters/product-image-normalizer.spec.ts index 08db9541e18..3266997eb74 100644 --- a/projects/core/src/occ/adapters/product/converters/product-image-normalizer.spec.ts +++ b/projects/core/src/occ/adapters/product/converters/product-image-normalizer.spec.ts @@ -138,7 +138,6 @@ describe('ProductImageNormalizer', () => { it('should convert product image', () => { const result = service.convert(product); - console.log('result', result); expect(result).toEqual(convertedProduct); }); }); From ed12d499613a0ecb5c40ec6c08b9592a61952421 Mon Sep 17 00:00:00 2001 From: I506207 Date: Mon, 31 Jul 2023 12:15:26 -0400 Subject: [PATCH 8/9] trigger build From b9273613731955878f75bdfe7fcc08b3e1d0ed30 Mon Sep 17 00:00:00 2001 From: I506207 Date: Mon, 31 Jul 2023 13:35:14 -0400 Subject: [PATCH 9/9] trigger build...