November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
I don't think you can filter it like that. Nested filter is a bit more tricky, you might need to create something like this
new NestedFilterExpression<BaseProduct, VariantStockDetails>(x => x.Stocks(), x => x.WarehouseCode.In(warehouses) & x.Quantity.GreaterThan(0)), client.Conventions);
disclaimer: I'm not a Find expert
I did the following:
var nestedFilter = new NestedFilterExpression<BaseProduct, VariantStockDetails>(x => x.Stock(), x => x.WarehouseCode.In(warehouses) & x.Quantity.GreaterThan(0), findClient.Conventions);
query = query.Filter(nestedFilter);
But receiving the MaxSerializationDepthExceededException.
You cannot do AND operation between DelegateFilterBuilder and FilterExpression, you could do using two DelegateFilterBuilder but not with a FilterExpression. Try following for the above scenario.
query
.Filter(x => x.Stock(), x => x.WarehouseCode.In(warehouses))
.Filter(x => x.Stock(), x => x.Quantity.GreaterThan(0));
When you use two filters like above, it works like default AND operation. If you need a complex operation you can use FilterBuilder and use FilterBuilder.Or / And function to build your operations.
Thanks for the suggestion, but it doesn’t resolve the issue in this specific scenario.
Consider this data sample:
"Stock$$nested": [
{
"Quantity$$number": 0,
"___types": [
"XXX.Foundation.Domain.Catalog.Variants.VariantStockDetails",
"System.Object"
],
"WarehouseCode$$string": "100",
"$type": "XXX.Foundation.Domain.Catalog.Variants.VariantStockDetails, XXX.Foundation.Domain"
},
{
"Quantity$$number": 36,
"___types": [
"XXX.Foundation.Domain.Catalog.Variants.VariantStockDetails",
"System.Object"
],
"WarehouseCode$$string": "106",
"$type": "XXX.Foundation.Domain.Catalog.Variants.VariantStockDetails, XXX.Foundation.Domain"
}
]
In this example, let’s say my list of warehouses only includes "100". With your proposed approach, the product is still included because there exists another warehouse ("106") with "Quantity > 0". However, the expected outcome would be to exclude this product since the specified warehouse ("100") has "Quantity = 0".
probably
public static FilterExpression<Inventory> MatchSomething(this BaseProduct value,
IList<string> warehouses)
{
var client = ServiceLocator.Current.GetInstance<IClient>();
new NestedFilterExpression<BaseProduct, VariantStockDetails>(x => x.Stocks(), x => x.WarehouseCode.In(warehouses) & x.Quantity.GreaterThan(0)), client.Conventions);
}
then
.Filter(x => x.MatchSomething(warehouses));
When you use two filters this is how internal EPiServer Find code resolves it to exactly what you are trying to do.
public static ITypeSearch<TSource> Filter<TSource>(this ITypeSearch<TSource> search, Filter filter)
{
search.ValidateNotNullArgument("search");
return new Search<TSource, IQuery>(search, delegate (ISearchContext context)
{
ApplyFilter(context, filter, (Filter existingFilter, Filter newFilter) => existingFilter & newFilter);
});
}
May be I am suggesting something wrong but expected result is as above.
Sorry, it should be
new NestedFilterExpression<BaseProduct, VariantStockDetails>(x => x.Stocks(), y => y.WarehouseCode.In(warehouses) & y.Quantity.GreaterThan(0)), client.Conventions);
Here is what I would suggest after understanding the problem.
Index another property in Stock() that is either string or boolean. Something like IsZeroQuantity or index the QuantityString as string. Once you do that try following code.
query.Filter(x => x.Stock(), x => x.WarehouseCode.In(warehouses) & x.IsZeroQuantity.Match(false));
query.Filter(x => x.Stock(), x => x.WarehouseCode.In(warehouses) & x.QuantityString.Match("0"));
In both of these cases you are trying to use AND operation between two DelegateFilterBuilder which will function correctly vs DelegateFilterBuilder & FilterExpression. Let us know if it works.
Similar to the issue described in "Filter Item search results on inventory?", I am trying to filter products based on whether any related variants are in stock. I attempted the following filter, where
warehouses
is a list of strings:The
Stock()
method is an extension method onProducts
that returns a list of the following type:I have also attempted to include this in our find initialization module:
I can see entries in the index like this:
However, it appears that the filter isn't being applied correctly, as I am still receiving results where none of the
WarehouseCode
s on stocks on the products entries matches any of the values in the providedwarehouses
list.