Check order type is set before returning to prevent notice. (#35349)

* Check order type is set before returning to prevent notice.

* Applied code standards.

* Remove type declaration since its not consistent with CPT datastore.

* Switch to a yoda condition (satisfy required linting check).

Co-authored-by: barryhughes <3594411+barryhughes@users.noreply.github.com>
This commit is contained in:
Vedanshu Jain 2022-10-31 14:26:28 +05:30 committed by GitHub
parent fa1ecf6e8b
commit 2c5d3d2acc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 3 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Check order type is set before returning to prevent notice.

View File

@ -948,7 +948,7 @@ WHERE
*/
public function get_order_type( $order_id ) {
$type = $this->get_orders_type( array( $order_id ) );
return $type[ $order_id ];
return $type[ $order_id ] ?? '';
}
/**

View File

@ -75,7 +75,7 @@ class COTMigrationUtil {
*/
public function is_custom_order_tables_in_sync() : bool {
$sync_status = $this->data_synchronizer->get_sync_status();
return $sync_status['current_pending_count'] === 0 && $this->data_synchronizer->data_sync_is_enabled();
return 0 === $sync_status['current_pending_count'] && $this->data_synchronizer->data_sync_is_enabled();
}
/**
@ -160,7 +160,7 @@ class COTMigrationUtil {
*
* @return string|null Type of the order.
*/
public function get_order_type( $order_id ) : ?string {
public function get_order_type( $order_id ) {
$order_id = $this->get_post_or_order_id( $order_id );
$order_data_store = \WC_Data_Store::load( 'order' );
return $order_data_store->get_order_type( $order_id );

View File

@ -1868,6 +1868,23 @@ class OrdersTableDataStoreTests extends WC_Unit_Test_Case {
$this->assertFalse( wc_get_order( $product->get_id() ) );
}
/**
* @testDox Make sure that getting order type for non order return without warning.
*/
public function test_get_order_type_for_non_order() {
$product = WC_Helper_Product::create_simple_product();
$product->save();
$this->assertEquals( '', $this->sut->get_order_type( $product->get_id() ) );
}
/**
* @testDox Test get order type working as expected.
*/
public function test_get_order_type_for_order() {
$order = $this->create_complex_cot_order();
$this->assertEquals( 'shop_order', $this->sut->get_order_type( $order->get_id() ) );
}
/**
* @testDox Test that we are not duplicating address indexing when updating.
*/