Update status only when its changed. (#38696)

This commit is contained in:
Ron Rennick 2023-06-14 16:50:09 -03:00 committed by GitHub
commit b0c06849a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Update status only when it's changed.

View File

@ -1816,8 +1816,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 );
}

View File

@ -2130,4 +2130,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'] );
}
}