-
Notifications
You must be signed in to change notification settings - Fork 0
/
uc_fedex.install
215 lines (184 loc) · 6.65 KB
/
uc_fedex.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
<?php
/**
* @file
* Install, update, and uninstall functions for the uc_fedex module.
*
* @author Tim Rohaly. <http://drupal.org/user/202830>
*/
/**
* Implements hook_requirements().
*/
function uc_fedex_requirements($phase) {
$t = get_t();
// Check that the PHP SOAP extension is loaded
$has_soap = extension_loaded('soap');
$requirements['uc_fedex_soap'] = array(
'title' => $t('SOAP'),
'value' => $has_soap ? $t('Installed') : $t('Not Installed'),
);
if (!$has_soap) {
$requirements['uc_fedex_soap']['severity'] = REQUIREMENT_ERROR;
$requirements['uc_fedex_soap']['description'] = $t("The FedEx API requires the PHP <a href='!soap_url'>SOAP</a> library.", array('!soap_url' => 'http://www.php.net/soap'));
}
return $requirements;
}
/**
* Implements hook_schema().
*/
function uc_fedex_schema() {
$schema = array();
$schema['uc_fedex_products'] = array(
'description' => 'Stores product information for FedEx shipping quotes.',
'fields' => array(
'vid' => array(
'description' => 'The {uc_products}.vid.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'nid' => array(
'description' => 'The {uc_products}.nid.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'pkg_type' => array(
'description' => 'The type of package in which the product will be shipped.',
'type' => 'varchar',
'length' => 2,
'not null' => TRUE,
'default' => '',
),
),
'primary key' => array('vid'),
);
return $schema;
}
/**
* Implements hook_uninstall().
*
* Removes all tables and variables inserted into the
* database by this module.
*/
function uc_fedex_uninstall() {
// Remove all module variables from the database
variable_del('uc_fedex_user_credential_key');
variable_del('uc_fedex_user_credential_password');
variable_del('uc_fedex_account_number');
variable_del('uc_fedex_freight_account_number');
variable_del('uc_fedex_meter_number');
variable_del('uc_fedex_server_role');
variable_del('uc_fedex_ground_services');
variable_del('uc_fedex_express_services');
variable_del('uc_fedex_freight_services');
variable_del('uc_fedex_quote_type');
variable_del('uc_fedex_dropoff_type');
variable_del('uc_fedex_package_type');
variable_del('uc_fedex_all_in_one');
variable_del('uc_fedex_insurance');
variable_del('uc_fedex_freight_min_length');
variable_del('uc_fedex_freight_extreme_length');
variable_del('uc_fedex_freight_class');
variable_del('uc_fedex_rate_markup');
variable_del('uc_fedex_rate_markup_type');
variable_del('uc_fedex_weight_markup');
variable_del('uc_fedex_weight_markup_type');
variable_del('uc_fedex_address_validation');
variable_del('uc_fedex_residential_quotes');
variable_del('uc_fedex_checkout_validation');
variable_del('uc_fedex_label_image_format');
variable_del('uc_fedex_label_stock');
variable_del('uc_fedex_label_orientation');
variable_del('uc_fedex_label_lifetime');
}
/**
* Implements hook_update_N().
*/
function uc_fedex_update_6200() {
$ret = array();
$schema = drupal_get_schema('uc_fedex_products', TRUE);
db_create_table($ret, 'uc_fedex_products', $schema);
return $ret;
}
/**
* Implements hook_update_N().
*
* Refactor uc_fedex shipping method into three separate methods:
* Ground, Express, and Freight. Ensure that service selections
* are transferred from the old method to the new methods. If FedEx
* was enabled at admin/store/settings/quotes/methods, figure out
* which of the new methods should be enabled based on the service
* selections.
*/
function uc_fedex_update_6201() {
$ret = array();
$services = variable_get('uc_fedex_services', NULL);
if (isset($services)) {
$ground_services = array();
$freight_services = array();
// Remove ground services from list of services
if (isset($services['FEDEX_GROUND'])) {
$ground_services['FEDEX_GROUND'] = $services['FEDEX_GROUND'];
unset($services['FEDEX_GROUND']);
}
if (isset($services['GROUND_HOME_DELIVERY'])) {
$ground_services['GROUND_HOME_DELIVERY'] = $services['GROUND_HOME_DELIVERY'];
unset($services['GROUND_HOME_DELIVERY']);
}
// Remove freight services from list of services
if (isset($services['FEDEX_1_DAY_FREIGHT'])) {
$freight_services['FEDEX_1_DAY_FREIGHT'] = $services['FEDEX_1_DAY_FREIGHT'];
unset($services['FEDEX_1_DAY_FREIGHT']);
}
if (isset($services['FEDEX_2_DAY_FREIGHT'])) {
$freight_services['FEDEX_2_DAY_FREIGHT'] = $services['FEDEX_2_DAY_FREIGHT'];
unset($services['FEDEX_2_DAY_FREIGHT']);
}
if (isset($services['FEDEX_3_DAY_FREIGHT'])) {
$freight_services['FEDEX_3_DAY_FREIGHT'] = $services['FEDEX_3_DAY_FREIGHT'];
unset($services['FEDEX_3_DAY_FREIGHT']);
}
if (isset($services['INTERNATIONAL_ECONOMY_FREIGHT'])) {
$freight_services['INTERNATIONAL_ECONOMY_FREIGHT'] = $services['INTERNATIONAL_ECONOMY_FREIGHT'];
unset($services['INTERNATIONAL_ECONOMY_FREIGHT']);
}
if (isset($services['INTERNATIONAL_PRIORITY_FREIGHT'])) {
$freight_services['INTERNATIONAL_PRIORITY_FREIGHT'] = $services['INTERNATIONAL_PRIORITY_FREIGHT'];
unset($services['INTERNATIONAL_PRIORITY_FREIGHT']);
}
if (isset($services['INTERNATIONAL_DISTRIBUTION_FREIGHT'])) {
$freight_services['INTERNATIONAL_DISTRIBUTION_FREIGHT'] = $services['INTERNATIONAL_DISTRIBUTION_FREIGHT'];
unset($services['INTERNATIONAL_DISTRIBUTUION_FREIGHT']);
}
// Create new variables with services separated out
variable_set('uc_fedex_ground_services', $ground_services);
variable_set('uc_fedex_express_services', $services);
variable_set('uc_fedex_freight_services', $freight_services);
variable_del('uc_fedex_services', $services);
// If FedEx quotes are enabled, figure out which services are
// being used and make sure the correct new methods are enabled
$enabled = variable_get('uc_quote_enabled', array());
if ($enabled['fedex']) {
if (count($ground_services)) $enabled['fedex_ground'] = TRUE;
if (count($services) == 0) $enabled['fedex'] = FALSE;
if (count($freight_services)) $enabled['fedex_freight'] = TRUE;
variable_set('uc_quote_enabled', $enabled);
}
}
return $ret;
}
/**
* Implements hook_update_N().
*
* Change the order of shipping method quotes display on checkout.
*/
function uc_fedex_update_7201() {
variable_set('uc_quote_method_weight', array(
'fedex_ground' => '-10',
'fedex' => '-9',
'fedex_freight' => '-8',
)
);
}