Skip to content

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

Open
@junajan

Description

@junajan

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.",

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions