forked from AcroMedia/commerce_pos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commerce_pos.install
247 lines (223 loc) · 6.91 KB
/
commerce_pos.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
/**
* @file
* Schema and install hooks for commerce_pos.
*/
/**
* Implements hook_schema().
*/
function commerce_pos_schema() {
$schema['commerce_pos_transaction'] = array(
'description' => 'The base table for POS transactions',
'fields' => array(
'transaction_id' => array(
'description' => 'The primary identifier for a transaction.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'description' => 'The user ID that this transaction belongs to, generally the employee logged into the POS.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'cashier' => array(
'description' => 'The ID of the cashier that the transaction belongs to. Generally the last cashier to update the transaction.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'order_id' => array(
'description' => 'The order ID for this transaction.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'type' => array(
'description' => 'The type of transaction this is. E.g. sale or return',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'register_id' => array(
'description' => 'The physical register that this transaction was performed at.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'data' => array(
'description' => 'A serialized array of additional data.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
),
'created' => array(
'description' => 'The Unix timestamp when the transaction was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the transaction was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'completed' => array(
'description' => 'The Unix timestamp when the transaction completed.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'transaction_order_id' => array('order_id'),
'transaction_uid' => array('uid'),
'register_id' => array('register_id'),
),
'unique keys' => array(
'order_id_uid' => array('order_id', 'uid'),
),
'primary key' => array('transaction_id'),
);
return $schema;
}
/**
* Implements hook_uninstall().
*/
function commerce_pos_uninstall() {
// Clean up variables.
variable_del('commerce_pos_search_api_index');
variable_del('commerce_pos_available_products');
variable_del('commerce_pos_search_results_count');
foreach (commerce_product_types() as $name => $type) {
variable_del('commerce_pos_image_field_' . $name);
// Also remove any default images.
if ($fid = variable_get('commerce_pos_image_default_' . $name, 0)) {
$file = file_load($fid);
file_delete($file, TRUE);
}
variable_del('commerce_pos_image_default_' . $name);
}
}
/**
* Implements hook_requirements().
*/
function commerce_pos_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
$t = get_t();
$jquery = drupal_get_library('system', 'jquery');
$version = $jquery['version'];
$requirements['commerce_pos'] = array(
'title' => $t('Commerce Point of Sale'),
'severity' => REQUIREMENT_OK,
'value' => $t('jQuery %jquery (<a href="@link">configure</a>)', array(
'%jquery' => $jquery['version'],
'@link' => url('admin/config/development/jquery_update'),
)),
);
if (version_compare($version, '1.7', '<')) {
$requirements['commerce_pos']['severity'] = REQUIREMENT_ERROR;
$requirements['commerce_pos']['description'] = $t('Commerce Point of Sale requires jQuery 1.7 or higher.');
}
}
return $requirements;
}
/**
* Implements hook_enable().
*/
function commerce_pos_enable() {
commerce_pos_user_phone_number_configure();
}
/**
* Change 'type' field from an integer field to a varchar.
*/
function commerce_pos_update_7001(&$sandbox) {
db_change_field('commerce_pos_transaction', 'type', 'type', array(
'description' => 'The type of transaction this is. E.g. sale or return',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
));
db_update('commerce_pos_transaction')
->fields(array(
'type' => CommercePosService::TRANSACTION_TYPE_RETURN,
))
->condition('type', 2)
->execute();
db_update('commerce_pos_transaction')
->fields(array(
'type' => CommercePosService::TRANSACTION_TYPE_SALE,
))
->condition('type', 1)
->execute();
}
/**
* Add 'completed' field to transactions table.
*/
function commerce_pos_update_7002(&$sandbox) {
db_add_field('commerce_pos_transaction', 'completed', array(
'description' => 'The Unix timestamp when the transaction completed.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
));
}
/**
* Enable cashier sub-module.
*/
function commerce_pos_update_7203() {
$t = get_t();
db_add_field('commerce_pos_transaction', 'cashier', array(
'description' => 'The ID of the cashier that the transaction belongs to. Generally the last cashier to update the transaction.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'initial' => 0,
));
module_enable(array('commerce_pos_cashier'));
return $t('This Point of Sale update introduces Cashiers, which are required to operate the POS. Please go !link to add one or more now.', array(
'!link' => l('here', 'admin/commerce/config/pos/cashiers'),
));
}
/**
* Update location_id to register_id
*/
function commerce_pos_update_7204() {
if(!db_field_exists('commerce_pos_transaction', 'register_id')) {
$spec = array(
'description' => 'The physical register that this transaction was performed at.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
);
db_add_field('commerce_pos_transaction', 'register_id', $spec);
db_add_index('commerce_pos_transaction', 'register_id', array(array('register_id', 4)));
// Check for existing data in the location_id column. If there is none, it's
// safe to drop it now.
$locations = db_select('commerce_pos_transaction', 'cpt')
->condition('cpt.location_id', 0, '!=')
->countQuery()
->execute()
->fetchField();
if (!$locations) {
db_drop_field('commerce_pos_transaction', 'location_id');
}
}
}
/**
* Add 'phone' field to user entity.
*/
function commerce_pos_update_7205(&$sandbox) {
commerce_pos_user_phone_number_configure();
}