public void GetProductProjectionSearchParametersBuilderFromFactory() { ProductProjectionSearchParameters productAdditionalParameters = new ProductProjectionSearchParameters(); IParametersBuilderFactory <ISearchParametersBuilder> parametersBuilderFactory = this.clientFixture.GetService <IParametersBuilderFactory <ISearchParametersBuilder> >(); ISearchParametersBuilder parametersBuilder = parametersBuilderFactory.GetParameterBuilder(productAdditionalParameters); Assert.Equal(typeof(ProductProjectionSearchParametersBuilder), parametersBuilder.GetType()); }
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 List <KeyValuePair <string, string> > GetSearchParameters <T>(ISearchParameters <T> searchParameters) { List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >(); ProductProjectionSearchParameters productProjectionSearchParameters = searchParameters as ProductProjectionSearchParameters; if (productProjectionSearchParameters == null) { return(parameters); } parameters.AddRange(AddTextLanguageParameter(productProjectionSearchParameters)); parameters.AddRange(AddParameters(productProjectionSearchParameters.Filter, "filter")); parameters.AddRange(AddParameters(productProjectionSearchParameters.FilterQuery, "filter.query")); parameters.AddRange(AddParameters(productProjectionSearchParameters.FilterFacets, "filter.facets")); parameters.AddRange(AddParameters(productProjectionSearchParameters.Facets, "facet")); parameters.AddRange(AddParameters(productProjectionSearchParameters.Sort, "sort")); if (productProjectionSearchParameters.Fuzzy != null) { parameters.Add(new KeyValuePair <string, string>("fuzzy", productProjectionSearchParameters.Fuzzy.ToString())); } if (productProjectionSearchParameters.FuzzyLevel != null) { parameters.Add(new KeyValuePair <string, string>("fuzzyLevel", productProjectionSearchParameters.FuzzyLevel.ToString())); } if (productProjectionSearchParameters.Limit != null) { parameters.Add(new KeyValuePair <string, string>("limit", productProjectionSearchParameters.Limit.ToString())); } if (productProjectionSearchParameters.Offset != null) { parameters.Add(new KeyValuePair <string, string>("offset", productProjectionSearchParameters.Offset.ToString())); } if (productProjectionSearchParameters.MarkMatchingVariants != null) { parameters.Add(new KeyValuePair <string, string>("markMatchingVariants", productProjectionSearchParameters.MarkMatchingVariants.ToString())); } return(parameters); }
private static List <KeyValuePair <string, string> > AddTextLanguageParameter(ProductProjectionSearchParameters productProjectionSearchParameters) { List <KeyValuePair <string, string> > queryStringParameters = new List <KeyValuePair <string, string> >(); if (productProjectionSearchParameters?.Text != null) { queryStringParameters.Add(new KeyValuePair <string, string>($"text.{productProjectionSearchParameters.Text.Language}", productProjectionSearchParameters.Text.Term)); } return(queryStringParameters); }
public List <KeyValuePair <string, string> > GetSearchParameters <T>(ISearchParameters <T> searchParameters) { List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >(); ProductProjectionSearchParameters productProjectionSearchParameters = searchParameters as ProductProjectionSearchParameters; if (productProjectionSearchParameters == null) { return(parameters); } parameters.AddRange(AddTextLanguageParameter(productProjectionSearchParameters)); parameters.AddRange(AddParameters(productProjectionSearchParameters.Filter, "filter")); parameters.AddRange(AddParameters(productProjectionSearchParameters.FilterQuery, "filter.query")); parameters.AddRange(AddParameters(productProjectionSearchParameters.FilterFacets, "filter.facets")); parameters.AddRange(AddParameters(productProjectionSearchParameters.Facets, "facet")); parameters.AddRange(AddParameters(productProjectionSearchParameters.Sort, "sort")); parameters.AddRange(AddParameters(productProjectionSearchParameters.Expand, "expand")); if (productProjectionSearchParameters.Fuzzy != null) { parameters.Add(new KeyValuePair <string, string>("fuzzy", productProjectionSearchParameters.Fuzzy.ToString())); } if (productProjectionSearchParameters.FuzzyLevel != null) { parameters.Add(new KeyValuePair <string, string>("fuzzyLevel", productProjectionSearchParameters.FuzzyLevel.ToString())); } if (productProjectionSearchParameters.Limit != null) { parameters.Add(new KeyValuePair <string, string>("limit", productProjectionSearchParameters.Limit.ToString())); } if (productProjectionSearchParameters.Offset != null) { parameters.Add(new KeyValuePair <string, string>("offset", productProjectionSearchParameters.Offset.ToString())); } if (productProjectionSearchParameters.MarkMatchingVariants != null) { parameters.Add(new KeyValuePair <string, string>("markMatchingVariants", productProjectionSearchParameters.MarkMatchingVariants.ToString())); } if (productProjectionSearchParameters.PriceCurrency != null) { parameters.Add(new KeyValuePair <string, string>("priceCurrency", productProjectionSearchParameters.PriceCurrency)); } if (productProjectionSearchParameters.PriceCountry != null) { parameters.Add(new KeyValuePair <string, string>("priceCountry", productProjectionSearchParameters.PriceCountry)); } if (productProjectionSearchParameters.PriceCustomerGroup != null) { parameters.Add(new KeyValuePair <string, string>("priceCustomerGroup", productProjectionSearchParameters.PriceCustomerGroup)); } if (productProjectionSearchParameters.PriceChannel != null) { parameters.Add(new KeyValuePair <string, string>("priceChannel", productProjectionSearchParameters.PriceChannel)); } if (productProjectionSearchParameters.StoreProjection != null) { parameters.Add(new KeyValuePair <string, string>("storeProjection", productProjectionSearchParameters.StoreProjection)); } if (productProjectionSearchParameters.LocaleProjection != null) { parameters.Add(new KeyValuePair <string, string>("localeProjection", productProjectionSearchParameters.LocaleProjection)); } var withTotal = productProjectionSearchParameters.WithTotal ? "true" : "false"; parameters.Add(new KeyValuePair <string, string>("withTotal", withTotal)); return(parameters); }