Do not attempt to cache orders during order creation (#37569)
This commit is contained in:
commit
9e9060e95b
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: fix
|
||||||
|
|
||||||
|
Do not attempt to cache order during order creation (HPOS).
|
|
@ -218,7 +218,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
||||||
|
|
||||||
if ( OrderUtil::orders_cache_usage_is_enabled() ) {
|
if ( OrderUtil::orders_cache_usage_is_enabled() ) {
|
||||||
$order_cache = wc_get_container()->get( OrderCache::class );
|
$order_cache = wc_get_container()->get( OrderCache::class );
|
||||||
$order_cache->update_if_cached( $this );
|
$order_cache->remove( $this->get_id() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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->get_id(), $coupon_data['id'] );
|
||||||
$this->assertEquals( $coupon_code, $coupon_data['code'] );
|
$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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue