Optional PurchaseAmount in custom promotion

Member since: 2016

Hi all! 

I'm working on a custom promotion and the condition consists of 

public virtual PurchaseAmount Amount { get; set; }
public virtual IList Items { get; set; }

I would like the amount to be optional. The idea behind the promotion is "Buy from [specific category?] for at least [amount or optional = 0]...", but it doesn't look like the PurchaseAmount can be made optional, I can't save the promotion if is either not set or 0. 

I could always just make a decimal/int for it, but then I lose the wonderful currency-amount-list that PurchaseAmount gives me.

Is it possible to somehow make it optional?


Joel Yourstone

#172390 Edited, Dec 01, 2016 17:56
  • Member since: 2016

    Looks like there is a validator for PurchaseAmount. I tried to put a validator for the promotion, but it didn't override the PurchaseAmount's validator. 

    My current workaround is not using PurchaseAmount, but using

    public virtual IList<Money> Amount { get; set; }

    It renders to the wonderful currency-amount-list I thought I'd lose :) However there is one drawback: I cannot use


    It is a pretty minor drawback though, that check can easily be done without it.

    #172400 Dec 01, 2016 22:08
  • Member since: 2012

    You could workaround by creating new extension like this:

    public void CanBeFulfilled(this IList<Money> amount, Currency orderCurrency)
        return amount != null && amounts.Any(a => a.Amount > 0 && a.Currency == orderCurrency);

    /Son Do

    #172407 Edited, Dec 02, 2016 6:03
  • Member since: 2016

    True, but then this would be overridden for all promotions using PurchaseAmount, wouldn't it? I only want my custom promotion type to allow empty values in PurchaseAmount.


    Joel Yourstone

    #172415 Dec 02, 2016 10:59
  • Member since: 2012

    Hi Joel,

    It won't override PurchaseAmount.CanBeFulfilled, you could verify this :)

    #172418 Edited, Dec 02, 2016 11:18
  • Member since: 2011

    CanBeFulfilled is just a shortcut to check if the order is not qualified for the promotions. So if you are using PurchaseAmount, it checks if the currency of the order can satisfy the conditions in PurchaseAmount.

    The reason you can't save the promotions with PurchaseAmount which has amount = 0 was because there is a validator (PurchaseAmountValidator) validates that. This validator however can't be disabled. Simply speaking, PurchaseAmount = IList<Money> + some validation.  So in your requirements, switching to IList<Money> is the way to go. 

    #172419 Dec 02, 2016 11:24
  • Member since: 2016

    Yeah I can easily do that check on my own, in the promotion processor. Thanks Son and Quan!

    #172423 Dec 02, 2016 12:29