From bde5fc5bbd0627abac41e66acf72abe649d9845d Mon Sep 17 00:00:00 2001 From: Andres Date: Fri, 10 Mar 2023 19:46:39 +0100 Subject: [PATCH] Adds tax calculation to regular and sale prices. (#714) * Adds tax calculation to regular and sale prices. * fixup! Adds tax calculation to regular and sale prices. * Fix phpunit deprecated method. * fixup! Fix phpunit deprecated method. * fixup! fixup! Fix phpunit deprecated method. * Fix missing param in function. * Fix linting. --------- Co-authored-by: Andres A --- includes/model/class-product.php | 11 +++++++++-- tests/wpunit/QLSessionHandlerTest.php | 12 ++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/includes/model/class-product.php b/includes/model/class-product.php index d2e8b1fe..fe65ff62 100644 --- a/includes/model/class-product.php +++ b/includes/model/class-product.php @@ -245,7 +245,7 @@ class Product extends WC_Post { }, 'regularPrice' => function() { return ! empty( $this->wc_data->get_regular_price() ) - ? \wc_graphql_price( $this->wc_data->get_regular_price() ) + ? \wc_graphql_price( \wc_get_price_to_display( $this->wc_data, [ 'price' => $this->wc_data->get_regular_price() ] ) ) : null; }, 'regularPriceRaw' => function() { @@ -253,7 +253,14 @@ class Product extends WC_Post { }, 'salePrice' => function() { return ! empty( $this->wc_data->get_sale_price() ) - ? \wc_graphql_price( $this->wc_data->get_sale_price() ) + ? \wc_graphql_price( + \wc_get_price_to_display( + [ + $this->wc_data, + 'price' => $this->wc_data->get_sale_price(), + ] + ) + ) : null; }, 'salePriceRaw' => function() { diff --git a/tests/wpunit/QLSessionHandlerTest.php b/tests/wpunit/QLSessionHandlerTest.php index 23b491a9..e7aaddd4 100644 --- a/tests/wpunit/QLSessionHandlerTest.php +++ b/tests/wpunit/QLSessionHandlerTest.php @@ -74,9 +74,9 @@ class QLSessionHandlerTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGrap // Expect token to be value. $token = $session->get_session_token(); - $this->assertObjectHasAttribute( 'iat', $token ); - $this->assertObjectHasAttribute( 'exp', $token ); - $this->assertObjectHasAttribute( 'data', $token ); + $this->assertTrue( ! empty( $token->iat ) ); + $this->assertTrue( ! empty( $token->exp ) ); + $this->assertTrue( ! empty( $token->data ) ); } public function test_get_session_header() { @@ -108,9 +108,9 @@ class QLSessionHandlerTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGrap $token = $session->build_token(); $decode_token = JWT::decode( $token, new Key( GRAPHQL_WOOCOMMERCE_SECRET_KEY, 'HS256' ) ); - $this->assertObjectHasAttribute( 'iat', $decode_token ); - $this->assertObjectHasAttribute( 'exp', $decode_token ); - $this->assertObjectHasAttribute( 'data', $decode_token ); + $this->assertTrue( ! empty( $decode_token->iat ) ); + $this->assertTrue( ! empty( $decode_token->exp ) ); + $this->assertTrue( ! empty( $decode_token->data ) ); $this->assertEquals( $token, $session->build_token() ); }