From d82e7e9a45f5dbdd5e9fc5708b95f9691021a7cd Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Fri, 24 Mar 2017 13:50:20 -0500 Subject: [PATCH] Issue #2863830 by mglaman: Disabled coupons still apply --- modules/promotion/src/CouponStorage.php | 2 +- modules/promotion/tests/src/Kernel/CouponStorageTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/promotion/src/CouponStorage.php b/modules/promotion/src/CouponStorage.php index e1f1fe8..2ad3692 100644 --- a/modules/promotion/src/CouponStorage.php +++ b/modules/promotion/src/CouponStorage.php @@ -13,7 +13,7 @@ class CouponStorage extends CommerceContentEntityStorage implements CouponStorag * {@inheritdoc} */ public function loadByCode($code) { - $coupons = $this->loadByProperties(['code' => $code]); + $coupons = $this->loadByProperties(['code' => $code, 'status' => TRUE]); return reset($coupons); } diff --git a/modules/promotion/tests/src/Kernel/CouponStorageTest.php b/modules/promotion/tests/src/Kernel/CouponStorageTest.php index 389e5a7..9c3c266 100644 --- a/modules/promotion/tests/src/Kernel/CouponStorageTest.php +++ b/modules/promotion/tests/src/Kernel/CouponStorageTest.php @@ -66,6 +66,16 @@ public function testLoadByCode() { $coupon_loaded = $this->couponStorage->loadByCode($coupon_code); $this->assertEquals($coupon->id(), $coupon_loaded->id()); + + $coupon_code = $this->randomMachineName(); + $coupon = Coupon::create([ + 'code' => $coupon_code, + 'status' => FALSE, + ]); + $coupon->save(); + + $coupon_loaded = $this->couponStorage->loadByCode($coupon_code); + $this->assertEmpty($coupon_loaded); } }