Projet

Général

Profil

Paste
Télécharger (3,59 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / commerce / modules / cart / includes / commerce_cart.checkout_pane.inc @ b858700c

1
<?php
2

    
3
/**
4
 * @file
5
 * Checkout pane callback functions for the cart module.
6
 */
7

    
8

    
9
/**
10
 * Checkout pane callback: returns the cart contents pane's settings form.
11
 */
12
function commerce_cart_contents_pane_settings_form($checkout_pane) {
13
  $form = array();
14

    
15
  // Build an options array of Views available for the cart contents pane.
16
  $options = array();
17

    
18
  // Generate an option list from all user defined and module defined Views,
19
  // excluding the core Commerce cart block / form and order listing Views.
20
  $exclude = array('commerce_cart_block', 'commerce_cart_form', 'commerce_orders', 'commerce_user_orders');
21
  $default = variable_get('commerce_cart_contents_pane_view', 'commerce_cart_summary|default');
22

    
23
  foreach (views_get_all_views() as $view_id => $view_value) {
24
    // Only include line item Views, including a View that may be excluded but
25
    // has already been set to be the selected View some other way. The list of
26
    // excluded Views was added in as of Commerce 1.5, so we want to preserve
27
    // existing selections much like we do for Price fields with currency select
28
    // lists whose currency may have been disabled since the price was entered.
29
    if ($view_value->base_table == 'commerce_order') {
30
      foreach ($view_value->display as $display_id => $display_value) {
31
        $key = $view_id . '|' . $display_id;
32

    
33
        if (!in_array($view_id, $exclude) || $key == $default) {
34
          $options[$view_id][$view_id . '|' . $display_id] = $display_value->display_title;
35
        }
36
      }
37
    }
38
  }
39

    
40
  $form['commerce_cart_contents_pane_view'] = array(
41
    '#type' => 'select',
42
    '#title' => t('Cart contents View'),
43
    '#description' => t('Specify the line item listing View to use in the cart contents pane. It should not include line item summary links or any Views form elements (e.g. quantity textfiedls or delete buttons).') . '<br />' . t('You are not allowed to use any default Views defined by core Commerce modules except the cart summary View.'),
44
    '#options' => $options,
45
    '#default_value' => $default,
46
  );
47

    
48
  return $form;
49
}
50

    
51
/**
52
 * Checkout pane callback: returns the cart contents View for inclusion in the
53
 *   checkout form.
54
 */
55
function commerce_cart_contents_pane_checkout_form($form, &$form_state, $checkout_pane, $order) {
56
  $pane_form = array();
57

    
58
  // Extract the View and display keys from the cart contents pane setting.
59
  list($view_id, $display_id) = explode('|', variable_get('commerce_cart_contents_pane_view', 'commerce_cart_summary|default'));
60

    
61
  $pane_form['cart_contents_view'] = array(
62
    '#markup' => commerce_embed_view($view_id, $display_id, array($order->order_id)),
63
  );
64

    
65
  // Attach the Cart and Price module CSS to accommodate the order total area
66
  // handler's CSS being reloaded properly on a form rebuild.
67
  $pane_form['cart_contents_views']['#attached']['css'][] = drupal_get_path('module', 'commerce_cart') . '/theme/commerce_cart.theme.css';
68
  $pane_form['cart_contents_views']['#attached']['css'][] = drupal_get_path('module', 'commerce_price') . '/theme/commerce_price.theme.css';
69

    
70
  return $pane_form;
71
}
72

    
73
/**
74
 * Checkout pane callback: returns the cart contents review data for the
75
 *   Review checkout pane.
76
 */
77
function commerce_cart_contents_pane_review($form, $form_state, $checkout_pane, $order) {
78
  drupal_add_css(drupal_get_path('module', 'commerce_cart') . '/theme/commerce_cart.theme.css');
79

    
80
  // Extract the View and display keys from the cart contents pane setting.
81
  list($view_id, $display_id) = explode('|', variable_get('commerce_cart_contents_pane_view', 'commerce_cart_summary|default'));
82

    
83
  return commerce_embed_view($view_id, $display_id, array($order->order_id));
84
}