From 0a4ebaf109d8a561bb1d0d44acdeca6cabfb3c8c Mon Sep 17 00:00:00 2001 From: Simon Walenkamp Hansen Date: Tue, 20 Aug 2024 15:11:10 +0200 Subject: [PATCH 1/3] recently purchased facet --- .../src/builders/search/facetBuilder.ts | 28 +++++++++++++++++-- .../facets.integration.test.ts | 16 +++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/packages/client/src/builders/search/facetBuilder.ts b/packages/client/src/builders/search/facetBuilder.ts index eaf0771..34a8611 100644 --- a/packages/client/src/builders/search/facetBuilder.ts +++ b/packages/client/src/builders/search/facetBuilder.ts @@ -1,4 +1,4 @@ -import { ProductCategoryAssortmentFacet, BrandFacet, CategoryFacet, CategoryPath, CategoryHierarchyFacet, SelectedProductCategoryPropertiesSettings, SelectedContentCategoryPropertiesSettings, ContentAssortmentFacet, ContentDataBooleanValueFacet, ContentDataDoubleRangeFacet, ContentDataDoubleRangesFacet, ContentDataDoubleValueFacet, ContentDataStringValueFacet, FacetSettings, PriceRangeFacet, PriceRangesFacet, ProductAssortmentFacet, ProductCategoryDataBooleanValueFacet, ProductCategoryDataDoubleRangeFacet, ProductCategoryDataDoubleRangesFacet, ProductCategoryDataDoubleValueFacet, ProductCategoryDataStringValueFacet, ProductDataBooleanValueFacet, ProductDataDoubleRangeFacet, ProductDataDoubleRangesFacet, ProductDataDoubleValueFacet, ProductDataStringValueFacet, ProductFacetQuery, VariantSpecificationFacet, ProductDataObjectFacet, DoubleNullableRange, ContentDataObjectFacet, ProductCategoryDataObjectFacet } from '../../models/data-contracts'; +import { ProductCategoryAssortmentFacet, BrandFacet, CategoryFacet, CategoryPath, CategoryHierarchyFacet, SelectedProductCategoryPropertiesSettings, SelectedContentCategoryPropertiesSettings, ContentAssortmentFacet, ContentDataBooleanValueFacet, ContentDataDoubleRangeFacet, ContentDataDoubleRangesFacet, ContentDataDoubleValueFacet, ContentDataStringValueFacet, FacetSettings, PriceRangeFacet, PriceRangesFacet, ProductAssortmentFacet, ProductCategoryDataBooleanValueFacet, ProductCategoryDataDoubleRangeFacet, ProductCategoryDataDoubleRangesFacet, ProductCategoryDataDoubleValueFacet, ProductCategoryDataStringValueFacet, ProductDataBooleanValueFacet, ProductDataDoubleRangeFacet, ProductDataDoubleRangesFacet, ProductDataDoubleValueFacet, ProductDataStringValueFacet, ProductFacetQuery, VariantSpecificationFacet, ProductDataObjectFacet, DoubleNullableRange, ContentDataObjectFacet, ProductCategoryDataObjectFacet, RecentlyPurchasedFacet, PurchaseQualifiers } from '../../models/data-contracts'; import { DataObjectFilterConditionBuilder } from '../dataObjectFilterConditionBuilder'; import { DataObjectFacetBuilder } from './dataObjectFacetBuilder'; @@ -30,7 +30,8 @@ export class FacetBuilder { | ProductDataStringValueFacet | ProductDataBooleanValueFacet | ProductDataDoubleValueFacet - | VariantSpecificationFacet)[] = []; + | VariantSpecificationFacet + | RecentlyPurchasedFacet)[] = []; //#region Product public addCategoryFacet(categorySelectionStrategy: 'ImmediateParent' | 'Ancestors', selectedValues: string[] | null = null, facetSettings?: FacetSettings): this { @@ -357,6 +358,29 @@ export class FacetBuilder { return this; } + + public addRecentlyPurchasedFacet( + purchaseQualifiers: PurchaseQualifiers, + selectedValues: boolean[] | null = null, + facetSettings?: FacetSettings): this { + + const facet: RecentlyPurchasedFacet = { + $type: 'Relewise.Client.DataTypes.Search.Facets.Queries.RecentlyPurchasedFacet, Relewise.Client', + field: 'Data', + settings: facetSettings, + selected: selectedValues, + purchaseQualifiers: { + byUser: purchaseQualifiers.byUser ?? false, + byUserCompany: purchaseQualifiers.byUserCompany ?? false, + byUserParentCompany: purchaseQualifiers.byUserParentCompany ?? false, + sinceMinutesAgo: purchaseQualifiers.sinceMinutesAgo ?? 1234, + }, + }; + + this.facets.push(facet); + + return this; + } //#endregion //#region Content diff --git a/packages/client/tests/integration-tests/facets.integration.test.ts b/packages/client/tests/integration-tests/facets.integration.test.ts index 36423f3..4b53b52 100644 --- a/packages/client/tests/integration-tests/facets.integration.test.ts +++ b/packages/client/tests/integration-tests/facets.integration.test.ts @@ -14,6 +14,22 @@ function baseBuilder() { }); }; +test('RecentlyPurchased facet', async() => { + + const request: ProductSearchRequest = baseBuilder() + .facets(f => f.addRecentlyPurchasedFacet({ + byUser: true, + byUserCompany: false, + byUserParentCompany: false, + sinceMinutesAgo: 1140, + }, [true])) + .build(); + + const result = await searcher.searchProducts(request); + + expect(result?.facets?.items![0].field).toBe('User'); +}); + test('SalesPrice facet', async() => { const request: ProductSearchRequest = baseBuilder() From 9a42dfaee3274d62fa35c99b53557037309684a1 Mon Sep 17 00:00:00 2001 From: Simon Walenkamp Hansen Date: Thu, 22 Aug 2024 09:24:34 +0200 Subject: [PATCH 2/3] Remove test fallback values --- packages/client/src/builders/search/facetBuilder.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/client/src/builders/search/facetBuilder.ts b/packages/client/src/builders/search/facetBuilder.ts index 34a8611..1c119e7 100644 --- a/packages/client/src/builders/search/facetBuilder.ts +++ b/packages/client/src/builders/search/facetBuilder.ts @@ -370,10 +370,10 @@ export class FacetBuilder { settings: facetSettings, selected: selectedValues, purchaseQualifiers: { - byUser: purchaseQualifiers.byUser ?? false, - byUserCompany: purchaseQualifiers.byUserCompany ?? false, - byUserParentCompany: purchaseQualifiers.byUserParentCompany ?? false, - sinceMinutesAgo: purchaseQualifiers.sinceMinutesAgo ?? 1234, + byUser: purchaseQualifiers.byUser, + byUserCompany: purchaseQualifiers.byUserCompany, + byUserParentCompany: purchaseQualifiers.byUserParentCompany, + sinceMinutesAgo: purchaseQualifiers.sinceMinutesAgo, }, }; From 5a80e8f2bdff2bc3e1dfbf721d15d3b7278a386c Mon Sep 17 00:00:00 2001 From: Simon Walenkamp Hansen <141124692+SWH-Relewise@users.noreply.github.com> Date: Thu, 22 Aug 2024 10:58:56 +0200 Subject: [PATCH 3/3] Update packages/client/src/builders/search/facetBuilder.ts Co-authored-by: Martin Zanoni --- packages/client/src/builders/search/facetBuilder.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/client/src/builders/search/facetBuilder.ts b/packages/client/src/builders/search/facetBuilder.ts index 1c119e7..596acb3 100644 --- a/packages/client/src/builders/search/facetBuilder.ts +++ b/packages/client/src/builders/search/facetBuilder.ts @@ -369,12 +369,7 @@ export class FacetBuilder { field: 'Data', settings: facetSettings, selected: selectedValues, - purchaseQualifiers: { - byUser: purchaseQualifiers.byUser, - byUserCompany: purchaseQualifiers.byUserCompany, - byUserParentCompany: purchaseQualifiers.byUserParentCompany, - sinceMinutesAgo: purchaseQualifiers.sinceMinutesAgo, - }, + purchaseQualifiers: purchaseQualifiers, }; this.facets.push(facet);