Projet

Général

Profil

Révision 280fe687

Ajouté par Assos Assos il y a plus de 8 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/commerce/.gitignore
4 4
*.kpf
5 5
*.swp
6 6
*.swo
7
.idea*
8

  
drupal7/sites/all/modules/commerce/commerce.api.php
177 177
function hook_commerce_entity_create_alter($entity_type, $entity) {
178 178
  // No example.
179 179
}
180

  
181
/**
182
 * Allows modules to alter the default currency.
183
 *
184
 * @param $currency_code
185
 *   The default currency code.
186
 *
187
 * @see commerce_default_currency()
188
 */
189
function hook_commerce_default_currency_alter(&$currency_code) {
190
  global $language;
191
  if (isset($language->language) && $language->language == 'en-US') {
192
    $currency_code = 'USD';
193
  }
194
}
drupal7/sites/all/modules/commerce/commerce.info
12 12
; Central Entity Controller.
13 13
files[] = includes/commerce.controller.inc
14 14

  
15
; Information added by Drupal.org packaging script on 2015-01-16
16
version = "7.x-1.11"
15
; Information added by Drupal.org packaging script on 2016-04-06
16
version = "7.x-1.13"
17 17
core = "7.x"
18 18
project = "commerce"
19
datestamp = "1421426596"
19
datestamp = "1459956613"
20 20

  
drupal7/sites/all/modules/commerce/commerce.module
470 470
 * Returns the currency code of the site's default currency.
471 471
 */
472 472
function commerce_default_currency() {
473
  return variable_get('commerce_default_currency', 'USD');
473
  $currency_code = variable_get('commerce_default_currency', 'USD');
474
  drupal_alter('commerce_default_currency', $currency_code);
475
  return $currency_code;
474 476
}
475 477

  
476 478
/**
......
950 952
    }
951 953
    else {
952 954
      // Otherwise add the child element with its simple value.
953
      $simplexml_element->addChild("$key", "$value");
955
      $simplexml_element->addChild("$key", htmlspecialchars($value, ENT_QUOTES, 'UTF-8', FALSE));
954 956
    }
955 957
  }
956 958
}
......
987 989
        return (bool) $query
988 990
          ->addTag($entity_info['access arguments']['access tag'])
989 991
          ->addMetaData('account', $account)
992
          ->addMetaData('entity', $entity)
990 993
          ->condition($entity_info['entity keys']['id'], $entity->{$entity_info['entity keys']['id']})
991 994
          ->range(0, 1)
992 995
          ->execute()
......
1239 1242

  
1240 1243
  $context = array(
1241 1244
    'account' => $account,
1245
    'entity' => $query->getMetaData('entity'),
1242 1246
    'entity_type' => $entity_type,
1243 1247
    'base_table' => $base_table
1244 1248
  );
drupal7/sites/all/modules/commerce/commerce_ui.info
4 4
dependencies[] = commerce
5 5
core = 7.x
6 6

  
7
; Information added by Drupal.org packaging script on 2015-01-16
8
version = "7.x-1.11"
7
; Information added by Drupal.org packaging script on 2016-04-06
8
version = "7.x-1.13"
9 9
core = "7.x"
10 10
project = "commerce"
11
datestamp = "1421426596"
11
datestamp = "1459956613"
12 12

  
drupal7/sites/all/modules/commerce/includes/commerce.currency.inc
219 219
    ),
220 220
    'CAD' => array(
221 221
      'code' => 'CAD',
222
      'symbol' => 'CA$',
222
      'symbol' => '$',
223 223
      'name' => t('Canadian Dollar'),
224 224
      'numeric_code' => '124',
225 225
      'minor_unit' => t('Cent'),
......
1147 1147
    ),
1148 1148
    'TRY' => array(
1149 1149
      'code' => 'TRY',
1150
      'symbol' => 'TL',
1150
      'symbol' => '',
1151 1151
      'name' => t('Turkish Lira'),
1152 1152
      'numeric_code' => '949',
1153 1153
      'thousands_separator' => '.',
drupal7/sites/all/modules/commerce/modules/cart/commerce_cart.api.php
100 100
  // No example.
101 101
}
102 102

  
103
/**
104
 * Allows modules to perform processing on a shopping cart order prior to the
105
 * logic in commerce_cart_order_refresh() taking place.
106
 *
107
 * @param $order_wrapper
108
 *   The entity metadata wrapper for the order about to be refreshed.
109
 *
110
 * @see commerce_cart_order_refresh()
111
 * @see entity_metadata_wrapper()
112
 */
113
function hook_commerce_cart_order_pre_refresh($order_wrapper) {
114
  // No example.
115
}
116

  
103 117
/**
104 118
 * Allows modules to perform additional processing to refresh an individual line
105 119
 * item on a shopping cart order.
drupal7/sites/all/modules/commerce/modules/cart/commerce_cart.info
15 15

  
16 16
; Views handlers
17 17
files[] = includes/views/handlers/commerce_cart_handler_field_add_to_cart_form.inc
18
files[] = includes/views/handlers/commerce_cart_handler_field_edit_attributes.inc
18 19
files[] = includes/views/handlers/commerce_cart_plugin_argument_default_current_cart_order_id.inc
19 20
files[] = includes/views/handlers/commerce_cart_handler_area_empty_text.inc
20 21

  
21 22
; Simple tests
22 23
files[] = tests/commerce_cart.test
23 24

  
24
; Information added by Drupal.org packaging script on 2015-01-16
25
version = "7.x-1.11"
25
; Information added by Drupal.org packaging script on 2016-04-06
26
version = "7.x-1.13"
26 27
core = "7.x"
27 28
project = "commerce"
28
datestamp = "1421426596"
29
datestamp = "1459956613"
29 30

  
drupal7/sites/all/modules/commerce/modules/cart/commerce_cart.module
334 334
  $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $form_state['line_items'][$line_item_id]);
335 335

  
336 336
  // If the deleted line item is a product...
337
  if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {
337
  if (in_array($line_item_wrapper->getBundle(), commerce_product_line_item_types())) {
338 338
    $title = $line_item_wrapper->commerce_product->title->value();
339 339
  }
340 340
  else {
......
1065 1065
function commerce_cart_order_refresh($order) {
1066 1066
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
1067 1067

  
1068
  // Allow other modules to act on the order prior to the refresh logic.
1069
  module_invoke_all('commerce_cart_order_pre_refresh', $order);
1070

  
1068 1071
  // Loop over every line item on the order...
1069 1072
  $line_item_changed = FALSE;
1070 1073

  
......
1130 1133
        $data['components'] = $current_data['components'];
1131 1134
        $line_item_wrapper->commerce_unit_price->data = $data;
1132 1135

  
1133
        // Save the updated line item and clear the entity cache.
1136
        // Save the updated line item.
1134 1137
        commerce_line_item_save($line_item_wrapper->value());
1135
        entity_get_controller('commerce_line_item')->resetCache(array($line_item_wrapper->line_item_id->value()));
1136 1138

  
1137 1139
        $line_item_changed = TRUE;
1138 1140
      }
......
1317 1319
  $quantity = $line_item->quantity;
1318 1320

  
1319 1321
  // Invoke the product prepare event with the shopping cart order.
1320
  rules_invoke_all('commerce_cart_product_prepare', $order, $product, $line_item->quantity);
1322
  rules_invoke_all('commerce_cart_product_prepare', $order, $product, $quantity);
1321 1323

  
1322 1324
  // Determine if the product already exists on the order and increment its
1323 1325
  // quantity instead of adding a new line if it does.
......
1382 1384

  
1383 1385
    commerce_line_item_save($matching_line_item);
1384 1386

  
1385
    // Clear the line item cache so the updated quantity will be available to
1386
    // the ensuing load instead of the original quantity as loaded above.
1387
    entity_get_controller('commerce_line_item')->resetCache(array($matching_line_item->line_item_id));
1388

  
1389 1387
    // Update the line item variable for use in the invocation and return value.
1390 1388
    $line_item = $matching_line_item;
1391 1389
  }
......
2336 2334
          $replacement_class,
2337 2335
        );
2338 2336

  
2339
        // Theme the product extra field to $element.
2340
        $variables = array(
2341
          $product_extra_field_name => $product->{$product_extra_field_name},
2342
          'label' => $product_extra_field['label'] . ':',
2343
          'product' => $product,
2344
        );
2345

  
2337
        // Build the product extra field to $element.
2346 2338
        $element = array(
2347
          '#markup' => theme($product_extra_field['theme'], $variables),
2339
          '#theme' => $product_extra_field['theme'],
2340
          '#' . $product_extra_field_name => $product->{$product_extra_field_name},
2341
          '#label' => $product_extra_field['label'] . ':',
2342
          '#product' => $product,
2348 2343
          '#attached' => array(
2349 2344
            'css' => array(drupal_get_path('module', 'commerce_product') . '/theme/commerce_product.theme.css'),
2350 2345
          ),
......
2368 2363
  return array('#type' => 'ajax', '#commands' => $commands);
2369 2364
}
2370 2365

  
2366
/**
2367
 * Ajax callback: returns AJAX commands when an attribute widget is changed on
2368
 * the Views powered shopping cart form.
2369
 */
2370
function commerce_cart_add_to_cart_views_form_refresh($form, $form_state) {
2371
  $commands[] = array();
2372

  
2373
  // Extract the View from the form's arguments and derive its DOM ID class.
2374
  $view = $form_state['build_info']['args'][0];
2375
  $dom_id_class = drupal_html_class('view-dom-id-' . $view->dom_id);
2376

  
2377
  // Unset the form related variables from the $_POST array. Otherwise, when we
2378
  // rebuild the View, the Views form will fetch these values to rebuild the
2379
  // form state and resubmit the form.
2380
  foreach (array('form_build_id', 'form_token', 'form_id') as $key) {
2381
    unset($_POST[$key]);
2382
  }
2383

  
2384
  // Render afresh the the output of the View and return it for replacement.
2385
  $output = commerce_embed_view($view->name, $view->current_display, $view->args, $view->override_url);
2386
  $commands[] = ajax_command_replace('.' . $dom_id_class, $output);
2387

  
2388
  return array('#type' => 'ajax', '#commands' => $commands);
2389
}
2390

  
2371 2391
/**
2372 2392
 * Form submit handler: add the selected product to the cart.
2373 2393
 */
......
2553 2573
    );
2554 2574

  
2555 2575
    if (count(commerce_product_line_item_types()) > 1) {
2556
      $summary[] = t('Add to Cart line item type: @type', array('@type' => commerce_line_item_type_get_name($settings['line_item_type'])));
2576
      $type = !empty($settings['line_item_type']) ? $settings['line_item_type'] : 'product';
2577
      $summary[] = t('Add to Cart line item type: @type', array('@type' => commerce_line_item_type_get_name($type)));
2557 2578
    }
2558 2579
  }
2559 2580

  
drupal7/sites/all/modules/commerce/modules/cart/includes/views/commerce_cart.views.inc
29 29
      'handler' => 'commerce_cart_handler_area_empty_text',
30 30
    ),
31 31
  );
32

  
33
  // Add an edit handler for cart line item attributes.
34
  $data['commerce_line_item']['edit_attributes'] = array(
35
    'field' => array(
36
      'title' => t('Attribute field widgets'),
37
      'help' => t('Renders attribute field widgets for customers to edit from the View.'),
38
      'handler' => 'commerce_cart_handler_field_edit_attributes',
39
    ),
40
  );
32 41
}
33 42

  
34 43
/**
drupal7/sites/all/modules/commerce/modules/cart/includes/views/handlers/commerce_cart_handler_field_edit_attributes.inc
1
<?php
2

  
3
/**
4
 * @file
5
 * Field handler to render attribute widgets to select a different product for
6
 * the line item.
7
 */
8

  
9
class commerce_cart_handler_field_edit_attributes extends views_handler_field {
10

  
11
  /**
12
   * Overrides views_handler_field::construct().
13
   */
14
  function construct() {
15
    parent::construct();
16
    $this->additional_fields['line_item_id'] = 'line_item_id';
17

  
18
    // Set real_field in order to make it generate a field_alias.
19
    $this->real_field = 'line_item_id';
20
  }
21

  
22
  /**
23
   * Overrides views_handler_field::render().
24
   */
25
  function render($values) {
26
    // Render the field as a placeholder for eventual Views form replacement.
27
    return '<!--form-item-' . $this->options['id'] . '--' . $this->view->row_index . '-->';
28
  }
29

  
30
  /**
31
   * Returns the form which replaces the placeholder from render().
32
   */
33
  function views_form(&$form, &$form_state) {
34
    // The view is empty, abort.
35
    if (empty($this->view->result)) {
36
      return;
37
    }
38

  
39
    $form[$this->options['id']] = array(
40
      '#tree' => TRUE,
41
    );
42

  
43
    // At this point, the query has already been run, so we can access the
44
    // results in order to get the base key value (for example, nid for nodes).
45
    foreach ($this->view->result as $row_id => $row) {
46
      // Load the line item and generate a form ID based on its context data.
47
      $line_item = commerce_line_item_load($this->get_value($row, 'line_item_id'));
48
      $product_ids = commerce_cart_add_to_cart_form_product_ids($line_item);
49
      $form_id = commerce_cart_add_to_cart_form_id($product_ids);
50

  
51
      // Ensure the current line item is a product line item.
52
      if (!in_array($line_item->type, commerce_product_line_item_types())) {
53
        continue;
54
      }
55

  
56
      // Fetch the Add to Cart form and put the attributes section into this
57
      // field's part of the form if it exists.
58
      $subform_state = $form_state;
59
      $subform_state['build_info'] = array(
60
        'form_id' => $form_id,
61
        'base_form_id' => 'commerce_cart_add_to_cart_form',
62
        'args' => array($line_item),
63
      );
64

  
65
      // If the form has been submitted, copy the attributes values from the
66
      // edit_attributes sub-array to the top level of the submitted values
67
      // array so the selected product can be properly matched when the Add to
68
      // Cart form builds itself.
69
      if (!empty($form_state['values']['edit_attributes'][$row_id])) {
70
        $subform_state['values'] += $form_state['values']['edit_attributes'][$row_id];
71
      }
72

  
73
      $subform = array();
74
      $subform = commerce_cart_add_to_cart_form($subform, $subform_state, $line_item);
75

  
76
      // If an Ajax refresh resulted in an updated product ID, update the line
77
      // item accordingly and rebuild the subform. Note that for line items
78
      // that group products such that a product select list is required, we
79
      // have to fetch the current product ID differently than if it is stored
80
      // in a hidden form field.
81
      $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
82

  
83
      if (!empty($subform['product_id'])) {
84
        $product_id = NULL;
85

  
86
        if (in_array($subform['product_id']['#type'], array('hidden', 'value'))) {
87
          $product_id = $subform['product_id']['#value'];
88
        }
89
        else {
90
          $product_id = $subform['product_id']['#default_value'];
91
        }
92

  
93
        if (isset($product_id) && $product_id != $line_item_wrapper->commerce_product->raw()) {
94
          $line_item_wrapper->commerce_product = $product_id;
95
          commerce_line_item_save($line_item);
96
          commerce_cart_order_refresh($line_item->order_id);
97

  
98
          // Rebuild the subform array.
99
          $subform_state = $form_state;
100
          $subform_state['build_info'] = array(
101
            'form_id' => $form_id,
102
            'base_form_id' => 'commerce_cart_add_to_cart_form',
103
            'args' => array($line_item),
104
          );
105

  
106
          $subform = array();
107
          $subform = commerce_cart_add_to_cart_form($subform, $subform_state, $line_item);
108
        }
109
      }
110

  
111
      // Initialize the element representing the attribute fields in the form.
112
      $form[$this->options['id']][$row_id] = array();
113
      $element = &$form[$this->options['id']][$row_id];
114
      $element['#line_item'] = $line_item->line_item_id;
115

  
116
      foreach (array('attributes', 'unchanged_attributes', 'product_id') as $name) {
117
        if (!empty($subform[$name])) {
118
          $element[$name] = $subform[$name];
119

  
120
          if (!empty($element[$name]['#ajax']['callback'])) {
121
            $element[$name]['#ajax']['callback'] = 'commerce_cart_add_to_cart_views_form_refresh';
122
          }
123

  
124
          foreach (element_children($element[$name]) as $key) {
125
            if (!empty($element[$name][$key]['#ajax']['callback'])) {
126
              $element[$name][$key]['#ajax']['callback'] = 'commerce_cart_add_to_cart_views_form_refresh';
127
            }
128
          }
129
        }
130
      }
131
    }
132
  }
133
}
drupal7/sites/all/modules/commerce/modules/cart/tests/commerce_cart.test
132 132
    $this->assertTrue(commerce_cart_order_is_cart($order), t('User has currently an order in cart status.'));
133 133
    // Get the products out of the order and store them in an array.
134 134
    foreach (entity_metadata_wrapper('commerce_order', $order)->commerce_line_items as $delta => $line_item_wrapper) {
135
       if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {
135
       if (in_array($line_item_wrapper->getBundle(), commerce_product_line_item_types())) {
136 136
         $product = $line_item_wrapper->commerce_product->value();
137 137
         $products[$product->product_id]= $product;
138 138
       }
......
302 302

  
303 303
    // Get the products out of the order and store them in an array.
304 304
    foreach (entity_metadata_wrapper('commerce_order', $order)->commerce_line_items as $delta => $line_item_wrapper) {
305
       if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {
305
       if (in_array($line_item_wrapper->getBundle(), commerce_product_line_item_types())) {
306 306
         $product = $line_item_wrapper->commerce_product->value();
307 307
         $products_in_cart[$product->product_id]= $product;
308 308
       }
......
509 509
    $this->drupalPost('node/' . $this->product_node->nid, array(), t('Add to cart'));
510 510

  
511 511
    // Get the order just created.
512
    $order_anonymous = reset(commerce_order_load_multiple(array(), array('uid' => $user->uid, 'status' => 'cart'), TRUE));
512
    $orders = commerce_order_load_multiple(array(), array('uid' => $user->uid, 'status' => 'cart'), TRUE);
513
    $order_anonymous = reset($orders);
513 514
    // Reset the cache as we don't want to keep the lock.
514 515
    entity_get_controller('commerce_order')->resetCache();
515 516

  
......
529 530
    $this->drupalPost('user', array('name' => $this->store_customer->name, 'pass' => $this->store_customer->pass_raw), t('Log in'));
530 531

  
531 532
    // Get the order for user just logged in.
532
    $order_authenticated = reset(commerce_order_load_multiple(array(), array('uid' => $this->store_customer->uid, 'status' => 'cart'), TRUE));
533
    $orders = commerce_order_load_multiple(array(), array('uid' => $this->store_customer->uid, 'status' => 'cart'), TRUE);
534
    $order_authenticated = reset($orders);
533 535
    // Reset the cache as we don't want to keep the lock.
534 536
    entity_get_controller('commerce_order')->resetCache();
535 537

  
drupal7/sites/all/modules/commerce/modules/checkout/commerce_checkout.api.php
292 292
function hook_commerce_checkout_pane_info_alter(&$checkout_panes) {
293 293
  $checkout_panes['billing']['weight'] = -6;
294 294
}
295

  
296
/**
297
 * Allows modules to define the first page for a new order entering checkout.
298
 *
299
 * The default first checkout page is whatever the first page is after the
300
 * checkout pages array is sorted by weight. This hook allows modules to provide
301
 * an alternate page ID or default page ID without having to build the checkout
302
 * page and pane info arrays, providing a noticeable performance improvement.
303
 *
304
 * If more than one module implements this hook, the first returned value will
305
 * be used.
306
 *
307
 * @return string
308
 *   The new first checkout page ID.
309
 */
310
function hook_commerce_checkout_first_checkout_page() {
311
  return 'checkout';
312
}
drupal7/sites/all/modules/commerce/modules/checkout/commerce_checkout.info
12 12
; Simple tests
13 13
files[] = tests/commerce_checkout.test
14 14

  
15
; Information added by Drupal.org packaging script on 2015-01-16
16
version = "7.x-1.11"
15
; Information added by Drupal.org packaging script on 2016-04-06
16
version = "7.x-1.13"
17 17
core = "7.x"
18 18
project = "commerce"
19
datestamp = "1421426596"
19
datestamp = "1459956613"
20 20

  
drupal7/sites/all/modules/commerce/modules/checkout/commerce_checkout.js
7 7
Drupal.behaviors.commerceCheckout = {
8 8
  attach: function (context, settings) {
9 9
    // When the buttons to move from page to page in the checkout process are
10
    // clicked we disable them so they are not accidently clicked twice.
10
    // clicked we disable them so they are not accidentally clicked twice.
11 11
    $('input.checkout-continue:not(.checkout-processed)', context).addClass('checkout-processed').click(function() {
12 12
      var $this = $(this);
13 13
      $this.clone().insertAfter(this).attr('disabled', true).next().removeClass('element-invisible');
drupal7/sites/all/modules/commerce/modules/checkout/commerce_checkout.module
128 128
    'commerce_checkout_pane_info_alter' => array(
129 129
      'group' => 'commerce',
130 130
    ),
131
    'commerce_checkout_first_checkout_page' => array(
132
      'group' => 'commerce',
133
    ),
131 134
    'commerce_checkout_router' => array(
132 135
      'group' => 'commerce',
133 136
    ),
......
279 282
  commerce_order_save($form_state['order']);
280 283

  
281 284
  // Redirect to the checkout page if specified.
282
  if ($form_state['triggering_element']['#value'] == $form['actions']['checkout']['#value']) {
285
  if ($form_state['triggering_element']['#value'] === $form['actions']['checkout']['#value']) {
283 286
    $form_state['redirect'] = 'checkout/' . $order->order_id;
284 287
  }
285 288
}
......
475 478
}
476 479

  
477 480
/**
478
 * Returns the page ID of the first checkout page sorted by weight.
481
 * Returns the page ID of the first checkout page to be used.
479 482
 */
480 483
function commerce_checkout_first_checkout_page() {
481
  return key(commerce_checkout_pages());
484
  // See if any modules return a page ID first.
485
  $page_id = module_invoke_all('commerce_checkout_first_checkout_page');
486

  
487
  // If we received a return value from the hook, use the first item in the
488
  // return array as the page ID.
489
  if (!empty($page_id)) {
490
    return reset($page_id);
491
  }
492

  
493
  // Otherwise fallback to the first page defined in checkout form.
494
  $keys = commerce_checkout_pages();
495
  reset($keys);
496
  return key($keys);
482 497
}
483 498

  
484 499
/**
......
993 1008
    $format = 'filtered_html';
994 1009
  }
995 1010
  else {
996
    // Otherwise select a fallback format and use a plaint text default value.
1011
    // Otherwise select a fallback format and use a plain text default value.
997 1012
    $value = 'Your order number is [commerce-order:order-number]. You can view your order on your account page when logged in.';
998 1013
    $format = filter_fallback_format();
999 1014
  }
drupal7/sites/all/modules/commerce/modules/checkout/tests/commerce_checkout.test
76 76
    $this->drupalPost('node/' . $this->product_node->nid, array(), t('Add to cart'));
77 77

  
78 78
    // Get the order for the anonymous user.
79
    $this->order = reset(commerce_order_load_multiple(array(), array('uid' => $user->uid, 'status' => 'cart'), TRUE));
79
    $orders = commerce_order_load_multiple(array(), array('uid' => $user->uid, 'status' => 'cart'), TRUE);
80
    $this->order = reset($orders);
80 81
    // Reset the cache as we don't want to keep the lock.
81 82
    entity_get_controller('commerce_order')->resetCache();
82 83
  }
drupal7/sites/all/modules/commerce/modules/customer/commerce_customer.info
21 21
; Simple tests
22 22
; files[] = tests/commerce_customer.test
23 23

  
24
; Information added by Drupal.org packaging script on 2015-01-16
25
version = "7.x-1.11"
24
; Information added by Drupal.org packaging script on 2016-04-06
25
version = "7.x-1.13"
26 26
core = "7.x"
27 27
project = "commerce"
28
datestamp = "1421426596"
28
datestamp = "1459956613"
29 29

  
drupal7/sites/all/modules/commerce/modules/customer/commerce_customer.module
424 424
  return $checkout_panes;
425 425
}
426 426

  
427
/**
428
 * Implements hook_field_views_data().
429
 */
430
function commerce_customer_field_views_data($field) {
431
  $data = field_views_field_default_views_data($field);
432

  
433
  // Build an array of bundles the customer profile reference field appears on.
434
  $bundles = array();
435

  
436
  foreach ($field['bundles'] as $entity => $entity_bundles) {
437
    $bundles[] = $entity . ' (' . implode(', ', $entity_bundles) . ')';
438
  }
439

  
440
  $replacements = array('!field_name' => $field['field_name'], '@bundles' => implode(', ', $bundles));
441

  
442
  foreach ($data as $table_name => $table_data) {
443
    foreach ($table_data as $field_name => $field_data) {
444
      if (isset($field_data['filter']['field_name']) && $field_name != 'delta') {
445
        $data[$table_name][$field_name]['relationship'] = array(
446
          'title' => t('Referenced customer profile'),
447
          'label' => t('Customer profile referenced by !field_name', $replacements),
448
          'help' => t('Relate this entity to the customer profile referenced by its !field_name value.', $replacements) . '<br />' . t('Appears in: @bundles.', $replacements),
449
          'base' => 'commerce_customer_profile',
450
          'base field' => 'profile_id',
451
          'handler' => 'views_handler_relationship',
452
        );
453
      }
454
    }
455
  }
456

  
457
  return $data;
458
}
459

  
460 427
/**
461 428
 * Implements hook_field_delete_instance().
462 429
 */
......
691 658
 * @param $profile_id
692 659
 *   The ID of the customer profile to delete.
693 660
 * @param $entity_context
694
 *   An optional entity context array that specifies the entity throgh whose
695
 *   customer profile reference field the given profiles are being deleted:
696
 *   - entity_type: the type of entity
697
 *   - entity_id: the unique ID of the entity
661
 *   An optional entity context array that specifies the entity through whose
662
 *   customer profile reference field the given profile is being deleted:
663
 *   - entity_type: The type of entity.
664
 *   - entity_id: The unique ID of the entity.
698 665
 *
699 666
 * @return
700 667
 *   TRUE on success, FALSE otherwise.
......
709 676
 * @param $profile_ids
710 677
 *   An array of customer profile IDs to delete.
711 678
 * @param $entity_context
712
 *   An optional entity context array that specifies the entity throgh whose
679
 *   An optional entity context array that specifies the entity through whose
713 680
 *   customer profile reference field the given profiles are being deleted:
714
 *   - entity_type: the type of entity
715
 *   - entity_id: the unique ID of the entity
681
 *   - entity_type: The type of entity.
682
 *   - entity_id: The unique ID of the entity.
716 683
 *
717 684
 * @return
718 685
 *   TRUE on success, FALSE otherwise.
......
908 875
function commerce_customer_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
909 876
  $result = array();
910 877

  
911
  // Collect the list of customer profile IDs.
912
  $profile_ids = array();
913

  
914
  foreach ($items as $delta => $item) {
915
    $profile_ids[] = $item['profile_id'];
916
  }
917

  
918 878
  switch ($display['type']) {
919 879
    case 'commerce_customer_profile_reference_display':
920 880
      foreach ($items as $delta => $item) {
drupal7/sites/all/modules/commerce/modules/customer/commerce_customer_ui.info
12 12
; Simple tests
13 13
files[] = tests/commerce_customer_ui.test
14 14

  
15
; Information added by Drupal.org packaging script on 2015-01-16
16
version = "7.x-1.11"
15
; Information added by Drupal.org packaging script on 2016-04-06
16
version = "7.x-1.13"
17 17
core = "7.x"
18 18
project = "commerce"
19
datestamp = "1421426596"
19
datestamp = "1459956613"
20 20

  
drupal7/sites/all/modules/commerce/modules/customer/includes/commerce_customer.checkout_pane.inc
297 297
  commerce_customer_profile_save($profile);
298 298

  
299 299
  // Store the profile ID for the related field as specified on the settings form.
300
  $wrapper = entity_metadata_wrapper('commerce_order', $order);
301

  
302
  if ($field_name = variable_get('commerce_' . $checkout_pane['pane_id'] . '_field', '')) {
300
  if (!empty($field_name)) {
301
    $wrapper = entity_metadata_wrapper('commerce_order', $order);
303 302
    $wrapper->{$field_name} = $profile;
304 303
  }
305 304
  else {
drupal7/sites/all/modules/commerce/modules/customer/includes/commerce_customer_profile.controller.inc
145 145
  public function delete($profile_ids, DatabaseTransaction $transaction = NULL, $entity_context = array()) {
146 146
    if (!empty($profile_ids)) {
147 147
      $profiles = $this->load($profile_ids, array());
148
      $profile_ids_to_remove = array();
148 149

  
149 150
      // Ensure the customer profiles can actually be deleted.
150 151
      foreach ((array) $profiles as $profile_id => $profile) {
......
156 157
        // If the profile cannot be deleted, remove it from the profiles array.
157 158
        if (!commerce_customer_profile_can_delete($profile)) {
158 159
          unset($profiles[$profile_id]);
160
          $profile_ids_to_remove[] = $profile_id;
159 161
        }
160 162
      }
161 163

  
......
164 166
        return FALSE;
165 167
      }
166 168

  
169
      $profile_ids = array_diff($profile_ids, $profile_ids_to_remove);
167 170
      parent::delete($profile_ids, $transaction);
168 171
      return TRUE;
169 172
    }
drupal7/sites/all/modules/commerce/modules/customer/includes/views/commerce_customer.views.inc
263 263

  
264 264
  return $data;
265 265
}
266

  
267
/**
268
 * Implements hook_field_views_data().
269
 */
270
function commerce_customer_field_views_data($field) {
271
  $data = field_views_field_default_views_data($field);
272

  
273
  // Build an array of bundles the customer profile reference field appears on.
274
  $bundles = array();
275

  
276
  foreach ($field['bundles'] as $entity => $entity_bundles) {
277
    $bundles[] = $entity . ' (' . implode(', ', $entity_bundles) . ')';
278
  }
279

  
280
  $replacements = array('!field_name' => $field['field_name'], '@bundles' => implode(', ', $bundles));
281

  
282
  foreach ($data as $table_name => $table_data) {
283
    foreach ($table_data as $field_name => $field_data) {
284
      if (isset($field_data['filter']['field_name']) && $field_name != 'delta') {
285
        $data[$table_name][$field_name]['relationship'] = array(
286
          'title' => t('Referenced customer profile'),
287
          'label' => t('Customer profile referenced by !field_name', $replacements),
288
          'help' => t('Relate this entity to the customer profile referenced by its !field_name value.', $replacements) . '<br />' . t('Appears in: @bundles.', $replacements),
289
          'base' => 'commerce_customer_profile',
290
          'base field' => 'profile_id',
291
          'handler' => 'views_handler_relationship',
292
        );
293
      }
294
    }
295
  }
296

  
297
  return $data;
298
}
drupal7/sites/all/modules/commerce/modules/customer/tests/commerce_customer_profile_dummy_type.info
5 5
core = 7.x
6 6
hidden = TRUE
7 7

  
8
; Information added by Drupal.org packaging script on 2015-01-16
9
version = "7.x-1.11"
8
; Information added by Drupal.org packaging script on 2016-04-06
9
version = "7.x-1.13"
10 10
core = "7.x"
11 11
project = "commerce"
12
datestamp = "1421426596"
12
datestamp = "1459956613"
13 13

  
drupal7/sites/all/modules/commerce/modules/customer/tests/commerce_customer_ui.test
118 118
    $this->assertTrue($this->url = url('admin/commerce/customer-profiles/add/billing', array('absolute => TRUE')));
119 119

  
120 120
    // Get the default values for the address.
121
    $address = addressfield_default_values();
121
    $field = field_info_field('commerce_customer_address');
122
    $instance = field_info_instance('commerce_customer_profile', 'commerce_customer_address', 'billing');
123
    $address = addressfield_default_values($field, $instance);
122 124

  
123 125
    // Check the integrity of the add form.
124 126
    $this->pass(t('Test the integrity of the add customer profile form:'));
......
263 265
    }
264 266

  
265 267
    // Load the profile and check if the field is filled.
266
    $profile = commerce_customer_profile_load(reset($this->loadCustomerProfile($conditions))->profile_id);
268
    $profiles = $this->loadCustomerProfile($conditions);
269
    $profile = commerce_customer_profile_load(reset($profiles)->profile_id);
267 270
    $this->assertTrue($profile->{'field_' . $edit['fields[_add_new_field][field_name]']}[LANGUAGE_NONE][0]['value'] == $field_value, t('The extra field !field created for the customer profile exists and it has the correct value: !value', array('!field' => $edit['fields[_add_new_field][field_name]'], '!value' => $field_value)));
268 271
  }
269 272

  
......
305 308
    $this->assertFieldByName('name', NULL, t('Name field is present and empty'));
306 309

  
307 310
    // Check at database level.
308
    $profile = reset(commerce_customer_profile_load_multiple(array($profile->profile_id), array(), TRUE));
311
    $profiles = commerce_customer_profile_load_multiple(array($profile->profile_id), array(), TRUE);
312
    $profile = reset($profiles);
309 313
    $this->assertTrue($profile->commerce_customer_address[LANGUAGE_NONE][0]['name_line'] == $edit['commerce_customer_address[und][0][name_line]'], t('\'Name line\' field has been correctly modified in the customer profile'));
310 314
    $this->assertTrue($profile->commerce_customer_address[LANGUAGE_NONE][0]['locality'] == $edit['commerce_customer_address[und][0][locality]'], t('\'Locality\' field has been correctly modified in the customer profile'));
311 315
    $this->assertTrue($profile->uid == 0, t('Profile owner is now anonymous user'));
......
326 330

  
327 331
    $this->drupalGet('admin/commerce/customer-profiles');
328 332
    $this->assertText(t('Disabled'), t('\'Disabled\' text for the profile appears in the profile listing page'));
329
    $profile = reset(commerce_customer_profile_load_multiple(array($profile->profile_id), array(), TRUE));
333
    $profiles = commerce_customer_profile_load_multiple(array($profile->profile_id), array(), TRUE);
334
    $profile = reset($profiles);
330 335
    $this->assertTrue($profile->status == 0, t('Profile status is Disabled'));
331 336
  }
332 337

  
......
364 369
    $this->assertText(t('No customer profiles have been created yet.'), t('\'No customer profiles have been created yet\' message is displayed'));
365 370

  
366 371
    // Check at database level.
367
    $profile = reset(commerce_customer_profile_load_multiple(array($profile->profile_id), array(), TRUE));
372
    $profiles = commerce_customer_profile_load_multiple(array($profile->profile_id), array(), TRUE);
373
    $profile = reset($profiles);
368 374
    $this->assertTrue(empty($profile), t('Profile can\'t be loaded from database after deleting it'));
369 375
  }
370 376

  
......
413 419
    $this->drupalLogin($this->store_admin);
414 420

  
415 421
    // Check the customer profile at database level.
416
    $order = reset(commerce_order_load_multiple(array($order->order_id), array(), TRUE));
422
    $orders = commerce_order_load_multiple(array($order->order_id), array(), TRUE);
423
    $order = reset($orders);
417 424
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
418 425
    $profile = $order_wrapper->commerce_customer_billing->value();
419 426
    $profile_wrapper = entity_metadata_wrapper('commerce_customer_profile', $profile);
......
466 473
      	'value' => $element,
467 474
      );
468 475
    }
469
    $profile = commerce_customer_profile_load(reset($this->loadCustomerProfile($conditions))->profile_id);
476
    $profiles = $this->loadCustomerProfile($conditions);
477
    $profile = commerce_customer_profile_load(reset($profiles)->profile_id);
470 478
    $profile_wrapper = entity_metadata_wrapper('commerce_customer_profile', $profile);
471 479
    $this->assertFalse(empty($profile), t('Profile has been created in database'));
472 480
    foreach ($address_info as $name => $info) {
......
498 506
    $this->assertTrue($edit['commerce_customer_billing[und][profiles][0][commerce_customer_address][und][0][name_line]'], t('\'Name line\' text is present with the correct value: !value', array('!value' => $edit['commerce_customer_billing[und][profiles][0][commerce_customer_address][und][0][name_line]'])));
499 507

  
500 508
    // Check the customer profile at database level.
501
    $profile = reset(commerce_customer_profile_load_multiple(array($profile->profile_id), array(), TRUE));
509
    $profiles = commerce_customer_profile_load_multiple(array($profile->profile_id), array(), TRUE);
510
    $profile = reset($profiles);
502 511
    $profile_wrapper = entity_metadata_wrapper('commerce_customer_profile', $profile);
503 512
    $this->assertEqual($profile_wrapper->commerce_customer_address->name_line->value(), $edit['commerce_customer_billing[und][profiles][0][commerce_customer_address][und][0][name_line]'], t('\'Name line\' property value !value match', array('!value' => $edit['commerce_customer_billing[und][profiles][0][commerce_customer_address][und][0][name_line]'])));
504 513
    $this->assertEqual($profile_wrapper->commerce_customer_address->locality->value(), $edit['commerce_customer_billing[und][profiles][0][commerce_customer_address][und][0][locality]'], t('\'Locality\' property value !value match', array('!value' => $edit['commerce_customer_billing[und][profiles][0][commerce_customer_address][und][0][locality]'])));
......
523 532
    $this->assertNoText($profile_wrapper->commerce_customer_address->name_line->value(), t('\'Name line\' for the profile is not present in the customer profiles listing'));
524 533

  
525 534
    // Check the customer profile has been deleted at database level.
526
    $profile = reset(commerce_customer_profile_load_multiple(array($profile->profile_id), array(), TRUE));
535
    $profiles = commerce_customer_profile_load_multiple(array($profile->profile_id), array(), TRUE);
536
    $profile = reset($profiles);
527 537
    $this->assertTrue(empty($profile), t('Profile has been delete from database'));
528 538
  }
529 539

  
540
  /**
541
   * Delete multiple profiles with and without orders attached.
542
   */
543
  public function testCommerceCustomerDeleteProfilesWithOrderReference() {
544
    // Create 2 new customer profiles.
545
    $profile_with_order = $this->createDummyCustomerProfile('billing', $this->store_customer->uid);
546
    $this->createDummyOrder($this->store_customer->uid, array(), 'pending', $profile_with_order->profile_id);
547
    $profile_without_order = $this->createDummyCustomerProfile('billing', $this->store_customer->uid);
548

  
549
    $profile_ids = array($profile_with_order->profile_id, $profile_without_order->profile_id);
550

  
551
    // Delete the profiles we can.
552
    commerce_customer_profile_delete_multiple($profile_ids);
553

  
554
    // Check the customer profile has been deleted at database level.
555
    $profiles = commerce_customer_profile_load_multiple($profile_ids, array(), TRUE);
556

  
557
    $this->assertTrue(!empty($profiles[$profile_with_order->profile_id]), t('Profile with order has not been delete from database'));
558
    $this->assertTrue(empty($profiles[$profile_without_order->profile_id]), t('Profile without order has been delete from database'));
559
  }
560

  
530 561
  /**
531 562
   * Create a custom profile type form an helper module and test it.
532 563
   */
......
613 644
    $this->drupalPost(NULL, $info, t('Continue to next step'));
614 645

  
615 646
    // Check the customer profile at database level.
616
    $order = reset(commerce_order_load_multiple(array($order->order_id), array(), TRUE));
647
    $orders = commerce_order_load_multiple(array($order->order_id), array(), TRUE);
648
    $order = reset($orders);
617 649
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
618 650

  
619 651
    // Extract the address field value from the billing profile.
drupal7/sites/all/modules/commerce/modules/line_item/commerce_line_item.info
15 15
files[] = includes/views/handlers/commerce_line_item_handler_argument_line_item_line_item_id.inc
16 16
files[] = includes/views/handlers/commerce_line_item_handler_field_line_item_title.inc
17 17
files[] = includes/views/handlers/commerce_line_item_handler_field_line_item_type.inc
18
files[] = includes/views/handlers/commerce_line_item_handler_filter_line_item_is_referenced.inc
18 19
files[] = includes/views/handlers/commerce_line_item_handler_filter_line_item_type.inc
19 20
files[] = includes/views/handlers/commerce_line_item_handler_field_edit_quantity.inc
20 21
files[] = includes/views/handlers/commerce_line_item_handler_field_edit_delete.inc
......
22 23
; Simple tests
23 24
; files[] = tests/commerce_line_item.test
24 25

  
25
; Information added by Drupal.org packaging script on 2015-01-16
26
version = "7.x-1.11"
26
; Information added by Drupal.org packaging script on 2016-04-06
27
version = "7.x-1.13"
27 28
core = "7.x"
28 29
project = "commerce"
29
datestamp = "1421426596"
30
datestamp = "1459956613"
30 31

  
drupal7/sites/all/modules/commerce/modules/line_item/commerce_line_item.module
105 105
 */
106 106
function commerce_line_item_form_alter(&$form, &$form_state, $form_id) {
107 107
  $line_item_form = FALSE;
108

  
108 109
  // Is this a views form?
109 110
  if (strpos($form_id, 'views_form_') === 0) {
110 111
    $view = $form_state['build_info']['args'][0];
112

  
111 113
    // Does the view contain one of the line item edit fields?
112 114
    foreach ($view->field as $field_name => $field) {
113 115
      if ($field instanceof commerce_line_item_handler_field_edit_delete || $field instanceof commerce_line_item_handler_field_edit_quantity) {
......
115 117
      }
116 118
    }
117 119
  }
120

  
118 121
  // This is not the form we are looking for.
119 122
  if (!$line_item_form) {
120 123
    return;
121 124
  }
125

  
122 126
  // Require the existence of an order_id argument (and its value).
123 127
  if (empty($view->argument['order_id']) || empty($view->argument['order_id']->value)) {
124 128
    return;
......
202 206
      'render element' => 'form',
203 207
    ),
204 208
    'commerce_line_item_summary' => array(
205
      'variables' => array('quantity_raw' => NULL, 'quantity_label' => NULL, 'quantity' => NULL, 'total_raw' => NULL, 'total' => NULL, 'links' => NULL, 'view' => NULL),
209
      'variables' => array('quantity_raw' => NULL, 'quantity_label' => NULL, 'quantity' => NULL, 'total_raw' => NULL, 'total_label' => NULL, 'total' => NULL, 'links' => NULL, 'view' => NULL),
206 210
      'path' => drupal_get_path('module', 'commerce_line_item') . '/theme',
207 211
      'template' => 'commerce-line-item-summary',
208 212
    ),
......
374 378

  
375 379
      if ($wrapper->{$field_name} instanceof EntityListWrapper) {
376 380
        foreach ($wrapper->{$field_name} as $delta => $line_item_wrapper) {
377
          $referenced_line_item_ids[] = $line_item_wrapper->line_item_id->value();
381
          try {
382
            $referenced_line_item_ids[] = $line_item_wrapper->line_item_id->value();
383
          }
384
          catch (EntityMetadataWrapperException $e) {
385
            // Do nothing, this was a bad reference value.
386
          }
378 387
        }
379 388
      }
380 389
      elseif (!is_null($wrapper->{$field_name}->value())) {
381
        $referenced_line_item_ids[] = $wrapper->{$field_name}->line_item_id->value();
390
        try {
391
          $referenced_line_item_ids[] = $wrapper->{$field_name}->line_item_id->value();
392
        }
393
        catch (EntityMetadataWrapperException $e) {
394
          // Do nothing, this was a bad reference value.
395
        }
382 396
      }
383 397

  
384 398
      // Loop over each line item referenced on this field...
......
541 555
 *   - add_form_validate
542 556
 *   - add_form_submit
543 557
 *
544
 * @return
558
 * @return string
545 559
 *   A string containing the name of the callback function or FALSE if it could
546
 *     not be found.
560
 *   not be found.
547 561
 */
548 562
function commerce_line_item_type_callback($line_item_type, $callback) {
549 563
  // If the specified callback function exists, return it.
......
995 1009
    }
996 1010

  
997 1011
    // Load the line items for temporary storage in the form array.
998
    $line_items = commerce_line_item_load_multiple($line_item_ids);
1012
    if(!empty($line_item_ids)) {
1013
      $line_items = commerce_line_item_load_multiple($line_item_ids);
1014
    }
1015
    else {
1016
      $line_items = array();
1017
    }
999 1018

  
1000 1019
    // Update the base form element array to use the proper theme and validate
1001 1020
    // functions and to include header information for the line item table.
......
1038 1057

  
1039 1058
      // Unset the title and description and add it to the line item form.
1040 1059
      $language = $widget_form['commerce_unit_price']['#language'];
1041
      unset($widget_form['commerce_unit_price'][$language][0]['amount']['#title']);
1042
      unset($widget_form['commerce_unit_price'][$language][0]['amount']['#description']);
1060
      $widget_form['commerce_unit_price'][$language][0]['amount']['#title_display'] = 'invisible';
1043 1061

  
1044 1062
      $element['line_items'][$line_item_id]['commerce_unit_price'] = $widget_form['commerce_unit_price'];
1045 1063
      $quantity = round($line_item->quantity);
......
1245 1263
  // If the "Add line item" button was clicked, store the line item type in the
1246 1264
  // $form_state for the rebuild of the $form array.
1247 1265
  if (!empty($form_state['triggering_element'])) {
1248
    if ($form_state['triggering_element']['#value'] == t('Add line item')) {
1266
    if ($form_state['triggering_element']['#value'] === t('Add line item')) {
1249 1267
      $form_state['line_item_add'] = $element['actions']['line_item_type']['#value'];
1250 1268
      $form_state['rebuild'] = TRUE;
1251 1269
    }
......
1431 1449
      $line_item = entity_metadata_wrapper('commerce_line_item', $line_item);
1432 1450
    }
1433 1451

  
1434
    if (empty($types) || in_array($line_item->type->value(), $types)) {
1452
    if (empty($types) || in_array($line_item->getBundle(), $types)) {
1435 1453
      $quantity += $line_item->quantity->value();
1436 1454
    }
1437 1455
  }
......
1503 1521
      $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item_wrapper);
1504 1522
    }
1505 1523

  
1506
    if (empty($types) || in_array($line_item_wrapper->type->value(), $types)) {
1524
    if (empty($types) || in_array($line_item_wrapper->getBundle(), $types)) {
1507 1525
      $total += commerce_currency_convert(
1508 1526
        $line_item_wrapper->commerce_total->amount->value(),
1509 1527
        $line_item_wrapper->commerce_total->currency_code->value(),
drupal7/sites/all/modules/commerce/modules/line_item/commerce_line_item_ui.info
9 9
core = 7.x
10 10
configure = admin/commerce/config/line-items
11 11

  
12
; Information added by Drupal.org packaging script on 2015-01-16
13
version = "7.x-1.11"
12
; Information added by Drupal.org packaging script on 2016-04-06
13
version = "7.x-1.13"
14 14
core = "7.x"
15 15
project = "commerce"
16
datestamp = "1421426596"
16
datestamp = "1459956613"
17 17

  
drupal7/sites/all/modules/commerce/modules/line_item/includes/commerce_line_item.controller.inc
139 139
    }
140 140

  
141 141
    try {
142
      // First attempt to delete references for the given line items.
142
      // First attempt to delete references to each line item, building a list
143
      // of modified entities to be saved once each after references to all line
144
      // items have been deleted.
145
      $reference_fields = commerce_info_fields('commerce_line_item_reference');
146
      $modified_entities = array();
147

  
143 148
      foreach ($line_items as $line_item_id => $line_item) {
144
        commerce_line_item_delete_references($line_item);
149
        // Check the data in every line item reference field.
150
        foreach ($reference_fields as $field_name => $field) {
151
          // Query for any entity referencing the deleted line item in this field.
152
          $query = new EntityFieldQuery();
153
          $query->fieldCondition($field_name, 'line_item_id', $line_item->line_item_id, '=');
154
          $result = $query->execute();
155

  
156
          // If no results were returned, continue to next field.
157
          if (empty($result)) {
158
            continue;
159
          }
160

  
161
          // Loop over results for each type of entity returned.
162
          foreach ($result as $entity_type => $data) {
163
            // Load the entities of the current type.
164
            $entities = entity_load($entity_type, array_keys($data));
165

  
166
            // Loop over each entity and remove the reference to the deleted line item.
167
            foreach ($entities as $entity_id => $entity) {
168
              // If we have this entity already, get the reference, otherwise
169
              // store the new entity to save changes later.
170
              if (!isset($modified_entities[$entity_type . ':' . $entity_id])) {
171
                $modified_entities[$entity_type . ':' . $entity_id] = array(
172
                  'entity_type' => $entity_type,
173
                  'entity' => $entity,
174
                );
175
              }
176

  
177
              commerce_entity_reference_delete($entity, $field_name, 'line_item_id', $line_item->line_item_id);
178
            }
179
          }
180
        }
181
      }
182

  
183
      // Save the entities that were modified through deleted references.
184
      foreach ($modified_entities as $entity_data) {
185
        entity_save($entity_data['entity_type'], $entity_data['entity']);
145 186
      }
146 187

  
147 188
      return parent::delete($line_item_ids, $transaction);
drupal7/sites/all/modules/commerce/modules/line_item/includes/views/commerce_line_item.views.inc
63 63

  
64 64
  // TODO: Expose the display view build mode.
65 65

  
66
  // Defines a filter that ensures line items are referenced by orders.
67
  $data['commerce_line_item']['line_item_is_referenced'] = array(
68
    'title' => t('Line item is referenced by its order'),
69
    'help' => t('Ensures a line item in the result set is referenced by the order it indicates in its order_id property.'),
70
    'filter' => array(
71
      'handler' => 'commerce_line_item_handler_filter_line_item_is_referenced',
72
    ),
73
  );
74

  
66 75
  // Expose the type-dependent line item title.
67 76
  $data['commerce_line_item']['line_item_title'] = array(
68 77
    'field' => array(
drupal7/sites/all/modules/commerce/modules/line_item/includes/views/handlers/commerce_line_item_handler_field_edit_quantity.inc
112 112
      $line_item = commerce_line_item_load($line_item_id);
113 113
      $line_item->quantity = $quantity;
114 114
      commerce_line_item_save($line_item);
115
      entity_get_controller('commerce_line_item')->resetCache(array($line_item->line_item_id));
116 115
    }
117 116
  }
118 117
}
drupal7/sites/all/modules/commerce/modules/line_item/includes/views/handlers/commerce_line_item_handler_filter_line_item_is_referenced.inc
1
<?php
2

  
3
/**
4
 * Filters a line item View to only include line items referenced by the order
5
 * they claim to be a part of in their order_id property.
6
 */
7

  
8
class commerce_line_item_handler_filter_line_item_is_referenced extends views_handler_filter {
9

  
10
  /**
11
   * Disables exposing this filter.
12
   */
13
  function can_expose() {
14
    return FALSE;
15
  }
16

  
17
  /**
18
   * Only add to the admin summary if the filter has been negated.
19
   */
20
  function admin_summary() {
21
    if ($this->operator == 'NOT IN') {
22
      return 'NOT';
23
    }
24

  
25
    return '';
26
  }
27

  
28
  function option_definition() {
29
    $options  = parent::option_definition();
30
    $options['operator'] = array('default' => 'IN');
31
    return $options;
32
  }
33

  
34
  function operator_options($which = 'title') {
35
    $options = array();
36
    $options['IN'] = t('Line item is referenced');
37
    $options['NOT IN'] = t('Line item is NOT referenced');
38
    return $options;
39
  }
40

  
41
  /**
42
   * Adds a subquery to the WHERE clause that ensures the order_id referenced by
43
   * the line item is present in the comerce_line_items field's table for the
44
   * given line_item_id.
45
   */
46
  function query() {
47
    // Ensure we have a valid operator for the subquery.
48
    if (empty($this->operator)) {
49
      $this->operator = 'IN';
50
    }
51

  
52
    // Ensure the commerce_line_items field exists and fetch its table name.
53
    $field_info = field_info_field('commerce_line_items');
54

  
55
    if (empty($field_info['storage']['details']['sql']['FIELD_LOAD_CURRENT'])) {
56
      return;
57
    }
58

  
59
    $field_table = key($field_info['storage']['details']['sql']['FIELD_LOAD_CURRENT']);
60
    $field_value_column = $field_info['storage']['details']['sql']['FIELD_LOAD_CURRENT'][$field_table]['line_item_id'];
61

  
62
    $this->table_alias = $this->query->ensure_table($this->view->base_table, $this->relationship);
63

  
64
    // Build SQL where snippet using a subquery on the field table for the
65
    // required default line item reference field on orders.
66
    $snippet = $this->table_alias . '.line_item_id ' . $this->operator . ' (SELECT ' . $field_value_column . ' FROM {' . $field_table . '} WHERE deleted = 0 AND entity_id != 0 AND entity_id = ' . $this->table_alias . '.order_id)';
67

  
68
    $this->query->add_where_expression($this->options['group'], $snippet);
69
  }
70

  
71
}
drupal7/sites/all/modules/commerce/modules/order/commerce_order.api.php
178 178
function hook_commerce_order_presave($order) {
179 179
  // No example.
180 180
}
181

  
182
/**
183
 * Respond to order deletion.
184
 *
185
 * The order will still exist and allows you to take an action before it is
186
 * completely removed.
187
 *
188
 * @param $order
189
 *   The order object that is being deleted.
190
 */
191
function hook_commerce_order_delete($order) {
192
  commerce_cart_order_session_delete($order->order_id);
193
  commerce_cart_order_session_delete($order->order_id, TRUE);
194
}
drupal7/sites/all/modules/commerce/modules/order/commerce_order.info
36 36
files[] = tests/commerce_order.rules.test
37 37
files[] = tests/commerce_order.test
38 38

  
39
; Information added by Drupal.org packaging script on 2015-01-16
40
version = "7.x-1.11"
39
; Information added by Drupal.org packaging script on 2016-04-06
40
version = "7.x-1.13"
41 41
core = "7.x"
42 42
project = "commerce"
43
datestamp = "1421426596"
43
datestamp = "1459956613"
44 44

  
drupal7/sites/all/modules/commerce/modules/order/commerce_order.module
1291 1291
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
1292 1292

  
1293 1293
  // First determine the currency to use for the order total.
1294
  $currency_code = commerce_default_currency();
1294
  $default_currency_code = $currency_code = commerce_default_currency();
1295 1295
  $currencies = array();
1296 1296

  
1297 1297
  // Populate an array of how many line items on the order use each currency.
......
1305 1305

  
1306 1306
    $line_item_currency_code = $line_item_wrapper->commerce_total->currency_code->value();
1307 1307

  
1308
    if (!in_array($line_item_currency_code, array_keys($currencies))) {
1308
    if (!isset($currencies[$line_item_currency_code])) {
1309 1309
      $currencies[$line_item_currency_code] = 1;
1310 1310
    }
1311 1311
    else {
......
1320 1320
  if (count($currencies) == 1) {
1321 1321
    $currency_code = key($currencies);
1322 1322
  }
1323
  elseif (in_array(commerce_default_currency(), array_keys($currencies))) {
1323
  elseif (isset($currencies[$default_currency_code])) {
1324 1324
    // Otherwise use the site default currency if it's in the order.
1325
    $currency_code = commerce_default_currency();
1325
    $currency_code = $default_currency_code;
1326 1326
  }
1327 1327
  elseif (count($currencies) > 1) {
1328 1328
    // Otherwise use the first currency on the order. We do this instead of
......
1347 1347
  );
1348 1348

  
1349 1349
  $order_wrapper->commerce_order_total->data = commerce_price_component_add($base_price, 'base_price', $base_price, TRUE);
1350
  $order_total = $order_wrapper->commerce_order_total->value();
1350 1351

  
1351 1352
  // Then loop over each line item and add its total to the order total.
1352 1353
  $amount = 0;
1353 1354

  
1354 1355
  foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
1355 1356
    // Convert the line item's total to the order's currency for totalling.
1356
    $component_total = commerce_price_component_total($line_item_wrapper->commerce_total->value());
1357
    $line_item_total = $line_item_wrapper->commerce_total->value();
1358
    $component_total = commerce_price_component_total($line_item_total);
1357 1359

  
1358 1360
    // Add the totals.
1359 1361
    $amount += commerce_currency_convert(
......
1363 1365
    );
1364 1366

  
1365 1367
    // Combine the line item total's component prices into the order total.
1366
    $order_wrapper->commerce_order_total->data = commerce_price_components_combine(
1367
      $order_wrapper->commerce_order_total->value(),
1368
      $line_item_wrapper->commerce_total->value()
1369
    );
1368
    $order_total['data'] = commerce_price_components_combine($order_total, $line_item_total);
1370 1369
  }
1371 1370

  
1372
  // Update the order total price field with the final total amount.
1371
  // Update the order total price field with the final total amount and data.
1373 1372
  $order_wrapper->commerce_order_total->amount = round($amount);
1373
  $order_wrapper->commerce_order_total->data = $order_total['data'];
1374 1374
}
1375 1375

  
1376 1376
/**
......
1504 1504
    $vars['footer'] = '';
1505 1505
  }
1506 1506
}
1507

  
1508
/**
1509
 * Element validate handler: strip whitespaces from order related e-mail fields.
1510
 * @see commerce_order_account_pane_checkout_form()
1511
 */
1512
function commerce_order_mail_validate($element, &$form_state, $form) {
1513
  form_set_value($element, trim($element['#value']), $form_state);
1514
}
drupal7/sites/all/modules/commerce/modules/order/commerce_order.rules.inc
282 282

  
283 283
    // Populate the array of the quantities of the products on the order.
284 284
    foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
285
      if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {
285
      if (in_array($line_item_wrapper->getBundle(), commerce_product_line_item_types())) {
286 286
        // Extract a product ID and quantity from the line item.
287 287
        $line_item_sku = $line_item_wrapper->commerce_product->sku->value();
288 288
        $quantity = $line_item_wrapper->quantity->value();
......
329 329
    // Look for product line items on the order whose products match the
330 330
    // specified product types and increment the quantity count accordingly.
331 331
    foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
332
      if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {
332
      if (in_array($line_item_wrapper->getBundle(), commerce_product_line_item_types())) {
333 333
        // Extract the product type from the line item.
334
        $line_item_product_type = $line_item_wrapper->commerce_product->type->value();
334
        $line_item_product_type = $line_item_wrapper->commerce_product->getBundle();
335 335

  
336 336
        // If the line item product type matches, update the total quantity.
337 337
        if (in_array($line_item_product_type, $product_types)) {
drupal7/sites/all/modules/commerce/modules/order/commerce_order_ui.info
16 16
; Simple tests
17 17
files[] = tests/commerce_order_ui.test
18 18

  
19
; Information added by Drupal.org packaging script on 2015-01-16
20
version = "7.x-1.11"
19
; Information added by Drupal.org packaging script on 2016-04-06
20
version = "7.x-1.13"
21 21
core = "7.x"
22 22
project = "commerce"
23
datestamp = "1421426596"
23
datestamp = "1459956613"
24 24

  
drupal7/sites/all/modules/commerce/modules/order/commerce_order_ui.module
17 17
    'title' => 'Create an order',
18 18
    'description' => 'Create a new order.',
19 19
    'page callback' => 'commerce_order_ui_order_form_wrapper',
20
    'page arguments' => array(commerce_order_new()),
21 20
    'access callback' => 'commerce_order_access',
22 21
    'access arguments' => array('create'),
23 22
    'weight' => 10,
......
27 26
    'title' => 'Create an order',
28 27
    'description' => 'Create a new order for the specified user.',
29 28
    'page callback' => 'commerce_order_ui_order_form_wrapper',
30
    'page arguments' => array(commerce_order_new(), 4),
29
    'page arguments' => array(NULL, 4),
31 30
    'access callback' => 'commerce_order_access',
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff