Do not attempt to cache orders during order creation (#37569)

This commit is contained in:
Vedanshu Jain 2023-04-05 20:49:57 +05:30 committed by GitHub
commit 9e9060e95b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Do not attempt to cache order during order creation (HPOS).

View File

@ -218,7 +218,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
if ( OrderUtil::orders_cache_usage_is_enabled() ) {
$order_cache = wc_get_container()->get( OrderCache::class );
$order_cache->update_if_cached( $this );
$order_cache->remove( $this->get_id() );
}
/**

View File

@ -269,4 +269,23 @@ class WC_Abstract_Order_Test extends WC_Unit_Test_Case {
$this->assertEquals( $coupon->get_id(), $coupon_data['id'] );
$this->assertEquals( $coupon_code, $coupon_data['code'] );
}
/**
* @testDox Cache does not interfere if wc_get_order returns a different class than WC_Order.
*/
public function test_cache_does_not_interferes_with_order_object() {
add_action(
'woocommerce_new_order',
function( $order_id ) {
// this makes the cache store a specific order class instance, but it's quickly replaced by a generic one
// as we're in the middle of a save and this gets executed before the logic in WC_Abstract_Order.
$order = wc_get_order( $order_id );
}
);
$order = new WC_Order();
$order->save();
$order = wc_get_order( $order->get_id() );
$this->assertInstanceOf( Automattic\WooCommerce\Admin\Overrides\Order::class, $order );
}
}