Loading modules/promotion/src/Entity/Coupon.php +4 −6 Original line number Diff line number Diff line Loading @@ -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; } } Loading modules/promotion/tests/src/Kernel/Entity/CouponTest.php +3 −7 Original line number Diff line number Diff line Loading @@ -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); Loading Loading
modules/promotion/src/Entity/Coupon.php +4 −6 Original line number Diff line number Diff line Loading @@ -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; } } Loading
modules/promotion/tests/src/Kernel/Entity/CouponTest.php +3 −7 Original line number Diff line number Diff line Loading @@ -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); Loading