Find products by field value

What would be the most efficient way to find products with a specific field value? We need to do it from a place where there’s no channel, country or anything like that.

Litium version: 8.12

Can try a search like

      var searchQuery = new SearchQuery
                {
                    Tags = new Dictionary<string, ISet<string>>
                    {
                       { "Id", new HashSet<string> { "value" }}
                    }
                };

                var searchResult = _productSearchService.SearchAsync(searchQuery, searchQuery.Tags).Result;
                var result = searchResult.Items.Value.Cast<ProductSearchResult>()
                    .Select(c => _productItemViewModelBuilder.Build(c.Item));

That was my first approach. It works fine as long as the call originates from a controller or somewhere else where channel and country are set (might be some other values as well) and can be accessed from RouteRequestLookupInfoAccessor and RequestModelAccessor. ProductSearchService.SearchAsync calls SearchQueryBuilder that needs these values when building the query.

In our case we need to call it from an EventBroker event and then we don’t have any channel or country. This makes SearchQueryBuilder to throw an error.

We can use DataService of course but I was hoping for an other way.

My code might differ with yours, but when I look in the BuildQuery function in ProductSearchServiceDecorator.cs I can pass a bool addDefaultQuery and set it to false.

Then atleast my code will skip all the channel context specific data, like channelSystemId.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.