From a5e645841d337c928dec80b5f961d9b4b7426914 Mon Sep 17 00:00:00 2001 From: Paul Kilmurray Date: Wed, 13 Nov 2024 12:31:33 +0100 Subject: [PATCH] v1.7.0 --- includes/API/Customers_Controller.php | 18 ++++++++ includes/API/Orders_Controller.php | 39 +++++++++++++++-- includes/Templates/Frontend.php | 2 +- readme.txt | 17 ++++++-- .../API/Test_HPOS_Orders_Controller.php | 42 +++++++++++++++++++ tests/includes/API/Test_Orders_Controller.php | 42 +++++++++++++++++++ woocommerce-pos.php | 8 ++-- 7 files changed, 155 insertions(+), 13 deletions(-) diff --git a/includes/API/Customers_Controller.php b/includes/API/Customers_Controller.php index 16fc618..df4fb1a 100644 --- a/includes/API/Customers_Controller.php +++ b/includes/API/Customers_Controller.php @@ -112,6 +112,16 @@ public function get_collection_params() { } } + // Add 'roles' filter, this allows us to filter by multiple roles. + $params['roles'] = array( + 'description' => __( 'Filter customers by roles.', 'woocommerce-pos' ), + 'type' => 'array', + 'items' => array( + 'type' => 'string', + ), + 'required' => false, + ); + return $params; } @@ -490,6 +500,14 @@ public function wcpos_customer_query( array $prepared_args, WP_REST_Request $req add_action( 'pre_user_query', array( $this, 'wcpos_include_exclude_users_by_id' ) ); } + // Filter by roles (this is a comma separated list of roles). + if ( ! empty( $request['roles'] ) && is_array( $request['roles'] ) ) { + $roles = array_map( 'sanitize_text_field', $request['roles'] ); + $prepared_args['role__in'] = $roles; + // remove $prepared_args['role'] to prevent it from overriding $prepared_args['role__in'] + unset( $prepared_args['role'] ); + } + return $prepared_args; } diff --git a/includes/API/Orders_Controller.php b/includes/API/Orders_Controller.php index 550ca20..cb44fca 100644 --- a/includes/API/Orders_Controller.php +++ b/includes/API/Orders_Controller.php @@ -370,25 +370,40 @@ public function wcpos_validate_billing_email( WP_REST_Request $request ) { return true; } - - /** * Modify the collection params. */ public function get_collection_params() { $params = parent::get_collection_params(); - if ( isset( $params['per_page'] ) ) { + // Ensure 'per_page' is an array and has a 'minimum' key + if ( isset( $params['per_page'] ) && is_array( $params['per_page'] ) ) { $params['per_page']['minimum'] = -1; } - if ( isset( $params['orderby'] ) && \is_array( $params['orderby']['enum'] ) ) { + // Ensure 'orderby' is an array and has an 'enum' key that is also an array + if ( isset( $params['orderby'] ) && is_array( $params['orderby'] ) && isset( $params['orderby']['enum'] ) && is_array( $params['orderby']['enum'] ) ) { $params['orderby']['enum'] = array_merge( $params['orderby']['enum'], array( 'status', 'customer_id', 'payment_method', 'total' ) ); } + // Add 'pos_cashier' parameter + $params['pos_cashier'] = array( + 'description' => __('Filter orders by POS cashier.', 'woocommerce-pos'), + 'type' => 'integer', + 'required' => false, + ); + + // Add 'pos_store' parameter + // @NOTE - this is different to 'store_id' which is the store the request was made from. + $params['pos_store'] = array( + 'description' => __('Filter orders by POS store.', 'woocommerce-pos'), + 'type' => 'integer', + 'required' => false, + ); + return $params; } @@ -603,6 +618,22 @@ public function wcpos_shop_order_query( array $args, WP_REST_Request $request ) } } + // Add 'pos_cashier' filter. + if ( isset( $request['pos_cashier'] ) ) { + $args['meta_query'][] = array( + 'key' => '_pos_user', + 'value' => $request['pos_cashier'], + ); + } + + // Add 'pos_store' filter. + if ( isset( $request['pos_store'] ) ) { + $args['meta_query'][] = array( + 'key' => '_pos_store', + 'value' => $request['pos_store'], + ); + } + return $args; } diff --git a/includes/Templates/Frontend.php b/includes/Templates/Frontend.php index f57de62..cbd1f9a 100644 --- a/includes/Templates/Frontend.php +++ b/includes/Templates/Frontend.php @@ -147,7 +147,7 @@ function ( $store ) { */ $vars = apply_filters( 'woocommerce_pos_inline_vars', $vars ); $initial_props = wp_json_encode( $vars ); - $dev_bundle = 'http://localhost:8081/index.bundle?platform=web&dev=true&hot=false'; + $dev_bundle = site_url( '/index.bundle?platform=web&dev=true&hot=false' ); /** * Add path to worker scripts diff --git a/readme.txt b/readme.txt index 74ce1da..03fcaaa 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: kilbot Tags: ecommerce, point-of-sale, pos, inventory, woocommerce Requires at least: 5.6 -Tested up to: 6.5 -Stable tag: 1.6.6 +Tested up to: 6.7 +Stable tag: 1.7.0 License: GPL-3.0 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -80,6 +80,15 @@ There is more information on our website at [https://wcpos.com](https://wcpos.co == Changelog == += 1.7.0 - 2024/11/13 = +* Enhancement: Updated all React components to use modern standards (Tailwind, Radix UI), improving reliability and usability +* Enhancement: Improved the local database query engine for a more responsive POS experience +* Enhancement: Improved barcode scanning detection +* Fix: Popover positioning issues +* Fix: Customer search on Android devices +* Fix: Quick discounts calculation bug affecting some users +* Pro: New Reports page for End of Day Reporting (Z-Report) + = 1.6.6 - 2024/09/05 = * Fix: POS Only Products appearing in the POS 😓 @@ -283,8 +292,8 @@ There is more information on our website at [https://wcpos.com](https://wcpos.co == Upgrade Notice == -= 1.5.0 = += 1.7.0 = **Important Update Notice:** -We have made some significant changes to the local POS database in this update. To ensure a smooth transition, please consider updating your system when you have a quiet moment, such as outside of your busy sales hours. This will allow you to thoroughly test the new features and changes. +We have made some significant changes to the User Interface. To ensure a smooth transition, please consider updating your system when you have a quiet moment, such as outside of your busy sales hours. This will allow you to thoroughly test the new features and changes. For the latest updates and real-time information, please visit our community chat at [wcpos.com/discord](https://wcpos.com/discord). diff --git a/tests/includes/API/Test_HPOS_Orders_Controller.php b/tests/includes/API/Test_HPOS_Orders_Controller.php index c89eb21..8eff40d 100644 --- a/tests/includes/API/Test_HPOS_Orders_Controller.php +++ b/tests/includes/API/Test_HPOS_Orders_Controller.php @@ -880,4 +880,46 @@ public function test_create_order_with_decimal_quantity() { $this->assertEquals( 'woocommerce-pos', $data['created_via'] ); } + + /** + * + */ + public function test_filter_order_by_cashier() { + $order1 = OrderHelper::create_order(); + $order2 = OrderHelper::create_order(); + $order2->add_meta_data( '_pos_user', 4, true ); + $order2->save(); + + $request = $this->wp_rest_get_request( '/wcpos/v1/orders' ); + $request->set_param( 'pos_cashier', 4 ); + + $response = $this->server->dispatch( $request ); + $data = $response->get_data(); + $this->assertEquals( 200, $response->get_status() ); + $this->assertEquals( 1, \count( $data ) ); + + $ids = wp_list_pluck( $data, 'id' ); + $this->assertEquals( array( $order2->get_id() ), $ids ); + } + + /** + * + */ + public function test_filter_order_by_store() { + $order1 = OrderHelper::create_order(); + $order2 = OrderHelper::create_order(); + $order2->add_meta_data( '_pos_store', 64, true ); + $order2->save(); + + $request = $this->wp_rest_get_request( '/wcpos/v1/orders' ); + $request->set_param( 'pos_store', 64 ); + + $response = $this->server->dispatch( $request ); + $data = $response->get_data(); + $this->assertEquals( 200, $response->get_status() ); + $this->assertEquals( 1, \count( $data ) ); + + $ids = wp_list_pluck( $data, 'id' ); + $this->assertEquals( array( $order2->get_id() ), $ids ); + } } diff --git a/tests/includes/API/Test_Orders_Controller.php b/tests/includes/API/Test_Orders_Controller.php index 60f607a..66855c6 100644 --- a/tests/includes/API/Test_Orders_Controller.php +++ b/tests/includes/API/Test_Orders_Controller.php @@ -832,4 +832,46 @@ public function test_create_order_with_decimal_quantity() { $this->assertEquals( 'woocommerce-pos', $data['created_via'] ); } + + /** + * + */ + public function test_filter_order_by_cashier() { + $order1 = OrderHelper::create_order(); + $order2 = OrderHelper::create_order(); + $order2->add_meta_data( '_pos_user', 4, true ); + $order2->save(); + + $request = $this->wp_rest_get_request( '/wcpos/v1/orders' ); + $request->set_param( 'pos_cashier', 4 ); + + $response = $this->server->dispatch( $request ); + $data = $response->get_data(); + $this->assertEquals( 200, $response->get_status() ); + $this->assertEquals( 1, \count( $data ) ); + + $ids = wp_list_pluck( $data, 'id' ); + $this->assertEquals( array( $order2->get_id() ), $ids ); + } + + /** + * + */ + public function test_filter_order_by_store() { + $order1 = OrderHelper::create_order(); + $order2 = OrderHelper::create_order(); + $order2->add_meta_data( '_pos_store', 64, true ); + $order2->save(); + + $request = $this->wp_rest_get_request( '/wcpos/v1/orders' ); + $request->set_param( 'pos_store', 64 ); + + $response = $this->server->dispatch( $request ); + $data = $response->get_data(); + $this->assertEquals( 200, $response->get_status() ); + $this->assertEquals( 1, \count( $data ) ); + + $ids = wp_list_pluck( $data, 'id' ); + $this->assertEquals( array( $order2->get_id() ), $ids ); + } } diff --git a/woocommerce-pos.php b/woocommerce-pos.php index 9f967e0..cd16c58 100644 --- a/woocommerce-pos.php +++ b/woocommerce-pos.php @@ -3,7 +3,7 @@ * Plugin Name: WooCommerce POS * Plugin URI: https://wordpress.org/plugins/woocommerce-pos/ * Description: A simple front-end for taking WooCommerce orders at the Point of Sale. Requires WooCommerce. - * Version: 1.6.6 + * Version: 1.7.0 * Author: kilbot * Author URI: http://wcpos.com * Text Domain: woocommerce-pos @@ -11,10 +11,10 @@ * License URI: http://www.gnu.org/licenses/gpl-3.0.txt * Domain Path: /languages * Requires at least: 5.6 - * Tested up to: 6.6 + * Tested up to: 6.7 * Requires PHP: 7.4 * Requires Plugins: woocommerce - * WC tested up to: 9.2 + * WC tested up to: 9.4 * WC requires at least: 5.3 * * @see http://wcpos.com @@ -24,7 +24,7 @@ namespace WCPOS\WooCommercePOS; // Define plugin constants. -const VERSION = '1.6.6'; +const VERSION = '1.7.0'; const PLUGIN_NAME = 'woocommerce-pos'; const SHORT_NAME = 'wcpos'; \define( __NAMESPACE__ . '\PLUGIN_FILE', plugin_basename( __FILE__ ) ); // 'woocommerce-pos/woocommerce-pos.php'