Skip to content

Commit

Permalink
feat: improvements for hex code attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikZed committed Oct 26, 2023
1 parent 779f34c commit 0308b06
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
28 changes: 22 additions & 6 deletions pkg/integration-kencove-api/src/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
);
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
5 changes: 5 additions & 0 deletions pkg/integration-kencove-api/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

1 comment on commit 0308b06

@vercel
Copy link

@vercel vercel bot commented on 0308b06 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.