diff --git a/pkg/integration-kencove-api/src/products.ts b/pkg/integration-kencove-api/src/products.ts index 17f7b303a..cdcaef4dd 100644 --- a/pkg/integration-kencove-api/src/products.ts +++ b/pkg/integration-kencove-api/src/products.ts @@ -461,20 +461,30 @@ export class KencoveApiAppProductSyncService { */ private async setAttributeValue({ attribute, + attributeInProduct, attributeValue, productId, variantId, isForVariant, }: { attribute: Attribute; - attributeValue: string; + attributeInProduct?: KencoveApiAttributeInProduct; + attributeValue?: string; productId?: string; variantId?: string; isForVariant: boolean; }) { - const attributeValueDecoded = htmlDecode(attributeValue); - const normalizedName = - normalizeStrings.attributeValueNames(attributeValue); + const valueEncoded = attributeValue || attributeInProduct?.value; + if (!valueEncoded) { + this.logger.error( + `Attribute ${attribute.name} has no value. Skipping.`, + ); + return; + } + const attributeValueDecoded = htmlDecode(valueEncoded); + const normalizedName = normalizeStrings.attributeValueNames( + attributeValueDecoded, + ); this.logger.debug( `Setting attribute ${attribute.name}, value ${attributeValueDecoded}`, ); @@ -513,7 +523,10 @@ export class KencoveApiAppProductSyncService { id: this.kencoveApiApp.tenantId, }, }, - value: attributeValueDecoded, + value: + hexCode && attributeInProduct?.attribute_text + ? attributeInProduct.attribute_text + : attributeValueDecoded, hexColor: hexCode, productVariant: { connect: { @@ -547,7 +560,10 @@ export class KencoveApiAppProductSyncService { id: this.kencoveApiApp.tenantId, }, }, - value: attributeValueDecoded, + value: + hexCode && attributeInProduct?.attribute_text + ? attributeInProduct.attribute_text + : attributeValueDecoded, hexColor: hexCode, product: { connect: { diff --git a/pkg/integration-kencove-api/src/types.d.ts b/pkg/integration-kencove-api/src/types.d.ts index e3ab9c2aa..ac5363c2c 100644 --- a/pkg/integration-kencove-api/src/types.d.ts +++ b/pkg/integration-kencove-api/src/types.d.ts @@ -107,6 +107,11 @@ export type KencoveApiAttributeInProduct = { attribute_id: number; display_type: string; attribute_model: string; + /** + * When attribute value is a hex value, like "#000000" + * then this is the text value of the color, like "Black" + */ + attribute_text?: string | null | undefined; }; export type KencoveApiContact = {