Rollback and log errors when orders are updated.

This commit is contained in:
Mike Jolley 2017-12-14 16:00:38 +00:00
parent 276bff133f
commit 1918e2e554
1 changed files with 14 additions and 0 deletions

View File

@ -106,6 +106,9 @@ class WC_Order extends WC_Abstract_Order {
if ( ! $this->get_id() ) {
return false;
}
wc_transaction_query( 'start' );
do_action( 'woocommerce_pre_payment_complete', $this->get_id() );
if ( WC()->session ) {
@ -126,12 +129,17 @@ class WC_Order extends WC_Abstract_Order {
} else {
do_action( 'woocommerce_payment_complete_order_status_' . $this->get_status(), $this->get_id() );
}
wc_transaction_query( 'commit' );
} catch ( Exception $e ) {
wc_transaction_query( 'rollback' );
$logger = wc_get_logger();
$logger->error( sprintf( 'Payment complete of order #%d failed!', $this->get_id() ), array(
'order' => $this,
'error' => $e,
) );
$this->add_order_note( __( 'Payment complete event failed.', 'woocommerce' ) . ' ' . $e->getMessage() );
return false;
}
@ -298,14 +306,20 @@ class WC_Order extends WC_Abstract_Order {
if ( ! $this->get_id() ) {
return false;
}
wc_transaction_query( 'start' );
$this->set_status( $new_status, $note, $manual );
$this->save();
wc_transaction_query( 'commit' );
} catch ( Exception $e ) {
wc_transaction_query( 'rollback' );
$logger = wc_get_logger();
$logger->error( sprintf( 'Update status of order #%d failed!', $this->get_id() ), array(
'order' => $this,
'error' => $e,
) );
$this->add_order_note( __( 'Update status event failed.', 'woocommerce' ) . ' ' . $e->getMessage() );
return false;
}