public async void FilterProductsInChannelAndCategory() { var searchText = "searchTerm"; var searchByKeyword = !string.IsNullOrEmpty(searchText); var channel = new Channel() { Id = "dbb5a6d0-2cbb-4855-bbe7-5cf58f434a82" }; var categoryId = "abc5a6d0-2cbb-4855-bbe7-5cf58f434c122"; var searchRequest = new SearchProductProjectionsCommand(); searchRequest.SetPriceChannel(channel.Id); searchRequest.Filter(p => p.Categories.Any(c => c.Id == categoryId)); if (searchByKeyword) { if (searchRequest.SearchParameters is ProductProjectionSearchParameters searchParameters) { searchParameters.Text = new TextSearch { Term = searchText, Language = "en" }; } } var httpApiCommandFactory = this.clientFixture.GetService <IHttpApiCommandFactory>(); var httpApiCommand = httpApiCommandFactory.Create(searchRequest); var content = await httpApiCommand.HttpRequestMessage.Content.ReadAsStringAsync(); Assert.Equal($"text.en={searchText}&filter=categories.id%3A%22abc5a6d0-2cbb-4855-bbe7-5cf58f434c122%22&priceChannel=dbb5a6d0-2cbb-4855-bbe7-5cf58f434a82&withTotal=false", content); }
private void ConfigureAndCreateEntitiesBeforeRunningTests() { //update current project to support these languages var project = this.ChangeProjectLanguages(new List <string> { "en", "de" }); Assert.Equal(2, project.Languages.Count); Assert.True(project.Languages.Contains("en") && project.Languages.Contains("de")); //Fill entities this.FillCategories(); this.FillProducts(); var allProductIds = AvailableProducts.Select(product => product.Id).ToArray(); var searchRequest = new SearchProductProjectionsCommand(); searchRequest.SetStaged(true); searchRequest.FilterQuery(p => p.Id.In(allProductIds)); IClient commerceToolsClient = this.GetService <IClient>(); //wait till elastic search index refreshed with created products AssertEventually(() => { var searchResults = commerceToolsClient.ExecuteAsync(searchRequest).Result; Assert.Equal(allProductIds.Length, searchResults.Results.Count); }); }
public void SearchHttpApiCommand() { SearchProductProjectionsCommand searchCommand = new SearchProductProjectionsCommand(new ProductProjectionSearchParameters()); IHttpApiCommandFactory httpApiCommandFactory = this.clientFixture.GetService <IHttpApiCommandFactory>(); IHttpApiCommand httpApiCommand = httpApiCommandFactory.Create(searchCommand); Assert.Equal(typeof(SearchHttpApiCommand <ProductProjection>), httpApiCommand.GetType()); }
public void GetProductProjectionsFilterFacetByCentAmountRange() { IClient commerceToolsClient = this.productFixture.GetService <IClient>(); SearchProductProjectionsCommand searchProductProjectionsCommand = new SearchProductProjectionsCommand(); searchProductProjectionsCommand.FilterFacets(p => p.Variants.Any(v => v.Price.Value.CentAmount.Range(1, 3000))); PagedQueryResult <ProductProjection> results = commerceToolsClient.ExecuteAsync(searchProductProjectionsCommand).Result; Assert.Equal(20, results.Count); }
public void GetProductProjectionsTermFacet() { IClient commerceToolsClient = this.productFixture.GetService <IClient>(); Facet <ProductProjection> colorFacet = new TermFacet <ProductProjection>(p => p.Variants.Select(v => v.Attributes.Where(a => a.Name == "color").Select(a => ((EnumAttribute)a).Value.Key).FirstOrDefault()).FirstOrDefault()); ProductProjectionSearchParameters searchParameters = new ProductProjectionSearchParameters(); searchParameters.SetFacets(new List <Facet <ProductProjection> >() { colorFacet }); SearchProductProjectionsCommand searchProductProjectionsCommand = new SearchProductProjectionsCommand(searchParameters); PagedQueryResult <ProductProjection> results = commerceToolsClient.ExecuteAsync(searchProductProjectionsCommand).Result; int facetCount = ((TermFacetResult)results.Facets["variants.attributes.color.key"]).Terms.Count(); Assert.Equal(18, facetCount); }
public async void SearchProductProjectionsAndFilterByScopedPriceInChannel() { var channel = new Channel() { Id = "dbb5a6d0-2cbb-4855-bbe7-5cf58f434a82" }; var searchRequest = new SearchProductProjectionsCommand(); searchRequest.SetPriceCurrency("USD"); searchRequest.SetPriceChannel(channel.Id); searchRequest.Filter(p => p.Variants.Any(v => v.ScopedPrice.Value.CentAmount.Exists())); var httpApiCommandFactory = this.clientFixture.GetService <IHttpApiCommandFactory>(); var httpApiCommand = httpApiCommandFactory.Create(searchRequest); var content = await httpApiCommand.HttpRequestMessage.Content.ReadAsStringAsync(); Assert.Equal("filter=variants.scopedPrice.value.centAmount%3Aexists&priceCurrency=USD&priceChannel=dbb5a6d0-2cbb-4855-bbe7-5cf58f434a82&withTotal=false", content); }
public async void SearchProductProjectionsAndFilterFacetProductsWithCountsInSubCategory() { var category = new Category() { Id = "2fa96742-5e39-48b1-95fa-ed6a936cc67f" }; var searchRequest = new SearchProductProjectionsCommand(); searchRequest.FilteredFacet(p => p.Categories.Any(c => c.Id.Subtree(category.Id.valueOf())), isCountingProducts: true); searchRequest.Limit(0); searchRequest.Expand(p => p.Categories.ExpandAll()); var httpApiCommandFactory = this.clientFixture.GetService <IHttpApiCommandFactory>(); var httpApiCommand = httpApiCommandFactory.Create(searchRequest); var content = await httpApiCommand.HttpRequestMessage.Content.ReadAsStringAsync(); Assert.Equal("facet=categories.id%3A+subtree%28%222fa96742-5e39-48b1-95fa-ed6a936cc67f%22%29+counting+products&expand=categories%5B%2A%5D&limit=0&withTotal=false", content); }
/// <summary> /// check if all the products used in search tests are indexed /// </summary> /// <returns>true if the products used in search tests are indexed</returns> private bool CheckIfProductsIndexed() { if (AvailableProductType == null) { return(false); } var searchRequest = new SearchProductProjectionsCommand(); searchRequest.SetStaged(SearchForStaged); searchRequest.FilterQuery(p => p.ProductType.Id == AvailableProductType.Id.valueOf()); var searchResults = client.ExecuteAsync(searchRequest).Result; var indexed = searchResults.Count >= ExpectedProductsCount; if (indexed) { AvailableProducts = searchResults.Results; } return(indexed); }