コード例 #1
0
        public virtual FiltersContainer GetTermFilters(ProductSearchCriteria criteria)
        {
            var result = new FiltersContainer();

            var terms = criteria.GetTerms();

            if (terms.Any())
            {
                var browseFilters = _browseFilterService.GetBrowseFilters(criteria);

                var filtersAndValues = browseFilters
                                       ?.Select(f => new { Filter = f, Values = f.GetValues() })
                                       .ToList();

                foreach (var term in terms)
                {
                    var browseFilter = browseFilters?.SingleOrDefault(x => x.Key.EqualsInvariant(term.Key));

                    // Handle special filter term with a key = "tags", it contains just values and we need to determine which filter to use
                    if (browseFilter == null && term.Key == "tags")
                    {
                        foreach (var termValue in term.Values)
                        {
                            // Try to find filter by value
                            var filterAndValues = filtersAndValues?.FirstOrDefault(x => x.Values?.Any(v => v.Id.Equals(termValue)) == true);
                            if (filterAndValues != null)
                            {
                                var filter = ConvertBrowseFilter(filterAndValues.Filter, term.Values, criteria);
                                result.PermanentFilters.Add(filter);
                            }
                            else
                            {
                                // Unknown term values should produce empty result
                                result.PermanentFilters.Add(new IdsFilter {
                                    Values = new[] { string.Empty }
                                });
                            }
                        }
                    }
                    else if (browseFilter != null) // Predefined filter
                    {
                        var filter = ConvertBrowseFilter(browseFilter, term.Values, criteria);
                        result.RemovableFilters.Add(new KeyValuePair <string, IFilter>(browseFilter.Key, filter));
                    }
                    else // Custom term
                    {
                        var filter = FiltersHelper.CreateTermFilter(term.Key, term.Values);
                        result.PermanentFilters.Add(filter);
                    }
                }
            }

            return(result);
        }
コード例 #2
0
        protected virtual FiltersContainer GetAllFilters(ProductSearchCriteria criteria)
        {
            var permanentFilters = GetPermanentFilters(criteria);
            var termFilters      = _termFilterBuilder.GetTermFilters(criteria);

            var result = new FiltersContainer
            {
                PermanentFilters = permanentFilters.Concat(termFilters.PermanentFilters).ToList(),
                RemovableFilters = termFilters.RemovableFilters,
            };

            return(result);
        }
コード例 #3
0
 protected virtual IList <IFilter> GetFilters(FiltersContainer allFilters)
 {
     return(allFilters.GetFiltersExceptSpecified(null));
 }
コード例 #4
0
        public IList <AggregationRequest> GetAggregationRequests(ProductSearchCriteria criteria, FiltersContainer allFilters)
        {
            var result = new List <AggregationRequest>();

            var browseFilters = _browseFilterService.GetBrowseFilters(criteria);

            if (browseFilters != null)
            {
                foreach (var filter in browseFilters)
                {
                    var existingFilters = allFilters.GetFiltersExceptSpecified(filter.Key);

                    var attributeFilter  = filter as AttributeFilter;
                    var priceRangeFilter = filter as PriceRangeFilter;
                    var rangeFilter      = filter as RangeFilter;

                    AggregationRequest         aggregationRequest  = null;
                    IList <AggregationRequest> aggregationRequests = null;

                    if (attributeFilter != null)
                    {
                        aggregationRequest = GetAttributeFilterAggregationRequest(attributeFilter, existingFilters);
                    }
                    else if (rangeFilter != null)
                    {
                        aggregationRequests = GetRangeFilterAggregationRequests(rangeFilter, existingFilters);
                    }
                    else if (priceRangeFilter != null && priceRangeFilter.Currency.EqualsInvariant(criteria.Currency))
                    {
                        aggregationRequests = GetPriceRangeFilterAggregationRequests(priceRangeFilter, criteria, existingFilters);
                    }

                    if (aggregationRequest != null)
                    {
                        result.Add(aggregationRequest);
                    }

                    if (aggregationRequests != null)
                    {
                        result.AddRange(aggregationRequests.Where(f => f != null));
                    }
                }
            }

            return(result);
        }