From 59bb1f8365dff43b5dd963bc3053ed1a5d7291ef Mon Sep 17 00:00:00 2001 From: Vedanshu Jain Date: Tue, 13 Jun 2023 21:12:03 +0530 Subject: [PATCH 1/2] Update status only when its changed. --- plugins/woocommerce/changelog/fix-35951 | 4 ++++ .../src/Internal/DataStores/Orders/OrdersTableDataStore.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-35951 diff --git a/plugins/woocommerce/changelog/fix-35951 b/plugins/woocommerce/changelog/fix-35951 new file mode 100644 index 00000000000..79e914c393e --- /dev/null +++ b/plugins/woocommerce/changelog/fix-35951 @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Update status only when it's changed. diff --git a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php index 2d25de0d9b3..ba48def3bcd 100644 --- a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php +++ b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php @@ -1738,8 +1738,8 @@ FROM $order_meta_table $changes['type'] = $order->get_type(); - // Make sure 'status' is correct. - if ( array_key_exists( 'status', $column_mapping ) ) { + // Make sure 'status' is correctly prefixed. + if ( array_key_exists( 'status', $column_mapping ) && array_key_exists( 'status', $changes ) ) { $changes['status'] = $this->get_post_status( $order ); } From 02a08e9e3bc75c4b675d753517edcf63e03783fe Mon Sep 17 00:00:00 2001 From: Vedanshu Jain Date: Wed, 14 Jun 2023 15:17:52 +0530 Subject: [PATCH 2/2] Add unit test for checking that status has the correct value. --- .../Orders/OrdersTableDataStoreTests.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreTests.php b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreTests.php index 23bcd9e8483..056b1c394ba 100644 --- a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreTests.php +++ b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreTests.php @@ -2132,4 +2132,20 @@ class OrdersTableDataStoreTests extends WC_Unit_Test_Case { $this->assertEquals( 1, $result ); } + + /** + * @testDox When saving an order, status is automatically prefixed even if it was not earlier. + */ + public function test_get_db_row_from_order_only_prefixed_status_is_written_to_db() { + $order = wc_create_order(); + + $order->set_status( 'completed' ); + $db_row_callback = function ( $order, $only_changes ) { + return $this->get_db_row_from_order( $order, $this->order_column_mapping, $only_changes ); + }; + + $db_row = $db_row_callback->call( $this->sut, $order, false ); + + $this->assertEquals( 'wc-completed', $db_row['data']['status'] ); + } }