Projet

Général

Profil

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

root / drupal7 / sites / all / modules / commerce / modules / line_item / commerce_line_item.info.inc @ 9d13637e

1
<?php
2

    
3
/**
4
 * @file
5
 * Provides metadata for the line item entity.
6
 */
7

    
8
/**
9
 * Implements hook_entity_property_info().
10
 */
11
function commerce_line_item_entity_property_info() {
12
  $info = array();
13

    
14
  // Add meta-data about the basic commerce_line_item properties.
15
  $properties = &$info['commerce_line_item']['properties'];
16

    
17
  $properties['line_item_id'] = array(
18
    'label' => t('Line item ID'),
19
    'description' => t('The internal numeric ID of the line item.'),
20
    'type' => 'integer',
21
    'schema field' => 'line_item_id',
22
  );
23
  $properties['order_id'] = array(
24
    'label' => t('Order ID', array(), array('context' => 'a drupal commerce order')),
25
    'type' => 'integer',
26
    'description' => t('The unique ID of the order the line item belongs to.'),
27
    'setter callback' => 'entity_property_verbatim_set',
28
    'setter permission' => 'administer line items',
29
    'clear' => array('order'),
30
    'schema field' => 'order_id',
31
  );
32
  $properties['order'] = array(
33
    'label' => t('Order', array(), array('context' => 'a drupal commerce order')),
34
    'type' => 'commerce_order',
35
    'description' => t('The order the line item belongs to.'),
36
    'getter callback' => 'commerce_line_item_get_properties',
37
    'setter callback' => 'commerce_line_item_set_properties',
38
    'setter permission' => 'administer line items',
39
    'required' => TRUE,
40
    'computed' => TRUE,
41
    'clear' => array('order_id'),
42
  );
43
  $properties['type'] = array(
44
    'label' => t('Type'),
45
    'description' => t('The human readable name of the line item type.'),
46
    'type' => 'token',
47
    'setter callback' => 'entity_property_verbatim_set',
48
    'options list' => 'commerce_line_item_type_options_list',
49
    'required' => TRUE,
50
    'schema field' => 'type',
51
  );
52
  $properties['line_item_label'] = array(
53
    'label' => t('Line item label'),
54
    'description' => t('The label displayed with the line item.'),
55
    'type' => 'text',
56
    'setter callback' => 'entity_property_verbatim_set',
57
    'required' => TRUE,
58
    'schema field' => 'line_item_label',
59
  );
60
  $properties['quantity'] = array(
61
    'label' => t('Quantity'),
62
    'description' => t('Quantity associated with this line item'),
63
    'type' => 'decimal',
64
    'getter callback' => 'entity_property_verbatim_get',
65
    'setter callback' => 'entity_property_verbatim_set',
66
    'required' => TRUE,
67
    'schema field' => 'quantity',
68
  );
69
  $properties['created'] = array(
70
    'label' => t('Date created'),
71
    'description' => t('The date the line item was created.'),
72
    'type' => 'date',
73
    'setter callback' => 'entity_metadata_verbatim_set',
74
    'setter permission' => 'administer line items',
75
    'schema field' => 'created',
76
  );
77
  $properties['changed'] = array(
78
    'label' => t('Date changed'),
79
    'description' => t('The date the line item was most recently updated.'),
80
    'type' => 'date',
81
    'schema field' => 'changed',
82
  );
83

    
84
  $info['commerce_line_item']['bundles'] = array();
85
  foreach (commerce_line_item_type_get_name() as $type => $name) {
86
    $info['commerce_line_item']['bundles'][$type] = array(
87
      'label' => $name,
88
    );
89
  }
90

    
91
  return $info;
92
}
93

    
94
/**
95
 * Implements hook_entity_property_info_alter() on top of the Line Item module.
96
 */
97
function commerce_line_item_entity_property_info_alter(&$info) {
98
  // Move the price properties to the line item by default; as they are required
99
  // default fields, this makes dealing with them more convenient.
100
  $properties = array();
101

    
102
  foreach ($info['commerce_line_item']['bundles'] as $bundle => $bundle_info) {
103
    $bundle_info += array('properties' => array());
104
    $properties += $bundle_info['properties'];
105
  }
106

    
107
  if (!empty($properties['commerce_unit_price'])) {
108
    $info['commerce_line_item']['properties']['commerce_unit_price'] = $properties['commerce_unit_price'];
109
  }
110
  if (!empty($properties['commerce_total'])) {
111
    $info['commerce_line_item']['properties']['commerce_total'] = $properties['commerce_total'];
112
  }
113
}