From 1fb0460f759385be09a9b9b71eb82cb955ddf2da Mon Sep 17 00:00:00 2001 From: Nicolasq Date: Fri, 19 Sep 2025 15:51:14 +0200 Subject: [PATCH 1/5] fix(products): handle product level attributes when type is not passed --- packages/sync-actions/src/product-actions.js | 5 ++-- .../test/product-sync-base.spec.js | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/sync-actions/src/product-actions.js b/packages/sync-actions/src/product-actions.js index 2cd6bc99c..6b8964acb 100644 --- a/packages/sync-actions/src/product-actions.js +++ b/packages/sync-actions/src/product-actions.js @@ -97,7 +97,6 @@ function _buildAttributeValue( newAttributeValue ) { let value - if (Array.isArray(diffedValue)) value = diffpatcher.getDeltaValue(diffedValue, oldAttributeValue) else if (typeof diffedValue === 'string') @@ -175,7 +174,7 @@ function _buildSetAttributeAction( attribute, sameForAllAttributeNames ) { - if (!attribute) return undefined + if (!attribute || !diffedValue) return undefined let action = { action: 'setAttribute', @@ -219,7 +218,7 @@ function _buildSetProductAttributeAction( oldProductData, newAttribute ) { - if (!newAttribute) return undefined + if (!newAttribute || !diffedValue) return undefined const action = { action: 'setProductAttribute', diff --git a/packages/sync-actions/test/product-sync-base.spec.js b/packages/sync-actions/test/product-sync-base.spec.js index 0e6035d6c..dc1176c97 100644 --- a/packages/sync-actions/test/product-sync-base.spec.js +++ b/packages/sync-actions/test/product-sync-base.spec.js @@ -837,4 +837,28 @@ describe('Actions', () => { { action: 'setProductAttribute', name: 'indexedAttr', value: 'newValue' }, ]) }) + + test('should not fail when type is not passed', () => { + const before = { + attributes: [ + { + type: 'text', + name: 'batteryIncluded', + value: 'No', + }, + ], + } + + const now = { + attributes: [ + { + name: 'batteryIncluded', + value: 'No', + }, + ], + } + const actions = productsSync.buildActions(now, before) + + expect(actions).toEqual([]) + }) }) From 35464f2e78e87ce41bd56d212214c1245c56f662 Mon Sep 17 00:00:00 2001 From: Nicolasq Date: Fri, 19 Sep 2025 16:05:47 +0200 Subject: [PATCH 2/5] chore(products): add changeset for handle product level attributes when type is not passed --- .changeset/plain-crews-jog.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/plain-crews-jog.md diff --git a/.changeset/plain-crews-jog.md b/.changeset/plain-crews-jog.md new file mode 100644 index 000000000..7f122f929 --- /dev/null +++ b/.changeset/plain-crews-jog.md @@ -0,0 +1,5 @@ +--- +'@commercetools/sync-actions': minor +--- + +handle product level attributes when type is not passed From e3ea9679c76f4534066c0787e2009465408909d5 Mon Sep 17 00:00:00 2001 From: Nicolasq Date: Fri, 19 Sep 2025 17:46:31 +0200 Subject: [PATCH 3/5] fix(products): fix undefined value being passed in product level attribute --- .../test/product-sync-base.spec.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/sync-actions/test/product-sync-base.spec.js b/packages/sync-actions/test/product-sync-base.spec.js index dc1176c97..5c64994e2 100644 --- a/packages/sync-actions/test/product-sync-base.spec.js +++ b/packages/sync-actions/test/product-sync-base.spec.js @@ -842,9 +842,8 @@ describe('Actions', () => { const before = { attributes: [ { - type: 'text', - name: 'batteryIncluded', - value: 'No', + name: 'price', + value: { centAmount: 100, currencyCode: 'USD' }, }, ], } @@ -852,13 +851,21 @@ describe('Actions', () => { const now = { attributes: [ { - name: 'batteryIncluded', - value: 'No', + name: 'price', + value: undefined, }, ], } const actions = productsSync.buildActions(now, before) - expect(actions).toEqual([]) + const expected = [ + { + action: 'setProductAttribute', + name: 'price', + value: now.attributes[0].value, + }, + ] + + expect(actions).toEqual(expected) }) }) From 0b8ac89f4b065664038081edfb21a25a1f8990a2 Mon Sep 17 00:00:00 2001 From: Nicolasq Date: Fri, 19 Sep 2025 17:52:58 +0200 Subject: [PATCH 4/5] chore(products): fix changeset --- .changeset/plain-crews-jog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/plain-crews-jog.md b/.changeset/plain-crews-jog.md index 7f122f929..e1414c04e 100644 --- a/.changeset/plain-crews-jog.md +++ b/.changeset/plain-crews-jog.md @@ -2,4 +2,4 @@ '@commercetools/sync-actions': minor --- -handle product level attributes when type is not passed +handle product level attributes when money value is undefined From 9a4c03654591add687d44bde3ff1792dff463273 Mon Sep 17 00:00:00 2001 From: Nicolasq Date: Fri, 19 Sep 2025 17:59:56 +0200 Subject: [PATCH 5/5] chore(products): add comments --- packages/sync-actions/src/product-actions.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/sync-actions/src/product-actions.js b/packages/sync-actions/src/product-actions.js index 6b8964acb..f63d61e19 100644 --- a/packages/sync-actions/src/product-actions.js +++ b/packages/sync-actions/src/product-actions.js @@ -174,6 +174,7 @@ function _buildSetAttributeAction( attribute, sameForAllAttributeNames ) { + // in the case of diffedValue being null or undefined, _buildAttributeValue will fail. if (!attribute || !diffedValue) return undefined let action = { @@ -218,6 +219,7 @@ function _buildSetProductAttributeAction( oldProductData, newAttribute ) { + // in the case of diffedValue being null or undefined, _buildAttributeValue will fail. if (!newAttribute || !diffedValue) return undefined const action = {