Skip to content

Commit 42554a9

Browse files
committed
fix decimal quantities for orders
1 parent 046380e commit 42554a9

File tree

10 files changed

+67
-31
lines changed

10 files changed

+67
-31
lines changed

.github/workflows/update-pot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
if: steps.git-diff.outputs.changes == 'true'
3939
uses: stefanzweifel/git-auto-commit-action@v4
4040
with:
41-
commit_message: 'chore(l10n): update languages/woocommerce-pos.pot'
41+
commit_message: 'chore(i18n): update languages/woocommerce-pos.pot'
4242
file_pattern: '*.pot'
4343

4444

includes/AJAX.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public function __construct() {
5353
return;
5454
}
5555

56-
if ( 'heartbeat' == $_POST['action'] ) {
56+
// ignore for WP Admin heartbeat requests
57+
if ( isset( $_POST['action'] ) && 'heartbeat' == $_POST['action'] ) {
5758
return;
5859
}
5960

includes/API/Orders_Controller.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,17 @@ public function get_item_schema() {
132132

133133
// Modify line_items->parent_name to accept 'string' or 'null'
134134
if ( isset( $schema['properties']['line_items'] ) &&
135-
\is_array( $schema['properties']['line_items']['items']['properties'] ) ) {
135+
\is_array( $schema['properties']['line_items']['items']['properties'] ) ) {
136136
$schema['properties']['line_items']['items']['properties']['parent_name']['type'] = array( 'string', 'null' );
137137
}
138138

139+
// Check for 'stock_quantity' and allow decimal
140+
if ( $this->wcpos_allow_decimal_quantities() &&
141+
isset( $schema['properties']['line_items'] ) &&
142+
\is_array( $schema['properties']['line_items']['items']['properties'] ) ) {
143+
$schema['properties']['line_items']['items']['properties']['quantity']['type'] = array( 'number' );
144+
}
145+
139146
return $schema;
140147
}
141148

includes/API/Traits/Product_Helpers.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,4 @@ public function wcpos_pos_only_products_enabled() {
6464
// make sure it's true, just in case there's a corrupt setting
6565
return true === $pos_only_products_enabled;
6666
}
67-
68-
/**
69-
* Get barcode field from settings.
70-
*
71-
* @return bool
72-
*/
73-
public function wcpos_allow_decimal_quantities() {
74-
$allow_decimal_quantities = woocommerce_pos_get_settings( 'general', 'decimal_qty' );
75-
76-
// Check for WP_Error
77-
if ( is_wp_error( $allow_decimal_quantities ) ) {
78-
Logger::log( 'Error retrieving decimal_qty: ' . $allow_decimal_quantities->get_error_message() );
79-
80-
return false;
81-
}
82-
83-
// make sure it's true, just in case there's a corrupt setting
84-
return true === $allow_decimal_quantities;
85-
}
8667
}

includes/API/Traits/WCPOS_REST_API.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ public function wcpos_format_id( string $id ): object {
2828
* @return array
2929
*/
3030
public function wcpos_parse_meta_data( WC_Data $object ): array {
31-
return array_map( function( $meta_data ) {
32-
return $meta_data->get_data();
33-
}, $object->get_meta_data());
31+
return array_map(
32+
function ( $meta_data ) {
33+
return $meta_data->get_data();
34+
},
35+
$object->get_meta_data()
36+
);
3437
}
3538

3639
/**
@@ -50,4 +53,23 @@ public function wcpos_log_large_rest_response( WP_REST_Response $response, int $
5053
Logger::log( "ID {$id} has a response size of {$response_size} bytes, exceeding the limit of {$max_response_size} bytes." );
5154
}
5255
}
56+
57+
/**
58+
* Get barcode field from settings.
59+
*
60+
* @return bool
61+
*/
62+
public function wcpos_allow_decimal_quantities() {
63+
$allow_decimal_quantities = woocommerce_pos_get_settings( 'general', 'decimal_qty' );
64+
65+
// Check for WP_Error
66+
if ( is_wp_error( $allow_decimal_quantities ) ) {
67+
Logger::log( 'Error retrieving decimal_qty: ' . $allow_decimal_quantities->get_error_message() );
68+
69+
return false;
70+
}
71+
72+
// make sure it's true, just in case there's a corrupt setting
73+
return true === $allow_decimal_quantities;
74+
}
5375
}

includes/Orders.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
/**
43
* WCPOS Orders Class
54
* Extends WooCommerce Orders.
@@ -21,7 +20,6 @@ public function __construct() {
2120
add_filter( 'woocommerce_valid_order_statuses_for_payment', array( $this, 'valid_order_statuses_for_payment' ), 10, 2 );
2221
add_filter( 'woocommerce_valid_order_statuses_for_payment_complete', array( $this, 'valid_order_statuses_for_payment_complete' ), 10, 2 );
2322
add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'payment_complete_order_status' ), 10, 3 );
24-
2523
add_filter( 'woocommerce_hidden_order_itemmeta', array( $this, 'hidden_order_itemmeta' ) );
2624

2725
// order emails

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wcpos/woocommerce-pos",
3-
"version": "1.4.5.1",
3+
"version": "1.4.6",
44
"description": "A simple front-end for taking WooCommerce orders at the Point of Sale.",
55
"main": "index.js",
66
"workspaces": {

readme.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: kilbot
33
Tags: cart, e-commerce, ecommerce, inventory, point-of-sale, pos, sales, sell, shop, shopify, store, vend, woocommerce, wordpress-ecommerce
44
Requires at least: 5.6 & WooCommerce 5.3
55
Tested up to: 6.4
6-
Stable tag: 1.4.5.1
6+
Stable tag: 1.4.6
77
License: GPL-3.0
88
License URI: http://www.gnu.org/licenses/gpl-3.0.html
99

@@ -63,7 +63,8 @@ There is more information on our website at [https://wcpos.com](https://wcpos.co
6363

6464
== Changelog ==
6565

66-
= 1.4.6 - 2024/01/XX =
66+
= 1.4.6 - 2024/01/16 =
67+
* Fix: decimal quantity for orders
6768
* Fix: load translation files
6869

6970
= 1.4.5 - 2024/01/14 =

tests/includes/API/Test_Orders_Controller.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,4 +775,30 @@ public function test_order_search_by_billing_first_name_with_excludes() {
775775
$ids = wp_list_pluck( $data, 'id' );
776776
$this->assertEquals( array( $order2->get_id() ), $ids );
777777
}
778+
779+
/**
780+
*
781+
*/
782+
public function test_create_order_with_decimal_quantity() {
783+
$this->setup_decimal_quantity_tests();
784+
785+
$request = $this->wp_rest_post_request( '/wcpos/v1/orders' );
786+
$request->set_body_params(
787+
array(
788+
'payment_method' => 'pos_cash',
789+
'line_items' => array(
790+
array(
791+
'product_id' => 1,
792+
'quantity' => '1.5',
793+
),
794+
),
795+
)
796+
);
797+
798+
$response = $this->server->dispatch( $request );
799+
$data = $response->get_data();
800+
$this->assertEquals( 201, $response->get_status() );
801+
802+
$this->assertEquals( 'woocommerce-pos', $data['created_via'] );
803+
}
778804
}

woocommerce-pos.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: WooCommerce POS
44
* Plugin URI: https://wordpress.org/plugins/woocommerce-pos/
55
* Description: A simple front-end for taking WooCommerce orders at the Point of Sale. Requires <a href="http://wordpress.org/plugins/woocommerce/">WooCommerce</a>.
6-
* Version: 1.4.5.1
6+
* Version: 1.4.6
77
* Author: kilbot
88
* Author URI: http://wcpos.com
99
* Text Domain: woocommerce-pos

0 commit comments

Comments
 (0)