nodejs icon indicating copy to clipboard operation
nodejs copied to clipboard

[sync-actions] Compare only id and typeId fields when syncing references

Open junajan opened this issue 6 years ago • 0 comments

When syncing attributes with SET of REFERENCE type it should compare only fields id and typeId. For example:

If the attribute before and after looks like this:

{
	name: 'setOfReference',
	value: [{
		id: '517321b8-7e3f-4427-ac5e-9d9001d69dc4',
		typeId: 'product'
	}, {
		id: 'f49aceda-145b-4975-af1b-a8c782b54354',
		typeId: 'product'
	}]
}

It won't generate any update actions, which is correct.

But if the before looks like this:

{
	name: 'setOfReference',
	value: [{
		id: '517321b8-7e3f-4427-ac5e-9d9001d69dc4',
		typeId: 'product',
		obj: { /** resolved product */ }
	}, {
		id: 'f49aceda-145b-4975-af1b-a8c782b54354',
		typeId: 'product',
		obj: { /** resolved product */ }
	}]
}

It will generate update action:

{
	"action": {
		"action": "setAttribute",
		"variantId": 1,
		"name": "packageContents",
		"value": [{
			"typeId": "product",
			"id": "517321b8-7e3f-4427-ac5e-9d9001d69dc4"
		}, {
			"typeId": "product",
			"id": "f49aceda-145b-4975-af1b-a8c782b54354"
		}],
		"staged": true
	}
}

Which is wrong because SET items were not changed so the API will throw an error:

"message": "A duplicate combination of the variant values (sku, key, images, prices, attributes) exists.",

junajan avatar Apr 09 '19 15:04 junajan