From 88f54ae9cb3934bd486dd38d33aceb6a58224785 Mon Sep 17 00:00:00 2001 From: Florian Bischoff Date: Thu, 14 Oct 2021 15:14:38 +0200 Subject: [PATCH 1/2] fix: respect woocommerce tax display settings --- includes/type/object/class-cart-type.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/includes/type/object/class-cart-type.php b/includes/type/object/class-cart-type.php index e80084295..8d37ffae2 100644 --- a/includes/type/object/class-cart-type.php +++ b/includes/type/object/class-cart-type.php @@ -132,8 +132,14 @@ public static function register_cart() { 'type' => 'String', 'description' => __( 'Cart contents total', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { - $price = ! is_null( $source->get_cart_contents_total() ) - ? $source->get_cart_contents_total() + if ( $source->display_prices_including_tax() ) { + $cart_subtotal = $source->get_subtotal() + $source->get_subtotal_tax(); + } else { + $cart_subtotal = $source->get_subtotal(); + } + + $price = ! is_null( $cart_subtotal ) + ? $cart_subtotal : 0; return \wc_graphql_price( $price ); }, @@ -326,7 +332,9 @@ public static function register_cart_item() { 'type' => 'String', 'description' => __( 'Item\'s total', 'wp-graphql-woocommerce' ), 'resolve' => function( $source ) { - $price = isset( $source['line_total'] ) ? floatval( $source['line_total'] ) : null; + $price_without_tax = isset( $source['line_total'] ) ? floatval( $source['line_total'] ) : null; + $tax = isset( $source['line_tax'] ) ? floatval( $source['line_tax'] ) : null; + $price = $price_without_tax + $tax; return \wc_graphql_price( $price ); }, ), From a2ca894f79c6d0237865da5db9ed99f08b4cde37 Mon Sep 17 00:00:00 2001 From: Florian Bischoff Date: Fri, 15 Oct 2021 08:40:52 +0200 Subject: [PATCH 2/2] fix: whitespace linting err --- includes/type/object/class-cart-type.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/type/object/class-cart-type.php b/includes/type/object/class-cart-type.php index 8d37ffae2..1e88163c8 100644 --- a/includes/type/object/class-cart-type.php +++ b/includes/type/object/class-cart-type.php @@ -137,7 +137,7 @@ public static function register_cart() { } else { $cart_subtotal = $source->get_subtotal(); } - + $price = ! is_null( $cart_subtotal ) ? $cart_subtotal : 0; @@ -334,7 +334,7 @@ public static function register_cart_item() { 'resolve' => function( $source ) { $price_without_tax = isset( $source['line_total'] ) ? floatval( $source['line_total'] ) : null; $tax = isset( $source['line_tax'] ) ? floatval( $source['line_tax'] ) : null; - $price = $price_without_tax + $tax; + $price = $price_without_tax + $tax; return \wc_graphql_price( $price ); }, ),