Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Optional PurchaseAmount in custom promotion

Vote:
 

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?

Regards,

Joel Yourstone

#172390
Edited, Dec 01, 2016 17:56
Vote:
 

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

PuchaseAmount.CanBeFulfilled(context.OrderGroup.Currency)

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

#172400
Dec 01, 2016 22:08
Vote:
 

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);
}

Regards,
/Son Do

#172407
Edited, Dec 02, 2016 6:03
Vote:
 

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.

Regards,

Joel Yourstone

#172415
Dec 02, 2016 10:59
Vote:
 

Hi Joel,

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

#172418
Edited, Dec 02, 2016 11:18
Vote:
 

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
Vote:
 

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

#172423
Dec 02, 2016 12:29
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.