Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Comment | File | Size | Author |
---|---|---|---|
#14 | implementing-usage-limiting-for-coupons-2862657-14.patch | 7.74 KB | SpartyDan |
#2 | coupon-usage-fields-2862657-2.patch | 3.29 KB | niko- |
Comments
Comment #2
niko- CreditAttribution: niko- as a volunteer commentedComment #3
mglamanNeeds base field changes. Makes sense as a promotion could have multiple one time coupons handed out to specific people
Comment #4
mglamanWe need #2763705: Implement a usage API first. And no need to store current usage on the coupon. I'll handle this once #2763705: Implement a usage API merged.
Comment #5
mglamanComment #6
bojanz CreditAttribution: bojanz at Centarro commentedThe usage API has landed and supports coupons. Usage is being tracked for attached coupons as of now.
That means that we need a usage_limit field + PromotionStorage::loadByCoupon() needs to start validating usage like loadValid() does.
Comment #7
mglamanUnassigning because I probably won't get to it before MidCamp
Comment #8
bojanz CreditAttribution: bojanz at Centarro commentedI'll do it.
But we need to decide on a relationship between coupon usage and promotion usage.
Two options:
A) We take both into account. If your coupon has 4 uses left, but the promotion doesn't, tough luck. This allows saying "Each coupon can be used once per person, but the entire promotion can only be used 50 times in total"
B) Only coupon usage is taken into account, promotion usage is ignored completely.
Pretty sure we want A?
Comment #9
niko- CreditAttribution: niko- as a volunteer commentedHi
+1 for A because if promo usage limit is 0 this variant equal to B, but if promo usage limit is more then 0, it can cover offten use case "Each coupon can be used once per person, but the entire promotion can only be used 50 times in total"
Comment #10
bojanz CreditAttribution: bojanz at Centarro commentedMatt and Ryan said the same, proceeding with that.
Comment #11
rajeshwari10 CreditAttribution: rajeshwari10 as a volunteer and at Valuebound commentedHi,
Any update regarding this issue?
Comment #12
Dom. CreditAttribution: Dom. as a volunteer and at ACINO commented+1 for update: can we help for this landing somehow ?
Comment #13
bojanz CreditAttribution: bojanz at Centarro commentedI ended up splitting most of the patch into another issue, and committing it in http://cgit.drupalcode.org/commerce/commit/?id=20e44ea
That was the needed API cleanup, we now need to add the usage_limit field to the Coupon entity, and start checking usage in Coupon::available().
Will return to this once I finish taxes.
Comment #14
SpartyDan CreditAttribution: SpartyDan as a volunteer commentedCompleted during sprint at DrupalCon Baltimore. @bojanz Thanks for guiding me on this.
PR on Github: https://github.com/drupalcommerce/commerce/pull/726
Posting patch as well.
Comment #15
mglamanReviewed the PR, committed a phpcs fix through the UI and all looks well.
Comment #16
Dom. CreditAttribution: Dom. as a volunteer and at ACINO commentedSorry, I can't get the patch #14 working:
- No update.php procedure needs me to delete all existing coupons before applying patch
- After done so and applying patch, I can't create new coupons because:
TypeError: Argument 1 passed to Drupal\commerce_promotion\PromotionUsage::getUsage() must implement interface Drupal\commerce_promotion\Entity\PromotionInterface, instance of Drupal\commerce_promotion\Entity\Coupon given
Did I miss something ?
Comment #17
mglamanRegarding #16, moving to needs work.
Comment #19
bojanz CreditAttribution: bojanz at Centarro commentedFixed bugs in the usage limit widget, added an update hook, committed. Thanks!