From 1726a00b6a9adf32729cab0d57ba561824ce32f2 Mon Sep 17 00:00:00 2001 From: Paul Kilmurray Date: Wed, 12 Jun 2024 19:58:03 +0100 Subject: [PATCH] v1.6.0 --- includes/API/Customers_Controller.php | 3 +- includes/API/Orders_Controller.php | 3 +- .../API/Product_Categories_Controller.php | 11 ++- includes/API/Product_Tags_Controller.php | 11 ++- .../API/Product_Variations_Controller.php | 10 ++- includes/API/Products_Controller.php | 3 +- includes/API/Taxes_Controller.php | 73 ++++++++++++++----- includes/Templates/Frontend.php | 2 - package.json | 2 +- readme.txt | 9 ++- woocommerce-pos.php | 4 +- 11 files changed, 99 insertions(+), 32 deletions(-) diff --git a/includes/API/Customers_Controller.php b/includes/API/Customers_Controller.php index a897278..ddba36e 100644 --- a/includes/API/Customers_Controller.php +++ b/includes/API/Customers_Controller.php @@ -335,11 +335,12 @@ function format_results( $users, $last_updates, $id_with_modified_date ) { // Collect execution time and server load. $execution_time = microtime( true ) - $start_time; + $execution_time_ms = number_format( $execution_time * 1000, 2 ); $server_load = sys_getloadavg(); $response = rest_ensure_response( $formatted_results ); $response->header( 'X-WP-Total', (int) $total ); - $response->header( 'X-Execution-Time', $execution_time ); + $response->header( 'X-Execution-Time', $execution_time_ms . ' ms' ); $response->header( 'X-Server-Load', json_encode( $server_load ) ); return $response; diff --git a/includes/API/Orders_Controller.php b/includes/API/Orders_Controller.php index 8dfa385..834b723 100644 --- a/includes/API/Orders_Controller.php +++ b/includes/API/Orders_Controller.php @@ -733,11 +733,12 @@ function ( $status ) { // Collect execution time and server load. $execution_time = microtime( true ) - $start_time; + $execution_time_ms = number_format( $execution_time * 1000, 2 ); $server_load = sys_getloadavg(); $response = rest_ensure_response( $formatted_results ); $response->header( 'X-WP-Total', (int) $total ); - $response->header( 'X-Execution-Time', $execution_time ); + $response->header( 'X-Execution-Time', $execution_time_ms . ' ms' ); $response->header( 'X-Server-Load', json_encode( $server_load ) ); return $response; diff --git a/includes/API/Product_Categories_Controller.php b/includes/API/Product_Categories_Controller.php index 28653f9..fd11c63 100644 --- a/includes/API/Product_Categories_Controller.php +++ b/includes/API/Product_Categories_Controller.php @@ -148,6 +148,7 @@ public function wcpos_terms_clauses_include_exclude( array $clauses, array $taxo public function wcpos_get_all_posts( $request ) { // Start timing execution. $start_time = microtime( true ); + $modified_after = $request->get_param( 'modified_after' ); $args = array( 'taxonomy' => 'product_cat', @@ -156,7 +157,12 @@ public function wcpos_get_all_posts( $request ) { ); try { - $results = get_terms( $args ); + /** + * @TODO - terms don't have a modified date, it would be good to add a term_meta for last_update + * - ideally WooCommerce would provide a modified_after filter for terms + * - for now we'll just return empty for modified terms + */ + $results = $modified_after ? array() : get_terms( $args ); // Format the response. $formatted_results = array_map( @@ -171,11 +177,12 @@ function ( $id ) { // Collect execution time and server load. $execution_time = microtime( true ) - $start_time; + $execution_time_ms = number_format( $execution_time * 1000, 2 ); $server_load = sys_getloadavg(); $response = rest_ensure_response( $formatted_results ); $response->header( 'X-WP-Total', (int) $total ); - $response->header( 'X-Execution-Time', $execution_time ); + $response->header( 'X-Execution-Time', $execution_time_ms . ' ms' ); $response->header( 'X-Server-Load', json_encode( $server_load ) ); return $response; diff --git a/includes/API/Product_Tags_Controller.php b/includes/API/Product_Tags_Controller.php index 99b1e74..f9a3730 100644 --- a/includes/API/Product_Tags_Controller.php +++ b/includes/API/Product_Tags_Controller.php @@ -148,6 +148,7 @@ public function wcpos_terms_clauses_include_exclude( array $clauses, array $taxo public function wcpos_get_all_posts( $request ): array { // Start timing execution. $start_time = microtime( true ); + $modified_after = $request->get_param( 'modified_after' ); $args = array( 'taxonomy' => 'product_tag', @@ -156,7 +157,12 @@ public function wcpos_get_all_posts( $request ): array { ); try { - $results = get_terms( $args ); + /** + * @TODO - terms don't have a modified date, it would be good to add a term_meta for last_update + * - ideally WooCommerce would provide a modified_after filter for terms + * - for now we'll just return empty for modified terms + */ + $results = $modified_after ? array() : get_terms( $args ); // Format the response. $formatted_results = array_map( @@ -171,11 +177,12 @@ function ( $id ) { // Collect execution time and server load. $execution_time = microtime( true ) - $start_time; + $execution_time_ms = number_format( $execution_time * 1000, 2 ); $server_load = sys_getloadavg(); $response = rest_ensure_response( $formatted_results ); $response->header( 'X-WP-Total', (int) $total ); - $response->header( 'X-Execution-Time', $execution_time ); + $response->header( 'X-Execution-Time', $execution_time_ms . ' ms' ); $response->header( 'X-Server-Load', json_encode( $server_load ) ); return $response; diff --git a/includes/API/Product_Variations_Controller.php b/includes/API/Product_Variations_Controller.php index 8d8c8ec..f1cfe96 100644 --- a/includes/API/Product_Variations_Controller.php +++ b/includes/API/Product_Variations_Controller.php @@ -376,6 +376,7 @@ public function wcpos_get_all_posts( $request ) { // Start timing execution. $start_time = microtime( true ); + $modified_after = $request->get_param( 'modified_after' ); $fields = $request->get_param( 'fields' ); $parent_id = (int) $this->wcpos_request->get_param( 'product_id' ); $id_with_modified_date = array( 'id', 'date_modified_gmt' ) === $fields; @@ -394,6 +395,12 @@ public function wcpos_get_all_posts( $request ) { $sql .= " WHERE {$wpdb->posts}.post_type = 'product_variation' AND {$wpdb->posts}.post_status = 'publish'"; } + // Add modified_after condition if provided. + if ( $modified_after ) { + $modified_after_date = date( 'Y-m-d H:i:s', strtotime( $modified_after ) ); + $sql .= $wpdb->prepare( ' AND post_modified_gmt > %s', $modified_after_date ); + } + // Dynamically add the post_parent clause if a parent ID is provided. if ( $parent_id ) { $sql = $wpdb->prepare( $sql . " AND {$wpdb->posts}.post_parent = %d", $parent_id ); @@ -409,11 +416,12 @@ public function wcpos_get_all_posts( $request ) { // Collect execution time and server load. $execution_time = microtime( true ) - $start_time; + $execution_time_ms = number_format( $execution_time * 1000, 2 ); $server_load = sys_getloadavg(); $response = rest_ensure_response( $formatted_results ); $response->header( 'X-WP-Total', (int) $total ); - $response->header( 'X-Execution-Time', $execution_time ); + $response->header( 'X-Execution-Time', $execution_time_ms . ' ms' ); $response->header( 'X-Server-Load', json_encode( $server_load ) ); return $response; diff --git a/includes/API/Products_Controller.php b/includes/API/Products_Controller.php index 273ce10..8dc9af4 100644 --- a/includes/API/Products_Controller.php +++ b/includes/API/Products_Controller.php @@ -474,11 +474,12 @@ public function wcpos_get_all_posts( $request ) { // Collect execution time and server load. $execution_time = microtime( true ) - $start_time; + $execution_time_ms = number_format( $execution_time * 1000, 2 ); $server_load = sys_getloadavg(); $response = rest_ensure_response( $formatted_results ); $response->header( 'X-WP-Total', (int) $total ); - $response->header( 'X-Execution-Time', $execution_time ); + $response->header( 'X-Execution-Time', $execution_time_ms . ' ms' ); $response->header( 'X-Server-Load', json_encode( $server_load ) ); return $response; diff --git a/includes/API/Taxes_Controller.php b/includes/API/Taxes_Controller.php index 9e34b44..a8c9e88 100644 --- a/includes/API/Taxes_Controller.php +++ b/includes/API/Taxes_Controller.php @@ -8,8 +8,11 @@ return; } +use Exception; use WC_REST_Taxes_Controller; +use WCPOS\WooCommercePOS\Logger; use WP_REST_Request; +use WP_REST_Response; /** * Product Tgas controller class. @@ -53,7 +56,7 @@ public function wcpos_dispatch_request( $dispatch_result, WP_REST_Request $reque * Optimised query for getting all rate IDs. */ if ( $request->get_param( 'posts_per_page' ) == -1 && $request->get_param( 'fields' ) !== null ) { - return $this->wcpos_get_all_posts( $request->get_param( 'fields' ) ); + return $this->wcpos_get_all_posts( $request ); } return $dispatch_result; @@ -206,26 +209,60 @@ private function wcpos_insert_tax_where_clause( $query, $condition ) { /** * Returns array of all tax_rate ids. * - * @param array $fields + * @param WP_REST_Request $request Full details about the request. * - * @return array|WP_Error + * @return WP_REST_Response|WP_Error */ - public function wcpos_get_all_posts( array $fields = array() ): array { + public function wcpos_get_all_posts( $request ) { global $wpdb; - $results = $wpdb->get_results( - ' - SELECT tax_rate_id as id FROM ' . $wpdb->prefix . 'woocommerce_tax_rates - ', - ARRAY_A - ); - - // Format the response. - return array_map( - function ( $item ) { - return array( 'id' => (int) $item['id'] ); - }, - $results - ); + // Start timing execution. + $start_time = microtime( true ); + $modified_after = $request->get_param( 'modified_after' ); + + try { + /** + * @TODO - taxes doen't have a modified date, so we can't filter by modified_after + * - ideally WooCommerce would provide a modified_after filter for terms + * - for now we'll just return empty for modified terms + */ + $results = $modified_after ? array() : $wpdb->get_results( + ' + SELECT tax_rate_id as id FROM ' . $wpdb->prefix . 'woocommerce_tax_rates + ', + ARRAY_A + ); + + // Format the response. + $formatted_results = array_map( + function ( $item ) { + return array( 'id' => (int) $item['id'] ); + }, + $results + ); + + // Get the total number of orders for the given criteria. + $total = count( $formatted_results ); + + // Collect execution time and server load. + $execution_time = microtime( true ) - $start_time; + $execution_time_ms = number_format( $execution_time * 1000, 2 ); + $server_load = sys_getloadavg(); + + $response = rest_ensure_response( $formatted_results ); + $response->header( 'X-WP-Total', (int) $total ); + $response->header( 'X-Execution-Time', $execution_time_ms . ' ms' ); + $response->header( 'X-Server-Load', json_encode( $server_load ) ); + + return $response; + } catch ( Exception $e ) { + Logger::log( 'Error fetching product tax rate IDs: ' . $e->getMessage() ); + + return new \WP_Error( + 'woocommerce_pos_rest_cannot_fetch', + 'Error fetching product tax rate IDs.', + array( 'status' => 500 ) + ); + } } } diff --git a/includes/Templates/Frontend.php b/includes/Templates/Frontend.php index 9ff25e7..401bedb 100644 --- a/includes/Templates/Frontend.php +++ b/includes/Templates/Frontend.php @@ -153,7 +153,6 @@ function ( $store ) { * Add path to worker scripts */ $idbWorker = PLUGIN_URL . 'assets/js/indexeddb.worker.js'; - $mmIdbWorker = PLUGIN_URL . 'assets/js/memory-mapped-indexeddb.worker.js'; /** * getScript helper and initialProps @@ -178,7 +177,6 @@ function getScript(source, callback) { } var idbWorker = '{$idbWorker}'; - var mmIdbWorker = '{$mmIdbWorker}'; var initialProps = {$initial_props}; " . "\n"; diff --git a/package.json b/package.json index a4c93c8..6680e4e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@wcpos/woocommerce-pos", - "version": "1.5.1", + "version": "1.6.0", "description": "A simple front-end for taking WooCommerce orders at the Point of Sale.", "main": "index.js", "workspaces": { diff --git a/readme.txt b/readme.txt index e4014ab..d59b927 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: kilbot Tags: ecommerce, point-of-sale, pos, inventory, woocommerce Requires at least: 5.6 Tested up to: 6.5 -Stable tag: 1.5.1 +Stable tag: 1.6.0 License: GPL-3.0 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -80,6 +80,13 @@ There is more information on our website at [https://wcpos.com](https://wcpos.co == Changelog == += 1.6.0 - 2024/06/12 = +* Improved: Performance for large stores +* Added: Log screen for insights into the POS performance and events +* Added: Cart setting to enable/disable show receipt after checkout +* Added: Cart setting to enable/disable auto-print receipt after checkout +* Fix: Prevent order create duplication from the POS + = 1.5.1 - 2024/06/03 = * Fix: "Sorry, you cannot list resources." error for cashier role diff --git a/woocommerce-pos.php b/woocommerce-pos.php index f674397..a8f95cb 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.5.1 + * Version: 1.6.0 * Author: kilbot * Author URI: http://wcpos.com * Text Domain: woocommerce-pos @@ -24,7 +24,7 @@ namespace WCPOS\WooCommercePOS; // Define plugin constants. -const VERSION = '1.5.1'; +const VERSION = '1.6.0'; const PLUGIN_NAME = 'woocommerce-pos'; const SHORT_NAME = 'wcpos'; \define( __NAMESPACE__ . '\PLUGIN_FILE', plugin_basename( __FILE__ ) ); // 'woocommerce-pos/woocommerce-pos.php'