From 1232c4f58222fd2df4b4c6e3600b860e1f759da5 Mon Sep 17 00:00:00 2001 From: Martin Zanoni Date: Fri, 15 Mar 2024 13:55:58 +0100 Subject: [PATCH 1/2] feat: introduce a better pattern for creating a SimilarProducts Request --- .../products/similarProductsProductBuilder.ts | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/client/src/builders/recommendation/products/similarProductsProductBuilder.ts b/packages/client/src/builders/recommendation/products/similarProductsProductBuilder.ts index 9c34554..6146129 100644 --- a/packages/client/src/builders/recommendation/products/similarProductsProductBuilder.ts +++ b/packages/client/src/builders/recommendation/products/similarProductsProductBuilder.ts @@ -1,3 +1,4 @@ +import { deprecate } from 'util'; import { Settings } from '../../../builders/settings'; import { SimilarProductsRequest, SimilarProductsEvaluationSettings, Product } from '../../../models/data-contracts'; import { BySingleProductRecommendationBuilder } from './bySingleProductRecommendationBuilder'; @@ -13,8 +14,33 @@ export class SimilarProductsProductBuilder extends BySingleProductRecommendation super(settings); } + /** @deprecated + * Use setEvaluationSettings instead + */ public setSimilarProductsEvaluationSettings(settings: SimilarProductsEvaluationSettings): this { - this.evaluationSettings = settings; + this.evaluationSettings = settings as SimilarProductsEvaluationSettings; + + return this; + } + + public setEvaluationSettings(builder: (settings: Partial) => void): this { + const cleanSettings: SimilarProductsEvaluationSettings = { + significanceOfSimilaritiesInDisplayName: 0, + productDisplayNameTransformer: null, + significanceOfSimilarListPrice: 0, + significanceOfCommonImmediateParentCategories: 0, + significanceOfCommonParentsParentCategories: 0, + significanceOfCommonAncestorCategories: 0, + significanceOfCommonProductDataKeys: 0, + significanceOfIdenticalProductDataValues: 0, + significantProductDataFields: null, + significanceOfSimilarSalesPrice: 0, + significanceOfSimilarBrand: 0, + variantEvaluationSettings: null, + }; + + builder(cleanSettings); + this.evaluationSettings = cleanSettings; return this; } From 091c322d079a39df9b4a39291d1e15fcd81b42f5 Mon Sep 17 00:00:00 2001 From: Martin Zanoni Date: Fri, 15 Mar 2024 13:57:17 +0100 Subject: [PATCH 2/2] self review --- .../recommendation/products/similarProductsProductBuilder.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/client/src/builders/recommendation/products/similarProductsProductBuilder.ts b/packages/client/src/builders/recommendation/products/similarProductsProductBuilder.ts index 6146129..9600b1b 100644 --- a/packages/client/src/builders/recommendation/products/similarProductsProductBuilder.ts +++ b/packages/client/src/builders/recommendation/products/similarProductsProductBuilder.ts @@ -1,4 +1,3 @@ -import { deprecate } from 'util'; import { Settings } from '../../../builders/settings'; import { SimilarProductsRequest, SimilarProductsEvaluationSettings, Product } from '../../../models/data-contracts'; import { BySingleProductRecommendationBuilder } from './bySingleProductRecommendationBuilder';