Negation in property filter on order list

Hi,

In the order list, in BackOffice, we can filter orders by loads of different parameters. One, in particular, is very interesting. The Property-filter.

But it seems that it can only filter on properties that are present on an order. I can’t find orders that do not have a given property.

Say I have 10 orders. Two of which has the property “hasSpecialMeaning” with the value “true”. The remaining 8 orders does not have that property. At all.

Using the filter, hasSpecialMeaning:true, I can find the two orders. No problems. But there is seemingly no way to find the other 8 orders. The ones that lack the hasSpecialMeaning property.

Essentially, I would like something like this: “hasSpecialMeaning:!true” or “!hasSpecialMeaning:true” that would give every order that either has no property of that name or a property with a value different from “true”.

Maybe I missed something in the documentation or maybe this is not supported?

I’m using Umbraco Commerce v15.3.6

That’s a nice suggestion. I don’t think we actually have this at the moment, but I do like the idea. I also like the hasSpecialMeaning:!true syntax too so I’m sure it wouldn’t take much for us to incorporate.

I’ll add it to our backlog to take a look at.

In the meantime, although we don’t have much docs, these filters are pluggable so you could write your own. Here is the code for the Order Properties filter which you might be able to modify.

[AdvancedFilter("props", Group = "order")]
public class OrderPropertiesAdvancedFilter : OrderAdvancedFilterBase
{
    public override bool CanApply(string value)
    {
        return !string.IsNullOrWhiteSpace(value);
    }

    public override IQuerySpecification<OrderReadOnly> Apply(IQuerySpecification<OrderReadOnly> query, IOrderQuerySpecificationFactory @where, string value)
    {
        var props = value.Split(new[]{','}, StringSplitOptions.RemoveEmptyEntries)
            .Select(x => x.Trim())
            .Where(x => !string.IsNullOrWhiteSpace(x))
            .Select(x => x.Split(':'))
            .ToList();

        var subQuery = props.Where(x => x.Length == 2).Aggregate<string[], IQuerySpecification<OrderReadOnly>>(null, (current, prop) => current == null
            ? @where.HasProperty(prop[0], prop[1])
            : current.Or(@where.HasProperty(prop[0], prop[1])));

        return subQuery == null
            ? query
            : query.And(subQuery);
    }
}

You can add .Not() to the HasProperty() call to negate it, so if you detect if prop[1] starts with ! you can just append the .Not().

Hopefully this helps in the meantime.

Hi @mattbrailsford

That would be great to see implemented!

I will take a look at the workaround in the meantime.

Thanks!