diff --git a/.github/workflows/update-pot.yml b/.github/workflows/update-pot.yml index 9d098b1..1c6cc8f 100644 --- a/.github/workflows/update-pot.yml +++ b/.github/workflows/update-pot.yml @@ -38,7 +38,7 @@ jobs: if: steps.git-diff.outputs.changes == 'true' uses: stefanzweifel/git-auto-commit-action@v4 with: - commit_message: 'chore(l10n): update languages/woocommerce-pos.pot' + commit_message: 'chore(i18n): update languages/woocommerce-pos.pot' file_pattern: '*.pot' diff --git a/includes/AJAX.php b/includes/AJAX.php index 6413516..5a07624 100644 --- a/includes/AJAX.php +++ b/includes/AJAX.php @@ -53,7 +53,8 @@ public function __construct() { return; } - if ( 'heartbeat' == $_POST['action'] ) { + // ignore for WP Admin heartbeat requests + if ( isset( $_POST['action'] ) && 'heartbeat' == $_POST['action'] ) { return; } diff --git a/includes/API/Orders_Controller.php b/includes/API/Orders_Controller.php index d26de41..ae57b13 100644 --- a/includes/API/Orders_Controller.php +++ b/includes/API/Orders_Controller.php @@ -132,10 +132,17 @@ public function get_item_schema() { // Modify line_items->parent_name to accept 'string' or 'null' if ( isset( $schema['properties']['line_items'] ) && - \is_array( $schema['properties']['line_items']['items']['properties'] ) ) { + \is_array( $schema['properties']['line_items']['items']['properties'] ) ) { $schema['properties']['line_items']['items']['properties']['parent_name']['type'] = array( 'string', 'null' ); } + // Check for 'stock_quantity' and allow decimal + if ( $this->wcpos_allow_decimal_quantities() && + isset( $schema['properties']['line_items'] ) && + \is_array( $schema['properties']['line_items']['items']['properties'] ) ) { + $schema['properties']['line_items']['items']['properties']['quantity']['type'] = array( 'number' ); + } + return $schema; } diff --git a/includes/API/Traits/Product_Helpers.php b/includes/API/Traits/Product_Helpers.php index ebc7d95..0a10b63 100644 --- a/includes/API/Traits/Product_Helpers.php +++ b/includes/API/Traits/Product_Helpers.php @@ -64,23 +64,4 @@ public function wcpos_pos_only_products_enabled() { // make sure it's true, just in case there's a corrupt setting return true === $pos_only_products_enabled; } - - /** - * Get barcode field from settings. - * - * @return bool - */ - public function wcpos_allow_decimal_quantities() { - $allow_decimal_quantities = woocommerce_pos_get_settings( 'general', 'decimal_qty' ); - - // Check for WP_Error - if ( is_wp_error( $allow_decimal_quantities ) ) { - Logger::log( 'Error retrieving decimal_qty: ' . $allow_decimal_quantities->get_error_message() ); - - return false; - } - - // make sure it's true, just in case there's a corrupt setting - return true === $allow_decimal_quantities; - } } diff --git a/includes/API/Traits/WCPOS_REST_API.php b/includes/API/Traits/WCPOS_REST_API.php index c7b976b..8b5c09c 100644 --- a/includes/API/Traits/WCPOS_REST_API.php +++ b/includes/API/Traits/WCPOS_REST_API.php @@ -28,9 +28,12 @@ public function wcpos_format_id( string $id ): object { * @return array */ public function wcpos_parse_meta_data( WC_Data $object ): array { - return array_map( function( $meta_data ) { - return $meta_data->get_data(); - }, $object->get_meta_data()); + return array_map( + function ( $meta_data ) { + return $meta_data->get_data(); + }, + $object->get_meta_data() + ); } /** @@ -50,4 +53,23 @@ public function wcpos_log_large_rest_response( WP_REST_Response $response, int $ Logger::log( "ID {$id} has a response size of {$response_size} bytes, exceeding the limit of {$max_response_size} bytes." ); } } + + /** + * Get barcode field from settings. + * + * @return bool + */ + public function wcpos_allow_decimal_quantities() { + $allow_decimal_quantities = woocommerce_pos_get_settings( 'general', 'decimal_qty' ); + + // Check for WP_Error + if ( is_wp_error( $allow_decimal_quantities ) ) { + Logger::log( 'Error retrieving decimal_qty: ' . $allow_decimal_quantities->get_error_message() ); + + return false; + } + + // make sure it's true, just in case there's a corrupt setting + return true === $allow_decimal_quantities; + } } diff --git a/includes/Orders.php b/includes/Orders.php index d0679cd..71a5534 100644 --- a/includes/Orders.php +++ b/includes/Orders.php @@ -1,5 +1,4 @@ assertEquals( array( $order2->get_id() ), $ids ); } + + /** + * + */ + public function test_create_order_with_decimal_quantity() { + $this->setup_decimal_quantity_tests(); + + $request = $this->wp_rest_post_request( '/wcpos/v1/orders' ); + $request->set_body_params( + array( + 'payment_method' => 'pos_cash', + 'line_items' => array( + array( + 'product_id' => 1, + 'quantity' => '1.5', + ), + ), + ) + ); + + $response = $this->server->dispatch( $request ); + $data = $response->get_data(); + $this->assertEquals( 201, $response->get_status() ); + + $this->assertEquals( 'woocommerce-pos', $data['created_via'] ); + } } diff --git a/woocommerce-pos.php b/woocommerce-pos.php index f8b635c..0a1daca 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.4.5.1 + * Version: 1.4.6 * Author: kilbot * Author URI: http://wcpos.com * Text Domain: woocommerce-pos