Skip to content

Commit

Permalink
Complete all orders if status is not 'pos-open'
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Dec 3, 2023
1 parent fa14938 commit 72aa338
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion includes/Templates/Received.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
55 changes: 29 additions & 26 deletions tests/includes/API/WCPOS_REST_Unit_Test_Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,42 @@ 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(
array(
'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;
}
Expand All @@ -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' );
}
}

0 comments on commit 72aa338

Please sign in to comment.