示例#1
0
        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);
        }
示例#2
0
        public void GetProductProjectionsFilterByCentAmountRange()
        {
            IClient commerceToolsClient = this.productFixture.GetService <IClient>();
            SearchProductProjectionsCommand searchProductProjectionsCommand = new SearchProductProjectionsCommand();

            searchProductProjectionsCommand.Filter(p =>
                                                   p.Variants.Any(v => v.Price.Value.CentAmount.Range(1, 3000)));
            PagedQueryResult <ProductProjection> results = commerceToolsClient.ExecuteAsync(searchProductProjectionsCommand).Result;

            Assert.Equal(19, results.Count);
        }
        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);
        }