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:
parent
fa1ecf6e8b
commit
2c5d3d2acc
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: fix
|
||||||
|
|
||||||
|
Check order type is set before returning to prevent notice.
|
|
@ -948,7 +948,7 @@ WHERE
|
||||||
*/
|
*/
|
||||||
public function get_order_type( $order_id ) {
|
public function get_order_type( $order_id ) {
|
||||||
$type = $this->get_orders_type( array( $order_id ) );
|
$type = $this->get_orders_type( array( $order_id ) );
|
||||||
return $type[ $order_id ];
|
return $type[ $order_id ] ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -75,7 +75,7 @@ class COTMigrationUtil {
|
||||||
*/
|
*/
|
||||||
public function is_custom_order_tables_in_sync() : bool {
|
public function is_custom_order_tables_in_sync() : bool {
|
||||||
$sync_status = $this->data_synchronizer->get_sync_status();
|
$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.
|
* @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_id = $this->get_post_or_order_id( $order_id );
|
||||||
$order_data_store = \WC_Data_Store::load( 'order' );
|
$order_data_store = \WC_Data_Store::load( 'order' );
|
||||||
return $order_data_store->get_order_type( $order_id );
|
return $order_data_store->get_order_type( $order_id );
|
||||||
|
|
|
@ -1868,6 +1868,23 @@ class OrdersTableDataStoreTests extends WC_Unit_Test_Case {
|
||||||
$this->assertFalse( wc_get_order( $product->get_id() ) );
|
$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.
|
* @testDox Test that we are not duplicating address indexing when updating.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue