Skip to content
Snippets Groups Projects

Issue #2609176: Prevent commerce_checkout_complete() to be fired more than once for the same order

1 file
+ 16
5
Compare changes
  • Side-by-side
  • Inline
@@ -972,15 +972,26 @@ function commerce_checkout_order_can_checkout($order) {
* Completes the checkout process for the given order.
*/
function commerce_checkout_complete($order) {
// An order could complete the checkout process more than once for a variety
// of reasons, including administrators making changes. We want to keep the
// timestamp from when the order was originally placed, so we don't update it
// if it is already set.
// Keep the timestamp from when the order was originally placed,
// so we don't update it if it is already set.
if (empty($order->placed)) {
$order->placed = REQUEST_TIME;
}
rules_invoke_all('commerce_checkout_complete', $order);
// Check to make sure the event hasn't been invoked for this order already.
// The checkout is expected to be completed only once, otherwise this may
// result in race conditions for example if the payment provider callback
// triggered this simultaneously:
if (empty($order->data['commerce_checkout_complete_invoked'])) {
// Update the order's data array to indicate this just happened.
$order->data['commerce_checkout_complete_invoked'] = TRUE;
// Save the updated order.
commerce_order_save($order);
// Invoke the event:
rules_invoke_all('commerce_checkout_complete', $order);
}
}
/**
Loading