Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Johannes Lantz 156 posts 838 karma points c-trib
    Dec 09, 2022 @ 09:37
    Johannes Lantz
    0

    Backoffice advanced filter - Discount

    Hi!

    I was curious if it's possible to use the backoffice advanced filter to find orders with discount codes?

    //Johannes

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Dec 09, 2022 @ 10:36
    Matt Brailsford
    100

    Hi Johannes,

    Hmm, good question. I don't think we have one OOTB, but I think it should be possible.

    The advanced filter view is pluggable and so long as we have a filter option on our order query specification (which we have a Redeems method to check if it discount / gift card code is redeemed by an order), you can implement your own.

    I don't think I got round to documenting those, but if you create a class that extends OrderAdvancedFilterBase with an AdvancedFilterAttribute to define it's meta data (like so)

    [AdvancedFilter("discountCode", "Discount Code", "A discount code to search on", Group = "Order")]
    public class OrderDiscountCodeAdvancedFilter : OrderAdvancedFilterBase
    {
        public override bool CanApply(string value)
        {
            return !string.IsNullOrWhiteSpace(value);
        }
    
        public override IQuerySpecification<OrderReadOnly> Apply(IQuerySpecification<OrderReadOnly> query, IOrderQuerySpecificationFactory @where, string value)
        {
            return query.And(where.Redeems(value));
        }
    }
    

    in your IUmbracoBuilder or IVendrBuilder you can call

    builder.WithOrderAdvancedFilters()
        .Add<OrderDiscountCodeAdvancedFilter>();
    

    I think this should do it.

  • Johannes Lantz 156 posts 838 karma points c-trib
    Dec 09, 2022 @ 11:00
    Johannes Lantz
    0

    Thank you so much Matt! That works wonder!

Please Sign in or register to post replies

Write your reply to:

Draft