-
Notifications
You must be signed in to change notification settings - Fork 0
/
uc_fedex.admin.inc
497 lines (441 loc) · 21.9 KB
/
uc_fedex.admin.inc
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<?php
/**
* @file
* FedEx Shipping Quotes module administration menu and callbacks.
*
* @author Tim Rohaly. <http://drupal.org/user/202830>
*/
/**
* Default FedEx Web Services API settings.
*
* Records FedEx account information neccessary to use service. Allows testing
* or production mode. Configures which FedEx services are quoted to customers.
*
* @return
* Forms for store administrator to set configuration options.
*
* @see uc_fedex_admin_settings_validate()
* @ingroup forms
*/
function uc_fedex_admin_settings() {
// Label printing routines.
module_load_include('inc', 'uc_fedex', 'uc_fedex.ship');
// Container for credentials forms.
$form['uc_fedex_credentials'] = array(
'#type' => 'fieldset',
'#title' => t('Credentials'),
'#description' => t('Account number and authorization information.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// Form to set the developer key.
$form['uc_fedex_credentials']['uc_fedex_user_credential_key'] = array(
'#type' => 'textfield',
'#title' => t('FedEx Web Services API User Key'),
'#default_value' => variable_get('uc_fedex_user_credential_key', ''),
'#required' => TRUE,
);
// Form to set the developer password.
$form['uc_fedex_credentials']['uc_fedex_user_credential_password'] = array(
'#type' => 'password',
'#title' => t('FedEx Web Services API Password'),
'#default_value' => variable_get('uc_fedex_user_credential_password', ''),
);
// Form to set user account number.
$form['uc_fedex_credentials']['uc_fedex_account_number'] = array(
'#type' => 'textfield',
'#title' => t('FedEx Account #'),
'#default_value' => variable_get('uc_fedex_account_number', 0),
'#required' => TRUE,
);
// Form to set user meter number.
$form['uc_fedex_credentials']['uc_fedex_meter_number'] = array(
'#type' => 'textfield',
'#title' => t('FedEx Meter #'),
'#default_value' => variable_get('uc_fedex_meter_number', 0),
'#required' => TRUE,
);
// Form to set choose between Production and Testing server.
// ***Defaults to Testing!***
$form['uc_fedex_credentials']['uc_fedex_server_role'] = array(
'#type' => 'select',
'#title' => t('FedEx Server Role'),
'#description' => t('Use the Testing server while developing and configuring your site. Switch to the Production server only after you have demostrated that transactions on the Testing server are working and you are ready to go live.'),
'#options' => array(
'testing' => t('Testing'),
'production' => t('Production'),
),
'#default_value' => variable_get('uc_fedex_server_role', 'testing'),
);
// Form to set freight account number.
$form['uc_fedex_credentials']['uc_fedex_freight_account_number'] = array(
'#type' => 'textfield',
'#title' => t('FedEx Freight Account #'),
'#default_value' => variable_get('uc_fedex_freight_account_number', 0),
'#required' => FALSE,
);
// Container for service selection forms.
$form['uc_fedex_service_selection'] = array(
'#type' => 'fieldset',
'#title' => t('Service Options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// Form to restrict FedEx Ground services available to customer.
$form['uc_fedex_service_selection']['uc_fedex_ground_services'] = array(
'#type' => 'checkboxes',
'#title' => t('FedEx Ground Services'),
'#default_value' => variable_get('uc_fedex_ground_services', _uc_fedex_ground_services()),
'#options' => _uc_fedex_ground_services(),
'#description' => t('Select the FedEx Ground services customers are allowed to use.'),
);
if (module_exists('rules')) {
$form['uc_fedex_service_selection']['uc_fedex_ground_conditions'] = array(
'#type' => 'fieldset',
'#title' => t('FedEx Ground service conditions'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$conditions = rules_config_load('get_quote_from_fedex_ground');
if ($conditions) {
$conditions->form($form['uc_fedex_service_selection']['uc_fedex_ground_conditions'], $form_state);
}
}
// Form to restrict FedEx Express services available to customer.
$form['uc_fedex_service_selection']['uc_fedex_express_services'] = array(
'#type' => 'checkboxes',
'#title' => t('FedEx Express Services'),
'#default_value' => variable_get('uc_fedex_express_services', _uc_fedex_express_services()),
'#options' => _uc_fedex_express_services(),
'#description' => t('Select the FedEx Express services customers are allowed to use.'),
);
if (module_exists('rules')) {
$form['uc_fedex_service_selection']['uc_fedex_express_conditions'] = array(
'#type' => 'fieldset',
'#title' => t('FedEx Express service conditions'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$conditions = rules_config_load('get_quote_from_fedex');
if ($conditions) {
$conditions->form($form['uc_fedex_service_selection']['uc_fedex_express_conditions'], $form_state);
}
}
// Form to restrict FedEx Freight services available to customer.
$form['uc_fedex_service_selection']['uc_fedex_freight_services'] = array(
'#type' => 'checkboxes',
'#title' => t('FedEx Freight Services'),
'#default_value' => variable_get('uc_fedex_freight_services', _uc_fedex_freight_services()),
'#options' => _uc_fedex_freight_services(),
'#description' => t('Select the FedEx Freight services customers are allowed to use.'),
);
if (module_exists('rules')) {
$form['uc_fedex_service_selection']['uc_fedex_freight_conditions'] = array(
'#type' => 'fieldset',
'#title' => t('FedEx Freight service conditions'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$conditions = rules_config_load('get_quote_from_fedex_freight');
if ($conditions) {
$conditions->form($form['uc_fedex_service_selection']['uc_fedex_freight_conditions'], $form_state);
}
}
// Container for quote options forms.
$form['uc_fedex_quote_options'] = array(
'#type' => 'fieldset',
'#title' => t('Quote Options'),
'#description' => t('Preferences that affect computation of quote.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
/* Form to set choose between LIST quotes and ACCOUNT quotes
* ***Defaults to LIST!***
* Valid values:
* LIST — Returns standard list in response.
* PREFERRED — Returns rates in currency specified in the
* PreferredCurrency element.
* NONE — Returns account specific rates in response.
*
* We do not include PREFERRED option in this integration
* as it does not provide value to the client.
*/
$form['uc_fedex_quote_options']['uc_fedex_quote_type'] = array(
'#type' => 'select',
'#title' => t('FedEx Quote Type'),
'#description' => t('Choose to present the customer with FedEx list prices or your discounted FedEx account prices. LIST prices only exist for US shipments - if you specify LIST for international shipments you will not receive any quotes. Note that ACCOUNT prices are accurate only on the PRODUCTION server!'),
'#options' => array(
'list' => t('List Prices'),
'none' => t('Discount Account Prices'),
),
'#default_value' => variable_get('uc_fedex_quote_type', 'list'),
);
// Form to set how the package is handed over to FedEx.
$form['uc_fedex_quote_options']['uc_fedex_dropoff_type'] = array(
'#type' => 'select',
'#title' => t('FedEx Pickup/Dropoff Options'),
'#default_value' => variable_get('uc_fedex_dropoff_type', _uc_fedex_dropoff_types()),
'#options' => _uc_fedex_dropoff_types(),
'#description' => t('Pickup/Dropoff options. It is assumed that all your packages are using the same method.'),
);
// Form to select FedEx packaging to use.
$form['uc_fedex_quote_options']['uc_fedex_package_type'] = array(
'#type' => 'select',
'#title' => t('FedEx Package Type'),
'#default_value' => variable_get('uc_fedex_package_type', _uc_fedex_package_types()),
'#options' => _uc_fedex_package_types(),
'#description' => t('Package Type. It is assumed that all your packages are using the same packaging.<br/><i>NOTE: This setting does not apply to Freight Quotes.</i>'),
);
// Form to select packaging type.
$form['uc_fedex_quote_options']['uc_fedex_all_in_one'] = array(
'#type' => 'radios',
'#title' => t('Number of Packages'),
'#default_value' => variable_get('uc_fedex_all_in_one', 1),
'#options' => array(
0 => t('Each product in its own package'),
1 => t('All products in one package'),
),
'#description' => t('Indicate whether each product is quoted as shipping separately or all in one package.'),
);
// Form to add optional Insurance coverage in the amount of the order.
$form['uc_fedex_quote_options']['uc_fedex_insurance'] = array(
'#type' => 'checkbox',
'#title' => t('Add Insurance to shipping quote'),
'#default_value' => variable_get('uc_fedex_insurance', FALSE),
'#description' => t('When enabled, products are insured for their full value.'),
);
// Form to select FedEx Freight Class.
$form['uc_fedex_quote_options']['uc_fedex_freight_class'] = array(
'#type' => 'select',
'#title' => t('FedEx Freight Class'),
'#default_value' => variable_get('uc_fedex_freight_class', 'CLASS_070'),
'#options' => _uc_fedex_freight_class_list(),
'#description' => t('Freight Class. It is assumed that all your packages/shipments are using the same class.'),
);
$length_units = array(
'in' => t('Inches'),
'ft' => t('Feet'),
'cm' => t('Centimeters'),
'mm' => t('Millimeters'),
);
// Form to set minimum shipment length that defines when
// FedEx Freight quote rates are requested and displayed to the customer.
$form['uc_fedex_quote_options']['uc_fedex_freight_min_length_values_title'] = array(
"#type" => 'markup',
'#markup' => '<label>' . t('FedEx Freight Quote - Minimum Length') . '</label>',
);
$form['uc_fedex_quote_options']['uc_fedex_freight_min_length_values'] = array(
'#type' => 'container',
'#attributes' => array('class' => array('uc-inline-form', 'uc-fedex-inline-form-markup', 'clearfix')),
);
$form['uc_fedex_quote_options']['uc_fedex_freight_min_length_values']['uc_fedex_freight_min_length'] = array(
'#type' => 'textfield',
'#title' => t('Length'),
'#default_value' => variable_get('uc_fedex_freight_min_length', '9'),
'#size' => 10,
);
$form['uc_fedex_quote_options']['uc_fedex_freight_min_length_values']['uc_fedex_freight_min_length_units'] = array(
'#type' => 'select',
'#title' => t('Units'),
'#default_value' => variable_get('uc_fedex_freight_min_length_units', 'FT'),
'#options' => $length_units,
);
$form['uc_fedex_quote_options']['uc_fedex_freight_min_length_values_desc'] = array(
"#type" => 'markup',
'#markup' => '<div class="uc-fedex-markup-desc description">' . t('Minimum length of the shipment that will trigger the display of FedEx Freight quote rates.<br/>If left at 0 - FedEx Freight quote rates will be displayed at all times.') . '</div>',
);
// Form to set minimum package number that defines when
// FedEx Freight quote rates are requested and displayed to the customer.
$form['uc_fedex_quote_options']['uc_fedex_freight_min_pkg_num'] = array(
'#type' => 'textfield',
'#title' => t('FedEx Freight - MIN Number of Packages'),
'#default_value' => variable_get('uc_fedex_freight_min_pkg_num', ''),
'#description' => t('Minimum number of packages that will trigger display of Freight quotes.'),
'#size' => 10,
);
// Form to set current EXTREME_LENGTH limit for FedEx Freight.
$form['uc_fedex_quote_options']['uc_fedex_freight_extreme_length_values_title'] = array(
"#type" => 'markup',
'#markup' => '<label>' . t('FedEx Freight - Extreme Length') . '</label>',
);
$form['uc_fedex_quote_options']['uc_fedex_freight_extreme_length_values'] = array(
'#type' => 'container',
'#attributes' => array('class' => array('uc-inline-form', 'uc-fedex-inline-form-markup', 'clearfix')),
);
$form['uc_fedex_quote_options']['uc_fedex_freight_extreme_length_values']['uc_fedex_freight_extreme_length'] = array(
'#type' => 'textfield',
'#title' => t('Length'),
'#default_value' => variable_get('uc_fedex_freight_extreme_length', '15'),
'#size' => 10,
'#states' => array(
// Only make required when Freight Account Number is not empty.
'required' => array(
':input[name="uc_fedex_freight_account_number"]' => array('!value' => '0'),
),
),
);
$form['uc_fedex_quote_options']['uc_fedex_freight_extreme_length_values']['uc_fedex_freight_extreme_length_units'] = array(
'#type' => 'select',
'#title' => t('Units'),
'#default_value' => variable_get('uc_fedex_freight_extreme_length_units', 'FT'),
'#options' => $length_units,
);
$form['uc_fedex_quote_options']['uc_fedex_freight_extreme_length_values_desc'] = array(
"#type" => 'markup',
'#markup' => '<div class="uc-fedex-markup-desc description">' . t('EXTREME_LENGTH limit according to current FedEx Freight regulations.<br/>This value will affect shipping rates and must be updated as soon as new FedEx Freight regulations come in effect.<br/>As of November 2017 - EXTREME_LENGTH surcharges will applied to shipments over 15ft/180in length. Starting January 2, 2017 - 12ft/144in.') . '</div>',
);
// Container for markup forms.
$form['uc_fedex_markups'] = array(
'#type' => 'fieldset',
'#title' => t('Markups'),
'#description' => t('Modifiers to the shipping weight and quoted rate.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// Form to select type of rate markup.
$form['uc_fedex_markups']['uc_fedex_rate_markup_type'] = array(
'#type' => 'select',
'#title' => t('Rate Markup Type'),
'#default_value' => variable_get('uc_fedex_rate_markup_type', 'percentage'),
'#options' => array(
'percentage' => t('Percentage (%)'),
'multiplier' => t('Multiplier (×)'),
'currency' => t('Addition (!currency)', array('!currency' => variable_get('uc_currency_sign', '$'))),
),
);
// Form to select rate markup amount.
$form['uc_fedex_markups']['uc_fedex_rate_markup'] = array(
'#type' => 'textfield',
'#title' => t('FedEx Shipping Rate Markup'),
'#default_value' => variable_get('uc_fedex_rate_markup', '0'),
'#description' => t('Markup FedEx shipping rate quote by dollar amount, percentage, or multiplier.'),
);
// Form to select type of weight markup.
$form['uc_fedex_markups']['uc_fedex_weight_markup_type'] = array(
'#type' => 'select',
'#title' => t('Weight Markup Type'),
'#default_value' => variable_get('uc_fedex_weight_markup_type', 'percentage'),
'#options' => array(
'percentage' => t('Percentage (%)'),
'multiplier' => t('Multiplier (×)'),
'mass' => t('Addition (!mass)', array('!mass' => '#')),
),
);
// Form to select weight markup amount.
$form['uc_fedex_markups']['uc_fedex_weight_markup'] = array(
'#type' => 'textfield',
'#title' => t('FedEx Shipping Weight Markup'),
'#default_value' => variable_get('uc_fedex_weight_markup', '0'),
'#description' => t('Markup FedEx shipping weight on a per-package basis before quote, by weight amount, percentage, or multiplier.'),
);
// Container for validation forms.
$form['uc_fedex_validation'] = array(
'#type' => 'fieldset',
'#title' => t('Address Validation'),
'#description' => t('Preferences for FedEx Address Validation. Additional permissions from FedEx are required to use this feature.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// Form to select Residential/Commercial destination address.
$form['uc_fedex_validation']['uc_fedex_address_validation'] = array(
'#type' => 'checkbox',
'#title' => t('Let FedEx determine if an address is Commercial or Residential'),
'#default_value' => variable_get('uc_fedex_address_validation', FALSE),
'#description' => t('When enabled, FedEx Address Validation Web Service will be used to determine if a shipping address is Commercial or Residential.'),
);
// Form to select Residential/Commercial destination address.
$form['uc_fedex_validation']['uc_fedex_residential_quotes'] = array(
'#type' => 'radios',
'#title' => t('Quote rates assuming destination is a'),
'#default_value' => variable_get('uc_fedex_residential_quotes', 1),
'#options' => array(
0 => t('Commercial address'),
1 => t('Residential address (extra fees)'),
),
'#description' => t('This selection will be used if Address Validation is disabled above, or if Address Validation is enabled and fails or times out.'),
);
// Form to select Residential/Commercial destination address.
$form['uc_fedex_validation']['uc_fedex_checkout_validation'] = array(
'#type' => 'checkbox',
'#title' => t('Enable checkout address validation'),
'#default_value' => variable_get('uc_fedex_checkout_validation', FALSE),
'#description' => t('When enabled, JavaScript will be used to validate the shipping address entered by the customer on the checkout page. Errors will be flagged immediately, before the order is submitted.'),
'#disabled' => TRUE,
);
// Container for label printing.
$form['uc_fedex_labels'] = array(
'#type' => 'fieldset',
'#title' => t('Label Printing'),
'#description' => t('Preferences for FedEx Shipping Label Printing. Additional permissions from FedEx are required to use this feature.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// Form to select label image format.
$form['uc_fedex_labels']['uc_fedex_label_image_format'] = array(
'#type' => 'select',
'#title' => t('Select image format for shipping labels'),
'#default_value' => variable_get('uc_fedex_label_image_format', 'PDF'),
'#options' => _uc_fedex_label_image_types(),
);
// Form to select label stock.
$form['uc_fedex_labels']['uc_fedex_label_stock'] = array(
'#type' => 'select',
'#title' => t('Select Laser or Thermal label stock size'),
'#default_value' => variable_get('uc_fedex_label_stock', 'PAPER_7X4.75'),
'#options' => _uc_fedex_label_stock_types(),
);
// Form to select label orientation.
$form['uc_fedex_labels']['uc_fedex_label_orientation'] = array(
'#type' => 'select',
'#title' => t('Select orientation for label printing'),
'#default_value' => variable_get('uc_fedex_label_orientation', _uc_fedex_label_orientation_types()),
'#options' => _uc_fedex_label_orientation_types(),
);
$period = drupal_map_assoc(array(86400, 302400, 604800, 1209600, 2419200, 0), 'format_interval');
$period[0] = t('Forever');
// Form to select how long labels stay on server.
$form['uc_fedex_labels']['uc_fedex_label_lifetime'] = array(
'#type' => 'select',
'#title' => t('Label lifetime'),
'#default_value' => variable_get('uc_fedex_label_lifetime', 604800),
'#options' => $period,
'#description' => t('Controls how long labels are stored on the server before being automatically deleted. Cron must be enabled for automatic deletion. Default lifetime is 1 week (604800 seconds).'),
);
// Register additional validation handler.
$form['#validate'][] = 'uc_fedex_admin_settings_validate';
return system_settings_form($form);
}
/**
* Validation handler for uc_fedex_admin_settings form.
*
* Requires password only if it hasn't been set.
*
* @see uc_fedex_admin_settings()
*/
function uc_fedex_admin_settings_validate($form, &$form_state) {
$old_password = variable_get('uc_fedex_user_credential_password', '');
if (!$form_state['values']['uc_fedex_user_credential_password']) {
if ($old_password) {
form_set_value($form['uc_fedex_credentials']['uc_fedex_user_credential_password'], $old_password, $form_state);
}
else {
form_set_error('uc_fedex_user_credential_password', t('Password field is required.'));
}
}
if (!is_numeric($form_state['values']['uc_fedex_rate_markup'])) {
form_set_error('uc_fedex_rate_markup', t('Rate markup must be a numeric value.'));
}
if (!is_numeric($form_state['values']['uc_fedex_weight_markup'])) {
form_set_error('uc_fedex_weight_markup', t('Weight markup must be a numeric value.'));
}
// Add validation for freight variables.
if (!is_numeric($form_state['values']['uc_fedex_freight_min_pkg_num']) && !empty($form_state['values']['uc_fedex_freight_min_pkg_num'])) {
form_set_error('uc_fedex_freight_min_pkg_num', t('"FedEx Freight - MIN Number of Packages" must be a numeric value.'));
}
if (!is_numeric($form_state['values']['uc_fedex_freight_extreme_length']) || $form_state['values']['uc_fedex_freight_extreme_length'] == 0) {
form_set_error('uc_fedex_freight_extreme_length_values][uc_fedex_freight_extreme_length', t('"FedEx Freight - Extreme Length" must be a numeric value and have a value than is greater than 0 when Freight Account Number is used.'));
}
if (!is_numeric($form_state['values']['uc_fedex_freight_min_length'])) {
form_set_error('uc_fedex_freight_min_length_values][uc_fedex_freight_min_length', t('"FedEx Freight Quote - Minimum Length" must be a numeric value.'));
}
}