Skip to content

Commit

Permalink
v1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kilbot committed Jun 12, 2024
1 parent f5b7664 commit 1726a00
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 32 deletions.
3 changes: 2 additions & 1 deletion includes/API/Customers_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion includes/API/Orders_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions includes/API/Product_Categories_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(
Expand All @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions includes/API/Product_Tags_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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(
Expand All @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion includes/API/Product_Variations_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 );
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion includes/API/Products_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
73 changes: 55 additions & 18 deletions includes/API/Taxes_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
);
}
}
}
2 changes: 0 additions & 2 deletions includes/Templates/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -178,7 +177,6 @@ function getScript(source, callback) {
}
var idbWorker = '{$idbWorker}';
var mmIdbWorker = '{$mmIdbWorker}';
var initialProps = {$initial_props};
</script>" . "\n";

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
9 changes: 8 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions woocommerce-pos.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="http://wordpress.org/plugins/woocommerce/">WooCommerce</a>.
* Version: 1.5.1
* Version: 1.6.0
* Author: kilbot
* Author URI: http://wcpos.com
* Text Domain: woocommerce-pos
Expand All @@ -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'
Expand Down

0 comments on commit 1726a00

Please sign in to comment.