aboutsummaryrefslogtreecommitdiffstats
path: root/public/admin/controller/extension/shipping/fedex.php
blob: 37a3f8e67eca367541460783d17162810de57387 (plain)
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
<?php
class ControllerExtensionShippingFedex extends Controller {
	private $error = array();

	public function index() {
		$this->load->language('extension/shipping/fedex');

		$this->document->setTitle($this->language->get('heading_title'));

		$this->load->model('setting/setting');

		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
			$this->model_setting_setting->editSetting('shipping_fedex', $this->request->post);

			$this->session->data['success'] = $this->language->get('text_success');

			$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true));
		}

		if (isset($this->error['warning'])) {
			$data['error_warning'] = $this->error['warning'];
		} else {
			$data['error_warning'] = '';
		}

		if (isset($this->error['key'])) {
			$data['error_key'] = $this->error['key'];
		} else {
			$data['error_key'] = '';
		}

		if (isset($this->error['password'])) {
			$data['error_password'] = $this->error['password'];
		} else {
			$data['error_password'] = '';
		}

		if (isset($this->error['account'])) {
			$data['error_account'] = $this->error['account'];
		} else {
			$data['error_account'] = '';
		}

		if (isset($this->error['meter'])) {
			$data['error_meter'] = $this->error['meter'];
		} else {
			$data['error_meter'] = '';
		}

		if (isset($this->error['postcode'])) {
			$data['error_postcode'] = $this->error['postcode'];
		} else {
			$data['error_postcode'] = '';
		}

		if (isset($this->error['dimension'])) {
			$data['error_dimension'] = $this->error['dimension'];
		} else {
			$data['error_dimension'] = '';
		}

		$data['breadcrumbs'] = array();

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_home'),
			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
		);

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_extension'),
			'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)
		);

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('heading_title'),
			'href' => $this->url->link('extension/shipping/fedex', 'user_token=' . $this->session->data['user_token'], true)
		);

		$data['action'] = $this->url->link('extension/shipping/fedex', 'user_token=' . $this->session->data['user_token'], true);

		$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true);

		if (isset($this->request->post['shipping_fedex_key'])) {
			$data['shipping_fedex_key'] = $this->request->post['shipping_fedex_key'];
		} else {
			$data['shipping_fedex_key'] = $this->config->get('shipping_fedex_key');
		}

		if (isset($this->request->post['shipping_fedex_password'])) {
			$data['shipping_fedex_password'] = $this->request->post['shipping_fedex_password'];
		} else {
			$data['shipping_fedex_password'] = $this->config->get('shipping_fedex_password');
		}

		if (isset($this->request->post['shipping_fedex_account'])) {
			$data['shipping_fedex_account'] = $this->request->post['shipping_fedex_account'];
		} else {
			$data['shipping_fedex_account'] = $this->config->get('shipping_fedex_account');
		}

		if (isset($this->request->post['shipping_fedex_meter'])) {
			$data['shipping_fedex_meter'] = $this->request->post['shipping_fedex_meter'];
		} else {
			$data['shipping_fedex_meter'] = $this->config->get('shipping_fedex_meter');
		}

		if (isset($this->request->post['shipping_fedex_postcode'])) {
			$data['shipping_fedex_postcode'] = $this->request->post['shipping_fedex_postcode'];
		} else {
			$data['shipping_fedex_postcode'] = $this->config->get('shipping_fedex_postcode');
		}

		if (isset($this->request->post['shipping_fedex_test'])) {
			$data['shipping_fedex_test'] = $this->request->post['shipping_fedex_test'];
		} else {
			$data['shipping_fedex_test'] = $this->config->get('shipping_fedex_test');
		}

		if (isset($this->request->post['shipping_fedex_service'])) {
			$data['shipping_fedex_service'] = $this->request->post['shipping_fedex_service'];
		} elseif ($this->config->has('shipping_fedex_service')) {
			$data['shipping_fedex_service'] = $this->config->get('shipping_fedex_service');
		} else {
			$data['shipping_fedex_service'] = array();
		}

		$data['services'] = array();

		$data['services'][] = array(
			'text'  => $this->language->get('text_europe_first_international_priority'),
			'value' => 'EUROPE_FIRST_INTERNATIONAL_PRIORITY'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_fedex_1_day_freight'),
			'value' => 'FEDEX_1_DAY_FREIGHT'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_fedex_2_day'),
			'value' => 'FEDEX_2_DAY'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_fedex_2_day_am'),
			'value' => 'FEDEX_2_DAY_AM'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_fedex_2_day_freight'),
			'value' => 'FEDEX_2_DAY_FREIGHT'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_fedex_3_day_freight'),
			'value' => 'FEDEX_3_DAY_FREIGHT'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_fedex_express_saver'),
			'value' => 'FEDEX_EXPRESS_SAVER'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_fedex_first_freight'),
			'value' => 'FEDEX_FIRST_FREIGHT'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_fedex_freight_economy'),
			'value' => 'FEDEX_FREIGHT_ECONOMY'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_fedex_freight_priority'),
			'value' => 'FEDEX_FREIGHT_PRIORITY'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_fedex_ground'),
			'value' => 'FEDEX_GROUND'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_first_overnight'),
			'value' => 'FIRST_OVERNIGHT'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_ground_home_delivery'),
			'value' => 'GROUND_HOME_DELIVERY'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_international_economy'),
			'value' => 'INTERNATIONAL_ECONOMY'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_international_economy_freight'),
			'value' => 'INTERNATIONAL_ECONOMY_FREIGHT'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_international_first'),
			'value' => 'INTERNATIONAL_FIRST'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_international_priority'),
			'value' => 'INTERNATIONAL_PRIORITY'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_international_priority_freight'),
			'value' => 'INTERNATIONAL_PRIORITY_FREIGHT'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_priority_overnight'),
			'value' => 'PRIORITY_OVERNIGHT'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_smart_post'),
			'value' => 'SMART_POST'
		);

		$data['services'][] = array(
			'text'  => $this->language->get('text_standard_overnight'),
			'value' => 'STANDARD_OVERNIGHT'
		);

		if (isset($this->request->post['shipping_fedex_length'])) {
			$data['shipping_fedex_length'] = $this->request->post['shipping_fedex_length'];
		} else {
			$data['shipping_fedex_length'] = $this->config->get('shipping_fedex_length');
		}

		if (isset($this->request->post['shipping_fedex_width'])) {
			$data['shipping_fedex_width'] = $this->request->post['shipping_fedex_width'];
		} else {
			$data['shipping_fedex_width'] = $this->config->get('shipping_fedex_width');
		}

		if (isset($this->request->post['shipping_fedex_height'])) {
			$data['shipping_fedex_height'] = $this->request->post['shipping_fedex_height'];
		} else {
			$data['shipping_fedex_height'] = $this->config->get('shipping_fedex_height');
		}

		if (isset($this->request->post['shipping_fedex_length_class_id'])) {
			$data['shipping_fedex_length_class_id'] = $this->request->post['shipping_fedex_length_class_id'];
		} else {
			$data['shipping_fedex_length_class_id'] = $this->config->get('shipping_fedex_length_class_id');
		}

		$this->load->model('localisation/length_class');

		$data['length_classes'] = $this->model_localisation_length_class->getLengthClasses();

		if (isset($this->request->post['shipping_fedex_dropoff_type'])) {
			$data['shipping_fedex_dropoff_type'] = $this->request->post['shipping_fedex_dropoff_type'];
		} else {
			$data['shipping_fedex_dropoff_type'] = $this->config->get('shipping_fedex_dropoff_type');
		}

		if (isset($this->request->post['shipping_fedex_packaging_type'])) {
			$data['shipping_fedex_packaging_type'] = $this->request->post['shipping_fedex_packaging_type'];
		} else {
			$data['shipping_fedex_packaging_type'] = $this->config->get('shipping_fedex_packaging_type');
		}

		if (isset($this->request->post['shipping_fedex_rate_type'])) {
			$data['shipping_fedex_rate_type'] = $this->request->post['shipping_fedex_rate_type'];
		} else {
			$data['shipping_fedex_rate_type'] = $this->config->get('shipping_fedex_rate_type');
		}

		if (isset($this->request->post['shipping_fedex_destination_type'])) {
			$data['shipping_fedex_destination_type'] = $this->request->post['shipping_fedex_destination_type'];
		} else {
			$data['shipping_fedex_destination_type'] = $this->config->get('shipping_fedex_destination_type');
		}

		if (isset($this->request->post['shipping_fedex_display_time'])) {
			$data['shipping_fedex_display_time'] = $this->request->post['shipping_fedex_display_time'];
		} else {
			$data['shipping_fedex_display_time'] = $this->config->get('shipping_fedex_display_time');
		}

		if (isset($this->request->post['shipping_fedex_display_weight'])) {
			$data['shipping_fedex_display_weight'] = $this->request->post['shipping_fedex_display_weight'];
		} else {
			$data['shipping_fedex_display_weight'] = $this->config->get('shipping_fedex_display_weight');
		}

		if (isset($this->request->post['shipping_fedex_weight_class_id'])) {
			$data['shipping_fedex_weight_class_id'] = $this->request->post['shipping_fedex_weight_class_id'];
		} else {
			$data['shipping_fedex_weight_class_id'] = $this->config->get('shipping_fedex_weight_class_id');
		}

		$this->load->model('localisation/weight_class');

		$data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses();

		if (isset($this->request->post['shipping_fedex_tax_class_id'])) {
			$data['shipping_fedex_tax_class_id'] = $this->request->post['shipping_fedex_tax_class_id'];
		} else {
			$data['shipping_fedex_tax_class_id'] = $this->config->get('shipping_fedex_tax_class_id');
		}

		$this->load->model('localisation/tax_class');

		$data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses();

		if (isset($this->request->post['shipping_fedex_geo_zone_id'])) {
			$data['shipping_fedex_geo_zone_id'] = $this->request->post['shipping_fedex_geo_zone_id'];
		} else {
			$data['shipping_fedex_geo_zone_id'] = $this->config->get('shipping_fedex_geo_zone_id');
		}

		$this->load->model('localisation/geo_zone');

		$data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();

		if (isset($this->request->post['shipping_fedex_status'])) {
			$data['shipping_fedex_status'] = $this->request->post['shipping_fedex_status'];
		} else {
			$data['shipping_fedex_status'] = $this->config->get('shipping_fedex_status');
		}

		if (isset($this->request->post['shipping_fedex_sort_order'])) {
			$data['shipping_fedex_sort_order'] = $this->request->post['shipping_fedex_sort_order'];
		} else {
			$data['shipping_fedex_sort_order'] = $this->config->get('shipping_fedex_sort_order');
		}

		$data['header'] = $this->load->controller('common/header');
		$data['column_left'] = $this->load->controller('common/column_left');
		$data['footer'] = $this->load->controller('common/footer');

		$this->response->setOutput($this->load->view('extension/shipping/fedex', $data));
	}

	protected function validate() {
		if (!$this->user->hasPermission('modify', 'extension/shipping/fedex')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}

		if (!$this->request->post['shipping_fedex_key']) {
			$this->error['key'] = $this->language->get('error_key');
		}

		if (!$this->request->post['shipping_fedex_password']) {
			$this->error['password'] = $this->language->get('error_password');
		}

		if (!$this->request->post['shipping_fedex_account']) {
			$this->error['account'] = $this->language->get('error_account');
		}

		if (!$this->request->post['shipping_fedex_meter']) {
			$this->error['meter'] = $this->language->get('error_meter');
		}

		if (!$this->request->post['shipping_fedex_postcode']) {
			$this->error['postcode'] = $this->language->get('error_postcode');
		}

		if (!$this->request->post['shipping_fedex_length'] || !$this->request->post['shipping_fedex_width'] || !$this->request->post['shipping_fedex_height']) {
			$this->error['dimension'] = $this->language->get('error_dimension');
		}

		return !$this->error;
	}
}