Skip to content

Commit

Permalink
Rollback and log errors when orders are updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Dec 14, 2017
1 parent 276bff1 commit 1918e2e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions includes/class-wc-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public function payment_complete( $transaction_id = '' ) {
if ( ! $this->get_id() ) {
return false;
}

wc_transaction_query( 'start' );

do_action( 'woocommerce_pre_payment_complete', $this->get_id() );

if ( WC()->session ) {
Expand All @@ -126,12 +129,17 @@ public function payment_complete( $transaction_id = '' ) {
} 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;
}
Expand Down Expand Up @@ -298,14 +306,20 @@ public function update_status( $new_status, $note = '', $manual = false ) {
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;
}
Expand Down

0 comments on commit 1918e2e

Please sign in to comment.