1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Implements hook_schema().
|
5
|
*/
|
6
|
function commerce_price_schema() {
|
7
|
$schema = array();
|
8
|
|
9
|
$schema['commerce_calculated_price'] = array(
|
10
|
'description' => 'Stores pre-calculated dynamic prices.',
|
11
|
'fields' => array(
|
12
|
'module' => array(
|
13
|
'description' => 'The name of the module performing the calculation.',
|
14
|
'type' => 'varchar',
|
15
|
'length' => 255,
|
16
|
'not null' => TRUE,
|
17
|
'default' => '',
|
18
|
),
|
19
|
'module_key' => array(
|
20
|
'description' => 'A module specific key useful for indicating the context of a particular calculation, e.g. the IDs of Rules evaluated to produce the calculated price.',
|
21
|
'type' => 'text',
|
22
|
'size' => 'medium',
|
23
|
'not null' => TRUE,
|
24
|
),
|
25
|
'entity_type' => array(
|
26
|
'description' => 'The type of entity this price belongs to.',
|
27
|
'type' => 'varchar',
|
28
|
'length' => 255,
|
29
|
'not null' => TRUE,
|
30
|
'default' => '',
|
31
|
),
|
32
|
'entity_id' => array(
|
33
|
'description' => 'The entity ID of the object this price belongs to.',
|
34
|
'type' => 'int',
|
35
|
'unsigned' => TRUE,
|
36
|
'not null' => TRUE,
|
37
|
'default' => 0,
|
38
|
),
|
39
|
'field_name' => array(
|
40
|
'description' => 'The name of the field the calculated price relates to.',
|
41
|
'type' => 'varchar',
|
42
|
'length' => 32,
|
43
|
'not null' => TRUE,
|
44
|
'default' => '',
|
45
|
),
|
46
|
'language' => array(
|
47
|
'description' => 'The {languages}.language of the entity.',
|
48
|
'type' => 'varchar',
|
49
|
'length' => 32,
|
50
|
'not null' => TRUE,
|
51
|
'default' => '',
|
52
|
),
|
53
|
'delta' => array(
|
54
|
'description' => 'The sequence number for this data item, used for multi-value fields',
|
55
|
'type' => 'int',
|
56
|
'unsigned' => TRUE,
|
57
|
'not null' => TRUE,
|
58
|
'default' => 0,
|
59
|
),
|
60
|
'amount' => array(
|
61
|
'description' => 'The price amount.',
|
62
|
'type' => 'int',
|
63
|
'not null' => TRUE,
|
64
|
'default' => 0,
|
65
|
),
|
66
|
'currency_code' => array(
|
67
|
'description' => 'The currency code for the price.',
|
68
|
'type' => 'varchar',
|
69
|
'length' => 32,
|
70
|
'not null' => TRUE,
|
71
|
),
|
72
|
'data' => array(
|
73
|
'description' => 'A serialized array of additional price data.',
|
74
|
'type' => 'text',
|
75
|
'size' => 'big',
|
76
|
'serialize' => TRUE,
|
77
|
),
|
78
|
'created' => array(
|
79
|
'description' => 'The Unix timestamp when the price was calculated.',
|
80
|
'type' => 'int',
|
81
|
'not null' => TRUE,
|
82
|
'default' => 0,
|
83
|
),
|
84
|
),
|
85
|
'indexes' => array(
|
86
|
'module' => array('module'),
|
87
|
'entity_type' => array('entity_type'),
|
88
|
'entity_id' => array('entity_id'),
|
89
|
),
|
90
|
);
|
91
|
|
92
|
return $schema;
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* Implements hook_field_schema().
|
97
|
*/
|
98
|
function commerce_price_field_schema($field) {
|
99
|
if ($field['type'] == 'commerce_price') {
|
100
|
return array(
|
101
|
'columns' => array(
|
102
|
'amount' => array(
|
103
|
'description' => 'The price amount.',
|
104
|
'type' => 'int',
|
105
|
'not null' => TRUE,
|
106
|
'default' => 0,
|
107
|
),
|
108
|
'currency_code' => array(
|
109
|
'description' => 'The currency code for the price.',
|
110
|
'type' => 'varchar',
|
111
|
'length' => 32,
|
112
|
'not null' => TRUE,
|
113
|
),
|
114
|
'data' => array(
|
115
|
'description' => 'A serialized array of additional price data.',
|
116
|
'type' => 'text',
|
117
|
'size' => 'big',
|
118
|
'not null' => FALSE,
|
119
|
'serialize' => TRUE,
|
120
|
),
|
121
|
),
|
122
|
'indexes' => array(
|
123
|
'currency_price' => array('amount', 'currency_code'),
|
124
|
),
|
125
|
);
|
126
|
}
|
127
|
}
|
128
|
|
129
|
/**
|
130
|
* Implements hook_uninstall().
|
131
|
*/
|
132
|
function commerce_price_uninstall() {
|
133
|
// Delete any price fields.
|
134
|
module_load_include('module', 'commerce');
|
135
|
commerce_delete_fields('commerce_price');
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* Fix invalid data values on price fields if necessary.
|
140
|
*/
|
141
|
function commerce_price_update_7100() {
|
142
|
$fields = field_info_fields();
|
143
|
$message = '';
|
144
|
|
145
|
foreach ($fields as $field_name => $field) {
|
146
|
// Only update fields stored in the default sql storage type in order to
|
147
|
// speed up the process.
|
148
|
if ($field['type'] == 'commerce_price' && $field['storage']['module'] == 'field_sql_storage') {
|
149
|
db_query("UPDATE {field_data_" . $field_name . "} SET " . $field_name . "_data = :data WHERE " . $field_name . "_data = 'Array';", array(':data' => NULL));
|
150
|
db_query("UPDATE {field_revision_" . $field_name . "} SET " . $field_name . "_data = :data WHERE " . $field_name . "_data = 'Array';", array(':data' => NULL));
|
151
|
|
152
|
$message = t('Price fields were cleaned of invalid data values as necessary.');
|
153
|
}
|
154
|
}
|
155
|
|
156
|
if (!empty($message)) {
|
157
|
return $message;
|
158
|
}
|
159
|
}
|