Projet

Général

Profil

Paste
Télécharger (1,15 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / commerce / modules / product_reference / commerce_product_reference.api.php @ dbb0c974

1
<?php
2

    
3
/**
4
 * @file
5
 * Hooks provided by the Product Reference module.
6
 */
7

    
8
/**
9
 * Allows modules to alter the delta value used to determine the default product
10
 * entity in an array of referenced products.
11
 *
12
 * The basic behavior for determining a default product from an array of
13
 * referenced products is to use the first referenced product. This hook allows
14
 * modules to change that to a different delta value.
15
 *
16
 * Note that in some cases $products will be keyed by product ID while in other
17
 * cases it will be 0 indexed.
18
 *
19
 * @param $delta
20
 *   The key in the $products array of the product that should be the default
21
 *   product for display purposes in a product reference field value array.
22
 * @param $products
23
 *   An array of product entities referenced by a product reference field.
24
 *
25
 * @see commerce_product_reference_default_product()
26
 */
27
function hook_commerce_product_reference_default_delta_alter(&$delta, $products) {
28
  // If a product with the SKU PROD-01 exists in the array, set that as the
29
  // default regardless of its position.
30
  foreach ($products as $key => $product) {
31
    if ($product->sku == 'PROD-01') {
32
      $delta = $key;
33
    }
34
  }
35
}