Skip to content

Commit

Permalink
Price range filter should use pricelists from search criteria (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-dudarev authored and tatarincev committed Feb 12, 2019
1 parent c3c32f0 commit 0015305
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public virtual SearchRequest BuildRequest(SearchCriteriaBase criteria)
Aggregations = _aggregationConverter?.GetAggregationRequests(productSearchCriteria, allFilters),
IsFuzzySearch = productSearchCriteria.IsFuzzySearch,
RawQuery = productSearchCriteria.RawQuery
};
};
}

return request;
Expand Down Expand Up @@ -162,7 +162,7 @@ protected virtual IList<IFilter> GetPermanentFilters(ProductSearchCriteria crite
if (criteria.PriceRange != null)
{
var range = criteria.PriceRange;
result.Add(FiltersHelper.CreatePriceRangeFilter(criteria.Currency, null, range.Lower, range.Upper, range.IncludeLower, range.IncludeUpper));
result.Add(FiltersHelper.CreatePriceRangeFilter(criteria.Currency, criteria.Pricelists, range.Lower, range.Upper, range.IncludeLower, range.IncludeUpper));
}

if (criteria.GeoDistanceFilter != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Globalization;
using System.Linq;
using VirtoCommerce.CatalogModule.Data.Search;
using VirtoCommerce.Domain.Catalog.Model.Search;
using VirtoCommerce.Domain.Commerce.Model.Search;
using VirtoCommerce.Domain.Search;
using Xunit;

namespace VirtoCommerce.CatalogModule.Test
{
[Trait("Category", "Unit")]
[CLSCompliant(false)]
public class ProductSearchRequestBuilderTests : BrowseFiltersTestBase
{
[Theory]
[InlineData(null, null, null, null, "price:")]
[InlineData(null, null, "", null, "price:")]
[InlineData("0", null, "", null, "price:(0 TO)")]
[InlineData(null, "100", "", null, "price:(TO 100)")]
[InlineData("0", "100", "", null, "price:(0 TO 100)")]
[InlineData("100", "200", "", null, "price:(100 TO 200)")]
[InlineData("100", "200", "USD", null, "price_usd:(100 TO 200)")]
[InlineData("100", "200", "USD", "1", "price_usd_1:(100 TO 200)")]
[InlineData("100", "200", "USD", "1;2", "(price_usd_1:(100 TO 200) OR (NOT(price_usd_1:(0 TO)) AND price_usd_2:(100 TO 200)))")]
[InlineData("100", "200", "USD", "1;2;3", "(price_usd_1:(100 TO 200) OR (NOT(price_usd_1:(0 TO)) AND (price_usd_2:(100 TO 200) OR (NOT(price_usd_2:(0 TO)) AND price_usd_3:(100 TO 200)))))")]
public void TestPriceRangeFilter(string lower, string upper, string currency, string pricelists, string expectedFilter)
{
var criteria = new ProductSearchCriteria
{
PriceRange = new NumericRange
{
Lower = ParseDecimal(lower),
Upper = ParseDecimal(upper),
},
Currency = currency,
Pricelists = pricelists?.Split(';'),
};

var termFilterBuilder = GetSearchRequestBuilder();

var searchRequest = termFilterBuilder.BuildRequest(criteria);

var priceFilter = (searchRequest.Filter as AndFilter)?.ChildFilters.Last().ToString();
Assert.Equal(expectedFilter, priceFilter);
}


private static decimal? ParseDecimal(string str)
{
decimal? result = null;

if (decimal.TryParse(str, NumberStyles.Number, CultureInfo.InvariantCulture, out var value))
{
result = value;
}

return result;
}

private static ISearchRequestBuilder GetSearchRequestBuilder()
{
return new ProductSearchRequestBuilder(null, GetTermFilterBuilder(), null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<Compile Include="BrowseFiltersTestBase.cs" />
<Compile Include="CatalogPropertyTest.cs" />
<Compile Include="FiltersHelperTests.cs" />
<Compile Include="ProductSearchRequestBuilderTests.cs" />
<Compile Include="PropertyDictionaryItemTest.cs" />
<Compile Include="OutlineTests.cs" />
<Compile Include="ProductAssociationSearchServiceTests.cs" />
Expand Down

0 comments on commit 0015305

Please sign in to comment.