Add new percentage off offer type with quantity restriction

Created on 30 August 2024, 18 days ago
Updated 13 September 2024, 3 days ago

When using the promotion offer type "Percentage off each matching product", there is no way to limit the quantity of products that can receive this promotion. If you attempt to make a "100% percentage off" coupon for a "specific product variation", a user could theoretically purchase 10,000 copies of the product for free.

When discussing this in Slack, @rszrama suggested a "Buy X, Get Y" approach instead, but that always assumes that an X exists - in our case, we only ever have a Y, and we can't set the quantity to "1", because that disables the coupon. @travis-bradbury noted that a similar use case is already noted in the Drupal Commerce docs here.

@rszrama ends with "Well, main issue is order item adjustments are against the unit price, so it's not quite so simple ... under the current architecture, you'd need an order level adjustment equivalent to the single quantity amount you intend to discount, so really the "Fixed amount off the order subtotal" promotion but with the fixed amount derived from the unit price of a single order item vs. a static amount set in the UI. Most likely solution would be a new offer type plugin; wouldn't be a bad idea for core inclusion."

Feature request
Status

Needs review

Version

3.0

Component

Promotions

Created by

🇮🇳India vipin.j

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @vipin.j
  • Merge request !325Add new promotion offer type plugin → (Open) created by vipin.j
  • Pipeline finished with Success
    17 days ago
    Total: 487s
    #269075
  • Status changed to Needs review 17 days ago
  • Status changed to Needs work 17 days ago
  • 🇳🇴Norway zaporylie

    What I am missing here is a slightly better explanation of why we need this feature in the Commerce Core. Based on the current state of MR it seems to address specific project requirements - unset($form['display_inclusive']);, '#max' => 1000,, etc.

    Should it only be limited to a percentage off?

  • 🇮🇳India vipin.j

    @zaporylie, The current available offer plugins have limitation that a site administrator cannot restrict its users to redeem a coupon with percentage discount to a fixed quantity for an order item in checkout.

    For example; suppose you got a coupon with 100% discount for a product variation. now, the site admin expects this coupon to redeem only for 1N quantity for the same order item. but, in fact with 100% discount you can even buy 10N quantity of that and place an order, and the system won't blocks you. Also, we can not go with the "Fixed amount off..." offer plugin too, because the product price may change after the coupon has been bought by the customer. The same conversation we had in #slack discussion

    unset($form['display_inclusive']);: This was done because if you calculates a certain percentage of discount with a given coupon, and then update the unit price of the order item in the order checkout, then in practically that doesn't make sense with quantity validation. as the unit price has now been updated to the discounted amount and if you block that amount for say 1N quantity, then the rest of the quantity will also get multiplied by the same amount. So, basically with a configured number of quantity validation when a coupon gets redeemed than the calculated discount must only be applied to that quantity only and the rest of the quantity should then multiplied to the original unit price.

    '#max' => 1000,: We just kept it to the max number, because with our use case a teacher can buy 100 coupons too for a digital product, that's it.

  • 🇺🇸United States Morbus Iff

    Some code comments:

    1. I'd remove the #max entirely.
    2. I think I'd change the promotion label to "Percentage off each matching product with fixed quantity". Or potentially shorter: "Percentage off each matching fixed quantity product".
    3. Same "to" to "with" change for the file documentation header.
    4. We're likely gonna need some tests.
    5. Too much closing bracket indent spacing in defaultConfiguration().
    6. I think I'd labeled "Max quantity" to just "Quantity". Maximum is implied.
    7. We can likely get rid of the #description too - it's all implied as part of the promotion label.
    8. The "Quantity must be a positive number." message could be replaced with "Quantity must be higher than or equal to 1." which is a similar error that is tested against in AddToCartFormTest.php.
  • Pipeline finished with Failed
    10 days ago
    Total: 363s
    #275649
  • Status changed to Needs review 3 days ago
Production build 0.71.5 2024