Commit 14b4ec78 authored by Jonathan Sacksick's avatar Jonathan Sacksick
Browse files

Revert "Issue #3278227 by jsacksick: Total per customer at the coupon level is...

Revert "Issue #3278227 by jsacksick: Total per customer at the coupon level is ignored for unknown customers."

This reverts commit 129ad838.
parent 53a71647
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -233,13 +233,11 @@ class Coupon extends CommerceContentEntityBase implements CouponInterface {
    if ($usage_limit && $usage_limit <= $usage->loadByCoupon($this)) {
      return FALSE;
    }

    // Only check customer usage when email address is known.
    if ($usage_limit_customer) {
      // Coupon cannot apply to orders without email addresses because of the
      // customer limit.
      if (!$email = $order->getEmail()) {
        return FALSE;
      }
      if ($usage_limit_customer <= $usage->loadByCoupon($this, $email)) {
      $email = $order->getEmail();
      if ($email && $usage_limit_customer <= $usage->loadByCoupon($this, $email)) {
        return FALSE;
      }
    }
+3 −7
Original line number Diff line number Diff line
@@ -174,20 +174,16 @@ class CouponTest extends OrderKernelTestBase {
    $this->assertFalse($coupon->available($this->order));

    // Test limit coupon usage by customer.
    $email = $this->order->getEmail();
    // Ensure that the usage limit per customer applies when the order email is
    // not known.
    $this->order->set('mail', NULL);
    $coupon->setCustomerUsageLimit(1);
    $coupon->setUsageLimit(0);
    $coupon->save();
    $coupon = $this->reloadEntity($coupon);
    $this->assertFalse($coupon->available($this->order));

    $this->order->setEmail($email);
    $this->assertFalse($coupon->available($this->order));

    $this->order->setEmail('another@example.com');
    $this->order->setRefreshState(Order::REFRESH_SKIP);
    $this->order->save();
    $this->order = $this->reloadEntity($this->order);
    $this->assertTrue($coupon->available($this->order));

    \Drupal::service('commerce_promotion.usage')->register($this->order, $promotion, $coupon);