Skip to content

Commit

Permalink
feat: introduce a better pattern for creating a SimilarProducts Request
Browse files Browse the repository at this point in the history
  • Loading branch information
mzanoni committed Mar 15, 2024
1 parent 04127ee commit 1232c4f
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<SimilarProductsEvaluationSettings>) => 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;
}
Expand Down

0 comments on commit 1232c4f

Please sign in to comment.