diff --git a/packages/client/src/builders/search/facetBuilder.ts b/packages/client/src/builders/search/facetBuilder.ts index eaf0771..596acb3 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,24 @@ 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: purchaseQualifiers, + }; + + 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()