Support from Acquia helps fund testing for Drupal Acquia logo

Comments

niko- created an issue. See original summary.

niko-’s picture

mglaman’s picture

Status: Active » Needs work

Needs base field changes. Makes sense as a promotion could have multiple one time coupons handed out to specific people

mglaman’s picture

Assigned: Unassigned » mglaman
Status: Needs work » Postponed

We 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.

mglaman’s picture

Issue tags: +MidCamp2017
bojanz’s picture

Title: coupons needs current_usage and usage limit fields » Implement usage limiting for coupons
Status: Postponed » Active

The 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.

mglaman’s picture

Assigned: mglaman » Unassigned

Unassigning because I probably won't get to it before MidCamp

bojanz’s picture

Assigned: Unassigned » bojanz

I'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?

niko-’s picture

Hi

+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"

bojanz’s picture

Matt and Ryan said the same, proceeding with that.

rajeshwari10’s picture

Hi,

Any update regarding this issue?

Dom.’s picture

+1 for update: can we help for this landing somehow ?

bojanz’s picture

I 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.

SpartyDan’s picture

Assigned: bojanz » Unassigned
Status: Active » Needs review
Issue tags: -MidCamp2017
FileSize
7.74 KB

Completed 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.

mglaman’s picture

Reviewed the PR, committed a phpcs fix through the UI and all looks well.

Dom.’s picture

Sorry, 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 ?

mglaman’s picture

Status: Needs review » Needs work

Regarding #16, moving to needs work.

  • bojanz committed 2fd5fd7 on 8.x-2.x authored by SpartyDan
    Issue #2862657 by niko-, SpartyDan, bojanz: Implement usage limiting for...
bojanz’s picture

Status: Needs work » Fixed

Fixed bugs in the usage limit widget, added an update hook, committed. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.