on ‎2019 Jun 28 3:09 PM
Hi All,
I have craeted two discounts using discount model, while create dicount i have configure priority as well. I have added two discounts to product. But its taking latest discount model. what is the role priority in discount model & how it will work?
DiscountA 10% priority 1 && DiscountA 10% priority 0 DiscountB 5% priority 0 && DiscountB 5% priority 1
Discount B(latest) is applying every time
Regards, Labanu
Request clarification before answering.
I've tried your case as follows, it may be helpful to understand the working principle.
I defined two discounts with name tenOff and fiveOff which give 10% and 5% discounts respectively. In the first run, I gave priority value as 5 to fiveOff and 10 to tenOff.
And I define two discount rows for the product with described discounts. And 5% discount is applied.
For the second run I changed the priority of the fiveOff discount to 15 and after that, 10 % discount is applied for the product.
This is because DiscountRowMatchComparator class defined in Europe1PriceFactory which firstly subtracts priority values to compare them. Thus, the discount with least priority is applied.
protected class DiscountRowMatchComparator implements Comparator<AbstractDiscountRow> {
protected DiscountRowMatchComparator() {
}
public int compare(AbstractDiscountRow row1, AbstractDiscountRow row2) {
int product1 = row1.getDiscount().getPriority();
int product2 = row2.getDiscount().getPriority();
if (product1 != product2) {
return product1 - product2;
} else {
boolean c1Set = row1.getCurrency() != null;
boolean c2Set = row1.getCurrency() != null;
if (c1Set != c2Set) {
return c1Set ? -1 : 1;
} else {
return row1.getPK().compareTo(row2.getPK());
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.