You are here

function commerce_checkout_panes in Commerce Core 7

Return a filtered array of checkout pane objects.

Parameters

$conditions: An array of conditions to filter the returned list by; for example, if you specify 'enabled' => TRUE in the array, then only checkout panes with an enabled value equal to TRUE would be included.

$skip_saved_data: A boolean that will allow the retrieval of checkout panes directly from code. Specifically, it will skip the cache and also prevent configured checkout panes data from merging.

Return value

The array of checkout pane objects, keyed by pane ID.

8 calls to commerce_checkout_panes()
CommerceCheckoutTestProcess::testCommerceCheckoutValidatePanesAnonymousUser in modules/checkout/tests/commerce_checkout.test
Test the checkout validation panes with anonymous user.
commerce_checkout_builder_form in modules/checkout/includes/commerce_checkout.admin.inc
Build the checkout form builder, adding in data for the checkout pages and the appropriate fields to enable tabledrag on the checkout panes.
commerce_checkout_builder_form_validate in modules/checkout/includes/commerce_checkout.admin.inc
Validation handler for the checkout builder form.
commerce_checkout_form in modules/checkout/includes/commerce_checkout.pages.inc
Builds the checkout form for the given order on the specified checkout page.
commerce_checkout_form_validate in modules/checkout/includes/commerce_checkout.pages.inc
Validate handler for the continue button of the checkout form.

... See full list

2 string references to 'commerce_checkout_panes'
commerce_checkout_panes_reset in modules/checkout/commerce_checkout.module
Resets the cached list of checkout panes.
commerce_customer_field_delete_instance in modules/customer/commerce_customer.module
Implements hook_field_delete_instance().

File

modules/checkout/commerce_checkout.module, line 535
Enable checkout as a multi-step form with customizable pages and a simple checkout pane API.

Code

function commerce_checkout_panes($conditions = array(), $skip_saved_data = FALSE) {
  if (!$skip_saved_data) {
    $checkout_panes =& drupal_static(__FUNCTION__);
  }

  // Cache the saved checkout pane data if it hasn't been loaded yet.
  if (!isset($checkout_panes)) {
    if (!$skip_saved_data) {
      $saved_panes = db_query('SELECT * FROM {commerce_checkout_pane}')
        ->fetchAllAssoc('pane_id', PDO::FETCH_ASSOC);
    }

    // Load panes defined by modules.
    $checkout_panes = array();
    foreach (module_implements('commerce_checkout_pane_info') as $module) {
      foreach (module_invoke($module, 'commerce_checkout_pane_info') as $pane_id => $checkout_pane) {
        $checkout_pane['pane_id'] = $pane_id;
        $checkout_pane['module'] = $module;

        // Update the pane with saved data.
        if (!$skip_saved_data && !empty($saved_panes[$pane_id])) {
          $checkout_pane = array_merge($checkout_pane, $saved_panes[$pane_id]);
          $checkout_pane['saved'] = TRUE;
        }
        $checkout_panes[$pane_id] = $checkout_pane;
      }
    }
    drupal_alter('commerce_checkout_pane_info', $checkout_panes);

    // Merge in defaults.
    foreach ($checkout_panes as $pane_id => $checkout_pane) {

      // Set some defaults for the checkout pane.
      $defaults = array(
        'base' => $pane_id,
        'name' => $checkout_pane['title'],
        'page' => 'checkout',
        'locked' => FALSE,
        'fieldset' => TRUE,
        'collapsible' => FALSE,
        'collapsed' => FALSE,
        'weight' => 0,
        'enabled' => TRUE,
        'review' => TRUE,
        'callbacks' => array(),
        'file' => '',
      );
      $checkout_pane += $defaults;

      // Merge in default callbacks.
      foreach (array(
        'settings_form',
        'checkout_form',
        'checkout_form_validate',
        'checkout_form_submit',
        'review',
      ) as $callback) {
        if (!isset($checkout_pane['callbacks'][$callback])) {
          $checkout_pane['callbacks'][$callback] = $checkout_pane['base'] . '_' . $callback;
        }
      }
      $checkout_panes[$pane_id] = $checkout_pane;
    }

    // Sort the panes by their weight value.
    uasort($checkout_panes, 'drupal_sort_weight');
  }

  // Apply conditions to the returned panes if specified.
  if (!empty($conditions)) {
    $matching_panes = array();
    foreach ($checkout_panes as $pane_id => $checkout_pane) {

      // Check the pane against the conditions array to determine whether to add
      // it to the return array or not.
      $valid = TRUE;
      foreach ($conditions as $property => $value) {

        // If the current value for the specified property on the pane does not
        // match the filter value...
        if (!isset($checkout_pane[$property]) || $checkout_pane[$property] != $value) {

          // Do not add it to the temporary array.
          $valid = FALSE;
        }
      }
      if ($valid) {
        $matching_panes[$pane_id] = $checkout_pane;
      }
    }
    return $matching_panes;
  }
  return $checkout_panes;
}