From 72aa3387add4d282aab5ab787d860370c6537b3b Mon Sep 17 00:00:00 2001 From: Paul Kilmurray Date: Sun, 3 Dec 2023 12:55:39 +0100 Subject: [PATCH] Complete all orders if status is not 'pos-open' --- includes/Templates/Received.php | 2 +- .../API/WCPOS_REST_Unit_Test_Case.php | 55 ++++++++++--------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/includes/Templates/Received.php b/includes/Templates/Received.php index 9ad2de7..aa36f57 100644 --- a/includes/Templates/Received.php +++ b/includes/Templates/Received.php @@ -48,7 +48,7 @@ public function get_template(): void { $order_json = $server->wp_rest_request( '/wcpos/v1/orders/' . $this->order_id ); $completed_status_setting = woocommerce_pos_get_settings( 'checkout', 'order_status' ); $completed_status = 'wc-' === substr( $completed_status_setting, 0, 3 ) ? substr( $completed_status_setting, 3 ) : $completed_status_setting; - $order_complete = $order->has_status( array( $completed_status, 'pos-partial' ) ); + $order_complete = $completed_status !== 'pos-open'; // @TODO - display message for errors diff --git a/tests/includes/API/WCPOS_REST_Unit_Test_Case.php b/tests/includes/API/WCPOS_REST_Unit_Test_Case.php index be829e1..feebdd8 100644 --- a/tests/includes/API/WCPOS_REST_Unit_Test_Case.php +++ b/tests/includes/API/WCPOS_REST_Unit_Test_Case.php @@ -16,14 +16,14 @@ abstract class WCPOS_REST_Unit_Test_Case extends WC_REST_Unit_Test_Case { * @var Controller */ protected $endpoint; - + /** * @var WP_User */ protected $user; public function setUp(): void { - add_action('rest_api_init', array($this, 'rest_api_init')); // add hook before parent::setUp() + add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); // add hook before parent::setUp() parent::setUp(); $this->user = $this->factory->user->create( @@ -31,27 +31,27 @@ public function setUp(): void { 'role' => 'administrator', ) ); - wp_set_current_user($this->user); + wp_set_current_user( $this->user ); } public function rest_api_init(): void { new API(); } - public function wp_rest_get_request($path = ''): WP_REST_Request { + public function wp_rest_get_request( $path = '' ): WP_REST_Request { $request = new WP_REST_Request(); - $request->set_header('X-WCPOS', '1'); - $request->set_method('GET'); - $request->set_route($path); + $request->set_header( 'X-WCPOS', '1' ); + $request->set_method( 'GET' ); + $request->set_route( $path ); return $request; } - public function wp_rest_post_request($path = ''): WP_REST_Request { + public function wp_rest_post_request( $path = '' ): WP_REST_Request { $request = new WP_REST_Request(); - $request->set_header('X-WCPOS', '1'); - $request->set_method('POST'); - $request->set_route($path); + $request->set_header( 'X-WCPOS', '1' ); + $request->set_method( 'POST' ); + $request->set_route( $path ); return $request; } @@ -62,29 +62,32 @@ public function wp_rest_post_request($path = ''): WP_REST_Request { * * @param mixed $path */ - public function wp_rest_patch_request($path = ''): WP_REST_Request { + public function wp_rest_patch_request( $path = '' ): WP_REST_Request { $request = new WP_REST_Request(); - $request->set_header('X-WCPOS', '1'); - $request->set_method('POST'); - $request->set_route($path); - $request->set_query_params(array('_method' => 'PATCH')); + $request->set_header( 'X-WCPOS', '1' ); + $request->set_method( 'POST' ); + $request->set_route( $path ); + $request->set_query_params( array( '_method' => 'PATCH' ) ); return $request; } - public function get_reflected_property_value($propertyName) { - $reflection = new ReflectionClass($this->endpoint); - $property = $reflection->getProperty($propertyName); - $property->setAccessible(true); + public function get_reflected_property_value( $propertyName ) { + $reflection = new ReflectionClass( $this->endpoint ); + $property = $reflection->getProperty( $propertyName ); + $property->setAccessible( true ); - return $property->getValue($this->endpoint); + return $property->getValue( $this->endpoint ); } protected function setup_decimal_quantity_tests(): void { - add_filter( 'woocommerce_pos_general_settings', function() { - return array('decimal_qty' => true); - }); - remove_filter('woocommerce_stock_amount', 'intval'); - add_filter('woocommerce_stock_amount', 'floatval'); + add_filter( + 'woocommerce_pos_general_settings', + function () { + return array( 'decimal_qty' => true ); + } + ); + remove_filter( 'woocommerce_stock_amount', 'intval' ); + add_filter( 'woocommerce_stock_amount', 'floatval' ); } }