-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshipwire.install
330 lines (319 loc) · 10.2 KB
/
shipwire.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<?php
/**
* @file
* Uninstall functions for the shipwire module.
*/
/**
* Implements hook_schema().
*/
function shipwire_schema() {
$schema = array();
$schema['shipwire_shipments'] = array(
'description' => 'Stores Shipwire shipment information.',
'fields' => array(
'shipwire_shipment_id' => array(
'description' => 'Primary key: local shipment ID.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'type' => array(
'description' => 'The bundle type',
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
),
'order_id' => array(
'description' => 'The order id that the shipment is for.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
),
'order_prefix' => array(
'description' => 'Order prefix prepended to order id.',
'type' => 'varchar',
'length' => 25,
'not null' => TRUE,
),
'shipwire_id' => array(
'description' => 'Shipwire shipment id.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'shipwire_uri' => array(
'description' => 'The URI to the shipment on the Shipwire site.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'shipping_method' => array(
'description' => 'Shipping method id.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'status' => array(
'description' => 'The current status of the shipment.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'trackable' => array(
'description' => 'Whether the shipment is tracked by the carrier.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
),
'carrier_code' => array(
'description' => 'Shipwire code identifying the shipping company and delivery method.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '0',
),
'carrier_name' => array(
'description' => 'Name of shipping company and delivery method.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'warehouse_code' => array(
'description' => 'Code identifying the warehouse the shipment was sent from.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'date_submitted' => array(
'description' => 'The Unix timestamp indicating when the shipment was submitted to Shipwire.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
),
'date_shipped' => array(
'description' => 'The Unix timestamp indicating when the shipment left Shipwire warehouse.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
),
'date_expected' => array(
'description' => 'The Unix timestamp indicating the expected date of delivery.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
),
'date_delivered' => array(
'description' => 'The Unix timestamp indicating the date of delivery.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
),
'tracking_number' => array(
'description' => 'Number used to locate the shipment while it is in transit.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'tracking_uri' => array(
'description' => 'The URI to a site that provides tracking information.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'currency' => array(
'description' => 'ISO 4217 3 digit currency code for the costs.',
'type' => 'varchar',
'length' => 3,
'not null' => TRUE,
'default' => '',
),
'cost_total' => array(
'description' => 'Total cost of the shipment as decimal.',
'type' => 'numeric',
'precision' => 16,
'scale' => 5,
'not null' => TRUE,
'default' => 0.0,
),
'cost_freight' => array(
'description' => 'Freight cost of the shipment as decimal.',
'type' => 'numeric',
'precision' => 16,
'scale' => 5,
'not null' => TRUE,
'default' => 0.0,
),
'cost_handling' => array(
'description' => 'Handling cost of the shipment as decimal.',
'type' => 'numeric',
'precision' => 16,
'scale' => 5,
'not null' => TRUE,
'default' => 0.0,
),
'cost_packaging' => array(
'description' => 'Packaging cost of the shipment as decimal.',
'type' => 'numeric',
'precision' => 16,
'scale' => 5,
'not null' => TRUE,
'default' => 0.0,
),
'cost_insurance' => array(
'description' => 'Insurance cost of the shipment as decimal.',
'type' => 'numeric',
'precision' => 16,
'scale' => 5,
'not null' => TRUE,
'default' => 0.0,
),
'manually_edited' => array(
'description' => 'Whether the shipment order was manually edited in Shipwire.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
),
'created' => array(
'description' => 'The Unix timestamp indicating the time the shipment was created.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp indicating the last time the shipment was modified.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
),
'messages' => array(
'description' => 'A serialized array of messages.',
'type' => 'text',
'serialize' => TRUE,
),
'data' => array(
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized array of additional data.',
),
),
'primary key' => array('shipwire_shipment_id'),
);
$schema['cache_shipwire_rates'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_shipwire_rates']['description'] = 'Cache table for the temporary storage of shipping rates for orders.';
$schema['cache_shipwire_rates']['fields']['cid']['description'] = 'Primary Key: Order ID and shipping method the rates are for.';
return $schema;
}
/**
* Implements hook_field_schema().
*/
function shipwire_field_schema($field) {
if ($field['type'] == 'shipwire_shipment_reference') {
return array(
'columns' => array(
'shipwire_shipment_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
),
'indexes' => array(
'shipwire_shipment_id' => array('shipwire_shipment_id'),
),
'foreign keys' => array(
'shipwire_shipment_id' => array(
'table' => 'shipwire_shipments',
'columns' => array('shipwire_shipment_id' => 'shipwire_shipment_id'),
),
),
);
}
}
/**
* Implements hook_install().
*/
function shipwire_install() {
if (!field_info_field('shipwire_shipments')) {
// To make the field type 'shipwire_shipment_reference' defined in this
// module the field cache must be cleared.
field_info_cache_clear();
$field = array(
'field_name' => 'shipwire_shipments',
'type' => 'shipwire_shipment_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'translatable' => FALSE,
'settings' => array(),
);
field_create_field($field);
}
}
/**
* Implements hook_uninstall().
*/
function shipwire_uninstall() {
$field = field_info_field('shipwire_shipments');
if ($field) {
field_delete_field($field['field_name']);
field_purge_field($field);
}
variable_del('shipwire_server');
variable_del('shipwire_response');
variable_del('shipwire_account');
variable_del('shipwire_operational');
variable_del('shipwire_log_errors');
variable_del('shipwire_log_xml_request');
variable_del('shipwire_log_xml_response');
variable_del('shipwire_cache_life');
variable_del('shipwire_fulfill_max');
variable_del('shipwire_fullfill_freq');
variable_del('shipwire_track_max');
variable_del('shipwire_track_freq');
variable_del('shipwire_inventory_max');
variable_del('shipwire_inventory_freq');
variable_del('shipwire_email_share');
}
/**
* Update access control on Shipwire Shipwments view.
*/
function shipwire_update_7103() {
$view = views_get_view('shipwire_shipments');
if ($view) {
if ($view->display['default']->display_options['access']['type'] == 'none') {
$view->display['default']->display_options['access']['type'] = 'perm';
$view->display['default']->display_options['access']['perm'] = 'view all shipwire shipments';
$view->save();
return t('View "@view_name" access permissions updated. Please check user permissions.', array('@view_name' => $view->human_name));
}
elseif ($view->display['default']->display_options['access']['type'] == 'perm' &&
$view->display['default']->display_options['access']['perm'] == 'view all shipwire shipments') {
return t('View "@view_name" access permissions checked. No update required.', array('@view_name' => $view->human_name));
}
else {
$perms = shipwire_permission();
return t('Please check view "@view_name" access control and make sure it is restricted by permission "@perm".', array(
'@view_name' => $view->human_name,
'@perm' => $perms['view all shipwire shipments']['title'],
));
}
}
}