From ebf212203e513c6191093728008c08573d4efa20 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Fri, 22 Oct 2021 19:50:11 -0400 Subject: [PATCH] feat: applied coupon description field added --- includes/type/object/class-cart-type.php | 8 ++++++++ tests/wpunit/CartMutationsTest.php | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/includes/type/object/class-cart-type.php b/includes/type/object/class-cart-type.php index 073bac956..bfa171ddc 100644 --- a/includes/type/object/class-cart-type.php +++ b/includes/type/object/class-cart-type.php @@ -618,6 +618,14 @@ public static function register_applied_coupon() { return \wc_graphql_price( $tax ); }, ), + 'description' => array( + 'type' => 'String', + 'description' => __( 'Description of applied coupon', 'wp-graphql-woocommerce' ), + 'resolve' => function( $source, array $args ) { + $coupon = new \WC_Coupon( $source ); + return $coupon->get_description(); + }, + ), ), ) ); diff --git a/tests/wpunit/CartMutationsTest.php b/tests/wpunit/CartMutationsTest.php index 79e4a2f2b..70719e265 100644 --- a/tests/wpunit/CartMutationsTest.php +++ b/tests/wpunit/CartMutationsTest.php @@ -427,7 +427,8 @@ public function testApplyCouponMutation() { $this->factory->coupon->create( array( 'amount' => 0.5, - 'product_ids' => array( $product_id ) + 'product_ids' => array( $product_id ), + 'description' => 'lorem ipsum dolor', ) ) ); @@ -445,6 +446,7 @@ public function testApplyCouponMutation() { cart { appliedCoupons { code + description } contents { nodes { @@ -484,7 +486,8 @@ public function testApplyCouponMutation() { $this->expectedNode( 'applyCoupon.cart.appliedCoupons', array( - 'code' => $coupon_code, + 'code' => $coupon_code, + 'description' => 'lorem ipsum dolor', ) ), $this->expectedNode(