You are here

function commerce_paypal_ec_review_pane_checkout_form in Commerce PayPal 7.2

Checkout pane callback: returns a pane allowing the customer to review the final details of the order and provide any final information required.

File

modules/ec/includes/commerce_paypal_ec.checkout_pane.inc, line 56
Checkout pane callback functions for the PayPal Express Checkout module.

Code

function commerce_paypal_ec_review_pane_checkout_form(&$form, &$form_state, $checkout_pane, $order) {
  $form_state['build_info']['files']['pane'] = drupal_get_path('module', 'commerce_paypal_ec') . '/includes/commerce_paypal_ec.checkout_pane.inc';
  $form_state['order'] = $order;

  // Adjust the weights of the help text and pane form to appear before the
  // embedded checkout panes.
  $form['help']['#weight'] = -10;
  $pane_form = array(
    '#weight' => -5,
  );

  // Duplicate the review checkout pane's contents.
  $pane_form['review'] = array(
    '#theme' => 'commerce_checkout_review',
    '#data' => array(),
  );

  // Loop through all the pages before the review page...
  foreach (commerce_checkout_pages() as $page_id => $checkout_page) {

    // Exit the loop once the review page is reached.
    if ($page_id == 'review') {
      break;
    }

    // Loop through all the panes on the current page specifying review...
    foreach (commerce_checkout_panes(array(
      'page' => $page_id,
      'enabled' => TRUE,
      'review' => TRUE,
    )) as $pane_id => $checkout_pane_local) {

      // If the pane has a valid review callback...
      if ($callback = commerce_checkout_pane_callback($checkout_pane_local, 'review')) {

        // Get the review data for this pane.
        $pane_data = $callback($form, $form_state, $checkout_pane_local, $order);

        // Only display the pane if there is data in the pane.
        if (!empty($pane_data)) {

          // Add a row for it in the review data.
          $pane_form['review']['#data'][$pane_id] = array(
            'title' => $checkout_pane_local['title'],
            'data' => $pane_data,
          );
        }
      }
    }
  }

  // Embed other specified checkout panes in this checkout pane.
  foreach (commerce_paypal_ec_embedded_checkout_panes() as $embedded_pane_id) {
    $embedded_pane = commerce_checkout_pane_load($embedded_pane_id);

    // If the checkout pane defines a checkout form callback...
    if ($embedded_pane && ($callback = commerce_checkout_pane_callback($embedded_pane, 'checkout_form'))) {

      // Get the form for the embedded checkout pane.
      $embedded_pane_form = $callback($form, $form_state, $embedded_pane, $order);

      // Embed it on this checkout pane if the form returned data.
      if (!empty($embedded_pane_form)) {
        $form[$embedded_pane_id] = array(
          '#type' => $embedded_pane['fieldset'] ? 'fieldset' : 'container',
          '#title' => check_plain($embedded_pane['title']),
          '#collapsible' => $embedded_pane['collapsible'],
          '#collapsed' => $embedded_pane['collapsed'],
          '#attributes' => array(
            'class' => array(
              $embedded_pane_id,
            ),
          ),
          '#tree' => TRUE,
        ) + $embedded_pane_form;
      }
    }
  }
  $form['pay_now'] = array(
    '#type' => 'submit',
    '#value' => t('Pay Now'),
    '#validate' => array(
      'commerce_paypal_ec_review_pane_checkout_form_validate',
    ),
    '#submit' => array(
      'commerce_paypal_ec_review_pane_checkout_form_submit',
    ),
  );
  return $pane_form;
}