From cd92351dd7bca272deec9af345eadf4d8f6904dc Mon Sep 17 00:00:00 2001 From: Justin Shreve Date: Thu, 9 Mar 2017 10:34:45 -0800 Subject: [PATCH] Fix direct property access for coupon amount. In 2.6, you could access the amount via $coupon->coupon_amount. Or legacy code incorrectly handles $coupon->amount instead. https://github.com/woocommerce/woocommerce/blob/77785833409869b33428fd0ce2c131ee3018df45/includes/class-wc-coupon.php#L102 This PR handles both since the RCs and betas allowed `->amount` and I don't want to break anything that may be accessing it that way.. To Test: * `phpunit --filter=test_coupon_backwards_compat_props_use_correct_getters` --- includes/legacy/class-wc-legacy-coupon.php | 2 ++ tests/unit-tests/coupon/data.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/includes/legacy/class-wc-legacy-coupon.php b/includes/legacy/class-wc-legacy-coupon.php index cd41f609116..9d982de331a 100644 --- a/includes/legacy/class-wc-legacy-coupon.php +++ b/includes/legacy/class-wc-legacy-coupon.php @@ -30,6 +30,7 @@ abstract class WC_Legacy_Coupon extends WC_Data { 'type', 'discount_type', 'amount', + 'coupon_amount', 'code', 'individual_use', 'product_ids', @@ -82,6 +83,7 @@ abstract class WC_Legacy_Coupon extends WC_Data { $value = $this->get_discount_type(); break; case 'amount' : + case 'coupon_amount' : $value = $this->get_amount(); break; case 'code' : diff --git a/tests/unit-tests/coupon/data.php b/tests/unit-tests/coupon/data.php index 5af592b8841..52819e32dfa 100644 --- a/tests/unit-tests/coupon/data.php +++ b/tests/unit-tests/coupon/data.php @@ -39,6 +39,7 @@ class WC_Tests_Coupon_Data extends WC_Unit_Test_Case { 'type', 'discount_type', 'amount', + 'coupon_amount', 'code', 'individual_use', 'product_ids', @@ -68,6 +69,7 @@ class WC_Tests_Coupon_Data extends WC_Unit_Test_Case { $this->assertEquals( $coupon->get_discount_type(), $coupon->type ); $this->assertEquals( $coupon->get_discount_type(), $coupon->discount_type ); $this->assertEquals( $coupon->get_amount(), $coupon->amount ); + $this->assertEquals( $coupon->get_amount(), $coupon->coupon_amount ); $this->assertEquals( $coupon->get_code(), $coupon->code ); $this->assertEquals( $coupon->get_individual_use(), ( 'yes' === $coupon->individual_use ? true : false ) ); $this->assertEquals( $coupon->get_product_ids(), $coupon->product_ids );