Check before getting order classname to see if it exists. (#35207)

This commit is contained in:
Vedanshu Jain 2022-10-20 14:47:58 +05:30 committed by GitHub
parent 80cbb9dcdc
commit 8848e4aa47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Check whether order has classname before returning.

View File

@ -233,7 +233,7 @@ class WC_Order_Factory {
*/ */
private static function get_class_name_for_order_id( $order_id ) { private static function get_class_name_for_order_id( $order_id ) {
$classname = self::get_class_names_for_order_ids( array( $order_id ) ); $classname = self::get_class_names_for_order_ids( array( $order_id ) );
return $classname[ $order_id ]; return $classname[ $order_id ] ?? false;
} }
} }

View File

@ -1824,4 +1824,15 @@ class OrdersTableDataStoreTests extends WC_Unit_Test_Case {
$this->sut->read_multiple( $orders ); $this->sut->read_multiple( $orders );
$this->assertFalse( $should_sync_callable->call( $this->sut, $order ) ); $this->assertFalse( $should_sync_callable->call( $this->sut, $order ) );
} }
/**
* @testDox Make sure get_order return false when checking an order of different order types without warning.
*/
public function test_get_order_with_id_for_different_type() {
$this->toggle_cot( true );
$this->disable_cot_sync();
$product = new \WC_Product();
$product->save();
$this->assertFalse( wc_get_order( $product->get_id() ) );
}
} }