This is an added feature to support discount offer percentage off with maximum amount price (screenshot field: Selection_131.png).

For example: admin create discount with 10% off and have maximum amount 10 USD.

Case A: customer has order total 200 USD.
Discount amount calculation: 10% * 200 = 20 USD.
Because discount amount higher than maximum amount, the discount amount for customer is 10 USD.

Case B: customer has order total 50 USD.
Discount amount calculation: 10% * 50 = 5 USD.
Because discount amount lower than maximum amount, the discount amount for customer is 5 USD.

Changes in code:
1. Add field commerce_percentage_maximum with type commerce_price and default value 0.
2. Add discount amount check on rules action apply percentage discount.

Comments

andre4s_y’s picture

Assigned: Unassigned » andre4s_y
StatusFileSize
new4.38 KB

I have created the patch.
Please help to review. :)

Thank you.

joelpittet’s picture

Status: Active » Needs review

Setting to needs review so testbot has a chance to review.

Though this likely should go this maybe? https://www.drupal.org/project/commerce_discount_extra

Status: Needs review » Needs work
andre4s_y’s picture

Status: Needs work » Needs review
StatusFileSize
new4.38 KB

Ups, my bad.
Update the patch: fix default value amount for commerce_percentage_maximum instance.

I have no idea whether this feature belong to discount or discount extra.
But IMO, this feature is usefull. :)

Status: Needs review » Needs work
andre4s_y’s picture

Status: Needs work » Needs review
StatusFileSize
new8.12 KB

Updates:

  1. fix PDOException for commerce_percentage_maximum_currency_code,
  2. add 2 test cases to check whether discount percentage with maximum amount works for order and product discounts.

Status: Needs review » Needs work
andre4s_y’s picture

Status: Needs work » Needs review
StatusFileSize
new8.28 KB

Update: fix create percentage offer discount and use maximum amount $20 for test cases.

Status: Needs review » Needs work
andre4s_y’s picture

Status: Needs work » Needs review
StatusFileSize
new8.33 KB

Update: change percentage maximum amount value to $0.2 at test cases.
Test cases use product amount $10.
If the discount percentage value is 5% and without maximum amount, the discount amount will be $0.5.
If the discount percentage value is 5% and with maximum amount $0.2, the discount amount will be $0.2.

Status: Needs review » Needs work
andre4s_y’s picture

Status: Needs work » Needs review
StatusFileSize
new8.42 KB

Update: fix product discount maximum amount calculation.

joelpittet’s picture

Status: Needs review » Needs work

As this feature could easily cause some confusion to customers, is there maybe a way you can present that maximum has been reached in the order on the component title maybe?

Sorry but I'm a bit hesitant on this feature.

Thanks for adding tests though, that is awesome!.

andre4s_y’s picture

You have 100% valid argument. This feature did create confusion to customer, I know it because I have already implemented. :D
Only marketing people found this useful. I will work on it, but of course the decision is yours. :)

joelpittet’s picture

Maybe worth adding to commerce_discount_extras, just a thought.

I can see where they may want to limit the discount but marketing needs to be a bit more explicit in what users are to expect. Which as you know isn't easy in commerce architecture to do in all cases but may be possible if thought through, just kinda hard and maybe messy/ugly.

Fine print incentives can turn off customers but Canadian tv/internet providers do it all the time!