You are here

function uc_cart_checkout_form in Ubercart 7.3

Same name and namespace in other branches
  1. 5 uc_cart/uc_cart.module \uc_cart_checkout_form()
  2. 6.2 uc_cart/uc_cart.pages.inc \uc_cart_checkout_form()

The checkout form built up from the enabled checkout panes.

Parameters

$order: The order that is being checked out.

See also

uc_cart_checkout_form_process()

uc_cart_checkout_form_validate()

uc_cart_checkout_form_submit()

uc_cart_checkout_review()

theme_uc_cart_checkout_form()

3 string references to 'uc_cart_checkout_form'
uc_ajax_process_form in uc_store/includes/uc_ajax_attach.inc
Form process callback to allow multiple Ajax callbacks on form elements.
uc_cart_checkout in uc_cart/uc_cart.pages.inc
Displays the cart checkout page built of checkout panes from enabled modules.
_uc_ajax_admin_build_checkout_form in uc_ajax_admin/uc_ajax_admin.module
Builds the checkout form, using the cart order if it exists, or a default shippable order if not.

File

uc_cart/uc_cart.pages.inc, line 192
Cart menu items.

Code

function uc_cart_checkout_form($form, &$form_state, $order) {
  if ($processed = isset($form_state['storage']['order'])) {
    $order = $form_state['storage']['order'];
  }
  else {
    $form_state['storage']['order'] = $order;
    $form_state['storage']['base_path'] = implode('/', array_slice(arg(), 0, -1));
  }
  $form['#attributes']['class'][] = 'uc-cart-checkout-form';
  $form['#attached']['js'][] = drupal_get_path('module', 'uc_cart') . '/uc_cart.js';
  $form['#attached']['css'][] = drupal_get_path('module', 'uc_cart') . '/uc_cart.css';
  if ($instructions = variable_get('uc_checkout_instructions', '')) {
    $form['instructions'] = array(
      '#prefix' => '<div id="checkout-instructions">',
      '#markup' => filter_xss_admin($instructions),
      '#suffix' => '</div>',
    );
  }
  $form['panes'] = array(
    '#tree' => TRUE,
  );
  $panes = _uc_checkout_pane_list();

  // If the order isn't shippable, remove panes with shippable == TRUE.
  if (!uc_order_is_shippable($order) && variable_get('uc_cart_delivery_not_shippable', TRUE)) {
    $panes = uc_cart_filter_checkout_panes($panes, array(
      'shippable' => TRUE,
    ));
  }

  // Invoke the 'prepare' op of enabled panes, but only if their 'process' ops
  // have not been invoked on this request (i.e. when rebuilding after AJAX).
  foreach ($panes as $id => $pane) {
    if ($pane['enabled'] && empty($form_state['storage']['panes'][$id]['prepared']) && isset($pane['callback']) && function_exists($pane['callback'])) {
      $pane['callback']('prepare', $order, $form, $form_state);
      $form_state['storage']['panes'][$id]['prepared'] = TRUE;
      $processed = FALSE;

      // Make sure we save the updated order.
    }
  }

  // Load the line items and save the order. We do this after the 'prepare'
  // callbacks of enabled panes have been invoked, because these may have
  // altered the order.
  if (!$processed) {
    $order->line_items = uc_order_load_line_items($order);
    uc_order_save($order);
  }
  foreach ($panes as $id => $pane) {
    if ($pane['enabled']) {
      $pane['prev'] = _uc_cart_checkout_prev_pane($panes, $id);
      $pane['next'] = _uc_cart_checkout_next_pane($panes, $id);
      if (!isset($pane['collapsed'])) {
        $collapsed = $pane['prev'] === FALSE || empty($displayed[$pane['prev']]) ? FALSE : TRUE;
      }
      if (isset($form_state['expanded_panes']) && in_array($id, $form_state['expanded_panes'])) {
        $collapsed = FALSE;
      }
      $return = $pane['callback']('view', $order, $form, $form_state);

      // Add the pane if any display data is returned from the callback.
      if (is_array($return) && (!empty($return['description']) || !empty($return['contents']))) {

        // Create the fieldset for the pane.
        $form['panes'][$id] = array(
          '#type' => 'fieldset',
          '#title' => check_plain($pane['title']),
          '#description' => !empty($return['description']) ? $return['description'] : '',
          '#collapsible' => $pane['collapsible'] && variable_get('uc_use_next_buttons', FALSE),
          '#collapsed' => variable_get('uc_use_next_buttons', FALSE) ? $collapsed : FALSE,
          '#id' => $id . '-pane',
          '#theme' => isset($return['theme']) ? $return['theme'] : NULL,
        );

        // Add the contents of the fieldset if any were returned.
        if (!empty($return['contents'])) {
          $form['panes'][$id] = array_merge($form['panes'][$id], $return['contents']);
        }

        // Add the 'Next' button if necessary.
        if ((!isset($return['next-button']) || $return['next-button'] !== FALSE) && $pane['next'] !== FALSE && variable_get('uc_use_next_buttons', FALSE) != FALSE) {
          $opt = variable_get('uc_collapse_current_pane', FALSE) ? $id : 'false';
          $form['panes'][$id]['next'] = array(
            '#type' => 'button',
            '#value' => t('Next'),
            '#weight' => 20,
            '#attributes' => array(
              'onclick' => "return uc_cart_next_button_click(this, '" . $pane['next'] . "', '" . $opt . "');",
            ),
            '#prefix' => '<div class="next-button">',
            '#suffix' => '</div>',
          );
        }

        // Log that this pane was actually displayed.
        $displayed[$id] = TRUE;
      }
    }
  }
  unset($form_state['expanded_panes']);
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
    '#validate' => array(),
    // Disable validation to prevent a new order
    // from being created.
    '#limit_validation_errors' => array(),
    '#submit' => array(
      'uc_cart_checkout_form_cancel',
    ),
  );
  $form['actions']['continue'] = array(
    '#type' => 'submit',
    '#value' => t('Review order'),
  );
  form_load_include($form_state, 'inc', 'uc_store', 'includes/uc_ajax_attach');
  $form['#process'][] = 'uc_ajax_process_form';
  unset($_SESSION['uc_checkout'][$order->order_id]);
  return $form;
}