1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Provides metadata for the product entity.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_entity_property_info().
|
10
|
*/
|
11
|
function commerce_product_entity_property_info() {
|
12
|
$info = array();
|
13
|
|
14
|
// Add meta-data about the basic commerce_product properties.
|
15
|
$properties = &$info['commerce_product']['properties'];
|
16
|
|
17
|
$properties['product_id'] = array(
|
18
|
'label' => t('Product ID'),
|
19
|
'description' => t('The internal numeric ID of the product.'),
|
20
|
'type' => 'integer',
|
21
|
'schema field' => 'product_id',
|
22
|
);
|
23
|
$properties['sku'] = array(
|
24
|
'label' => t('SKU'),
|
25
|
'description' => t('The human readable product SKU.'),
|
26
|
'type' => 'text',
|
27
|
'setter callback' => 'entity_property_verbatim_set',
|
28
|
'required' => TRUE,
|
29
|
'schema field' => 'sku',
|
30
|
);
|
31
|
$properties['type'] = array(
|
32
|
'label' => t('Type'),
|
33
|
'description' => t('The type of the product.'),
|
34
|
'type' => 'token',
|
35
|
'setter callback' => 'entity_property_verbatim_set',
|
36
|
'setter permission' => 'administer commerce_product entities',
|
37
|
'options list' => 'commerce_product_type_options_list',
|
38
|
'required' => TRUE,
|
39
|
'schema field' => 'type',
|
40
|
);
|
41
|
$properties['title'] = array(
|
42
|
'label' => t('Title'),
|
43
|
'description' => t('The title of the product.'),
|
44
|
'type' => 'text',
|
45
|
'setter callback' => 'entity_property_verbatim_set',
|
46
|
'required' => TRUE,
|
47
|
'schema field' => 'title',
|
48
|
);
|
49
|
$properties['language'] = array(
|
50
|
'label' => t('Language'),
|
51
|
'type' => 'token',
|
52
|
'description' => t('The language the product was created in.'),
|
53
|
'setter callback' => 'entity_property_verbatim_set',
|
54
|
'options list' => 'entity_metadata_language_list',
|
55
|
'schema field' => 'language',
|
56
|
'setter permission' => 'administer commerce_product entities',
|
57
|
);
|
58
|
$properties['status'] = array(
|
59
|
'label' => t('Status'),
|
60
|
'description' => t('Boolean indicating whether the product is active or disabled.'),
|
61
|
'type' => 'boolean',
|
62
|
'options list' => 'commerce_product_status_options_list',
|
63
|
'setter callback' => 'entity_property_verbatim_set',
|
64
|
'setter permission' => 'administer commerce_product entities',
|
65
|
'schema field' => 'status',
|
66
|
);
|
67
|
$properties['created'] = array(
|
68
|
'label' => t('Date created'),
|
69
|
'description' => t('The date the product was created.'),
|
70
|
'type' => 'date',
|
71
|
'setter callback' => 'entity_property_verbatim_set',
|
72
|
'setter permission' => 'administer commerce_product entities',
|
73
|
'schema field' => 'created',
|
74
|
);
|
75
|
$properties['changed'] = array(
|
76
|
'label' => t('Date updated'),
|
77
|
'description' => t('The date the product was most recently updated.'),
|
78
|
'type' => 'date',
|
79
|
'setter callback' => 'entity_property_verbatim_set',
|
80
|
'query callback' => 'entity_metadata_table_query',
|
81
|
'setter permission' => 'administer commerce_product entities',
|
82
|
'schema field' => 'changed',
|
83
|
);
|
84
|
$properties['uid'] = array(
|
85
|
'label' => t('Creator ID'),
|
86
|
'type' => 'integer',
|
87
|
'description' => t('The unique ID of the product creator.'),
|
88
|
'setter callback' => 'entity_property_verbatim_set',
|
89
|
'setter permission' => 'administer commerce_product entities',
|
90
|
'clear' => array('creator'),
|
91
|
'schema field' => 'uid',
|
92
|
);
|
93
|
$properties['creator'] = array(
|
94
|
'label' => t('Creator'),
|
95
|
'type' => 'user',
|
96
|
'description' => t('The creator of the product.'),
|
97
|
'getter callback' => 'commerce_product_get_properties',
|
98
|
'setter callback' => 'commerce_product_set_properties',
|
99
|
'setter permission' => 'administer commerce_product entities',
|
100
|
'required' => TRUE,
|
101
|
'computed' => TRUE,
|
102
|
'clear' => array('uid'),
|
103
|
);
|
104
|
|
105
|
$info['commerce_product']['bundles'] = array();
|
106
|
foreach (commerce_product_type_get_name() as $type => $name) {
|
107
|
$info['commerce_product']['bundles'][$type] = array(
|
108
|
'label' => $name,
|
109
|
);
|
110
|
}
|
111
|
|
112
|
return $info;
|
113
|
}
|
114
|
|
115
|
/**
|
116
|
* Implements hook_entity_property_info_alter() on top of the Product module.
|
117
|
*/
|
118
|
function commerce_product_entity_property_info_alter(&$info) {
|
119
|
// Move the default price property to the product by default; as it is a
|
120
|
// required default field, this makes dealing with it more convenient.
|
121
|
$properties = array();
|
122
|
|
123
|
foreach ($info['commerce_product']['bundles'] as $bundle => $bundle_info) {
|
124
|
$bundle_info += array('properties' => array());
|
125
|
$properties += $bundle_info['properties'];
|
126
|
}
|
127
|
|
128
|
if (!empty($properties['commerce_price'])) {
|
129
|
$info['commerce_product']['properties']['commerce_price'] = $properties['commerce_price'];
|
130
|
}
|
131
|
}
|