You are here

function commerce_checkout_form_submit in Commerce Core 7

Submit handler for the continue button of the checkout form.

1 string reference to 'commerce_checkout_form_submit'
commerce_checkout_form in modules/checkout/includes/commerce_checkout.pages.inc
Builds the checkout form for the given order on the specified checkout page.

File

modules/checkout/includes/commerce_checkout.pages.inc, line 377
The page and form callbacks for use in the checkout form.

Code

function commerce_checkout_form_submit($form, &$form_state) {
  $checkout_page = $form_state['checkout_page'];

  // Load a fresh copy of the order stored in the form.
  $order = commerce_order_load($form_state['order']->order_id);

  // If we are going to redirect with checkout pane messages stored in the form
  // state, they will not be displayed on a subsequent form build like normal.
  // Move them out of the form state messages array and into the current
  // session's general message array instead.
  if (!empty($form_state['storage']['messages'])) {
    foreach ($form_state['storage']['messages'] as $pane_id => $pane_messages) {
      $_SESSION['messages'] = array_merge_recursive($_SESSION['messages'], $pane_messages);
    }
  }

  // If the form was submitted via the continue button...
  if (end($form_state['triggering_element']['#array_parents']) == 'continue') {

    // If there is another checkout page...
    if ($checkout_page['next_page']) {

      // Update the order status to reflect the next checkout page.
      $order = commerce_order_status_update($order, 'checkout_' . $checkout_page['next_page'], FALSE, NULL, t('Customer continued to the next checkout page via a submit button.'));

      // If it happens to be the complete page, process completion now.
      if ($checkout_page['next_page'] == 'complete') {
        commerce_checkout_complete($order);
      }

      // Redirect to the next checkout page.
      $form_state['redirect'] = 'checkout/' . $order->order_id . '/' . $checkout_page['next_page'];
    }
  }
}