|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Linq;
|
| 4 | +using System.Text.RegularExpressions; |
4 | 5 | using System.Threading;
|
5 | 6 | using System.Threading.Tasks;
|
6 | 7 | using VirtoCommerce.CatalogModule.Core;
|
@@ -278,11 +279,36 @@ protected virtual Aggregation GetRangeAggregation(RangeFilter rangeFilter, IList
|
278 | 279 |
|
279 | 280 | protected virtual Aggregation GetPriceRangeAggregation(PriceRangeFilter priceRangeFilter, IList<AggregationResponse> aggregationResponses)
|
280 | 281 | {
|
| 282 | + var rangeAggregations = new List<AggregationResponse>(); |
| 283 | + |
| 284 | + // Merge All Virtual Price Ranges in rangeAggregations |
| 285 | + var priceFieldName = "price"; |
| 286 | + |
| 287 | + var priceValues = aggregationResponses.Where(a => a.Id.StartsWith(priceFieldName)).SelectMany(x => x.Values).ToArray(); |
| 288 | + |
| 289 | + if (priceValues.Length == 0) |
| 290 | + { |
| 291 | + return null; |
| 292 | + } |
| 293 | + |
| 294 | + var matchIdRegEx = new Regex(@"^(?<left>[0-9*]+)-(?<right>[0-9*]+)$", RegexOptions.IgnoreCase | RegexOptions.Compiled); |
| 295 | + |
| 296 | + rangeAggregations.AddRange(priceValues.Select(x => |
| 297 | + { |
| 298 | + var matchId = matchIdRegEx.Match(x.Id); |
| 299 | + var left = matchId.Groups["left"].Value; |
| 300 | + var right = matchId.Groups["right"].Value; |
| 301 | + x.Id = left == "*" ? $@"under-{right}" : x.Id; |
| 302 | + x.Id = right == "*" ? $@"over-{left}" : x.Id; |
| 303 | + return new AggregationResponse { Id = $@"{priceFieldName}-{x.Id}", Values = new List<AggregationResponseValue> { x } }; |
| 304 | + })); |
| 305 | + |
| 306 | + |
281 | 307 | var result = new Aggregation
|
282 | 308 | {
|
283 | 309 | AggregationType = "pricerange",
|
284 | 310 | Field = priceRangeFilter.Key,
|
285 |
| - Items = GetRangeAggregationItems(priceRangeFilter.Key, priceRangeFilter.Values, aggregationResponses).ToArray(), |
| 311 | + Items = GetRangeAggregationItems(priceRangeFilter.Key, priceRangeFilter.Values, rangeAggregations).ToArray(), |
286 | 312 | };
|
287 | 313 |
|
288 | 314 |
|
|
0 commit comments