usps.php (19129B)
1 <?php 2 class ControllerExtensionShippingUsps extends Controller { 3 private $error = array(); 4 5 public function index() { 6 $this->load->language('extension/shipping/usps'); 7 8 $this->document->setTitle($this->language->get('heading_title')); 9 10 $this->load->model('setting/setting'); 11 12 if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { 13 $this->model_setting_setting->editSetting('shipping_usps', $this->request->post); 14 15 $this->session->data['success'] = $this->language->get('text_success'); 16 17 $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); 18 } 19 20 if (isset($this->error['warning'])) { 21 $data['error_warning'] = $this->error['warning']; 22 } else { 23 $data['error_warning'] = ''; 24 } 25 26 if (isset($this->error['user_id'])) { 27 $data['error_user_id'] = $this->error['user_id']; 28 } else { 29 $data['error_user_id'] = ''; 30 } 31 32 if (isset($this->error['postcode'])) { 33 $data['error_postcode'] = $this->error['postcode']; 34 } else { 35 $data['error_postcode'] = ''; 36 } 37 38 if (isset($this->error['dimension'])) { 39 $data['error_dimension'] = $this->error['dimension']; 40 } else { 41 $data['error_dimension'] = ''; 42 } 43 44 $data['breadcrumbs'] = array(); 45 46 $data['breadcrumbs'][] = array( 47 'text' => $this->language->get('text_home'), 48 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) 49 ); 50 51 $data['breadcrumbs'][] = array( 52 'text' => $this->language->get('text_extension'), 53 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) 54 ); 55 56 $data['breadcrumbs'][] = array( 57 'text' => $this->language->get('heading_title'), 58 'href' => $this->url->link('extension/shipping/usps', 'user_token=' . $this->session->data['user_token'], true) 59 ); 60 61 $data['action'] = $this->url->link('extension/shipping/usps', 'user_token=' . $this->session->data['user_token'], true); 62 63 $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); 64 65 if (isset($this->request->post['shipping_usps_user_id'])) { 66 $data['shipping_usps_user_id'] = $this->request->post['shipping_usps_user_id']; 67 } else { 68 $data['shipping_usps_user_id'] = $this->config->get('shipping_usps_user_id'); 69 } 70 71 if (isset($this->request->post['shipping_usps_postcode'])) { 72 $data['shipping_usps_postcode'] = $this->request->post['shipping_usps_postcode']; 73 } else { 74 $data['shipping_usps_postcode'] = $this->config->get('shipping_usps_postcode'); 75 } 76 77 if (isset($this->request->post['shipping_usps_domestic_00'])) { 78 $data['shipping_usps_domestic_00'] = $this->request->post['shipping_usps_domestic_00']; 79 } else { 80 $data['shipping_usps_domestic_00'] = $this->config->get('shipping_usps_domestic_00'); 81 } 82 83 if (isset($this->request->post['shipping_usps_domestic_01'])) { 84 $data['shipping_usps_domestic_01'] = $this->request->post['shipping_usps_domestic_01']; 85 } else { 86 $data['shipping_usps_domestic_01'] = $this->config->get('shipping_usps_domestic_01'); 87 } 88 89 if (isset($this->request->post['shipping_usps_domestic_02'])) { 90 $data['shipping_usps_domestic_02'] = $this->request->post['shipping_usps_domestic_02']; 91 } else { 92 $data['shipping_usps_domestic_02'] = $this->config->get('shipping_usps_domestic_02'); 93 } 94 95 if (isset($this->request->post['shipping_usps_domestic_03'])) { 96 $data['shipping_usps_domestic_03'] = $this->request->post['shipping_usps_domestic_03']; 97 } else { 98 $data['shipping_usps_domestic_03'] = $this->config->get('shipping_usps_domestic_03'); 99 } 100 101 if (isset($this->request->post['shipping_usps_domestic_1'])) { 102 $data['shipping_usps_domestic_1'] = $this->request->post['shipping_usps_domestic_1']; 103 } else { 104 $data['shipping_usps_domestic_1'] = $this->config->get('shipping_usps_domestic_1'); 105 } 106 107 if (isset($this->request->post['shipping_usps_domestic_2'])) { 108 $data['shipping_usps_domestic_2'] = $this->request->post['shipping_usps_domestic_2']; 109 } else { 110 $data['shipping_usps_domestic_2'] = $this->config->get('shipping_usps_domestic_2'); 111 } 112 113 if (isset($this->request->post['shipping_usps_domestic_3'])) { 114 $data['shipping_usps_domestic_3'] = $this->request->post['shipping_usps_domestic_3']; 115 } else { 116 $data['shipping_usps_domestic_3'] = $this->config->get('shipping_usps_domestic_3'); 117 } 118 119 if (isset($this->request->post['shipping_usps_domestic_4'])) { 120 $data['shipping_usps_domestic_4'] = $this->request->post['shipping_usps_domestic_4']; 121 } else { 122 $data['shipping_usps_domestic_4'] = $this->config->get('shipping_usps_domestic_4'); 123 } 124 125 if (isset($this->request->post['shipping_usps_domestic_5'])) { 126 $data['shipping_usps_domestic_5'] = $this->request->post['shipping_usps_domestic_5']; 127 } else { 128 $data['shipping_usps_domestic_5'] = $this->config->get('shipping_usps_domestic_5'); 129 } 130 131 if (isset($this->request->post['shipping_usps_domestic_6'])) { 132 $data['shipping_usps_domestic_6'] = $this->request->post['shipping_usps_domestic_6']; 133 } else { 134 $data['shipping_usps_domestic_6'] = $this->config->get('shipping_usps_domestic_6'); 135 } 136 137 if (isset($this->request->post['shipping_usps_domestic_7'])) { 138 $data['shipping_usps_domestic_7'] = $this->request->post['shipping_usps_domestic_7']; 139 } else { 140 $data['shipping_usps_domestic_7'] = $this->config->get('shipping_usps_domestic_7'); 141 } 142 143 if (isset($this->request->post['shipping_usps_domestic_12'])) { 144 $data['shipping_usps_domestic_12'] = $this->request->post['shipping_usps_domestic_12']; 145 } else { 146 $data['shipping_usps_domestic_12'] = $this->config->get('shipping_usps_domestic_12'); 147 } 148 149 if (isset($this->request->post['shipping_usps_domestic_13'])) { 150 $data['shipping_usps_domestic_13'] = $this->request->post['shipping_usps_domestic_13']; 151 } else { 152 $data['shipping_usps_domestic_13'] = $this->config->get('shipping_usps_domestic_13'); 153 } 154 155 if (isset($this->request->post['shipping_usps_domestic_16'])) { 156 $data['shipping_usps_domestic_16'] = $this->request->post['shipping_usps_domestic_16']; 157 } else { 158 $data['shipping_usps_domestic_16'] = $this->config->get('shipping_usps_domestic_16'); 159 } 160 161 if (isset($this->request->post['shipping_usps_domestic_17'])) { 162 $data['shipping_usps_domestic_17'] = $this->request->post['shipping_usps_domestic_17']; 163 } else { 164 $data['shipping_usps_domestic_17'] = $this->config->get('shipping_usps_domestic_17'); 165 } 166 167 if (isset($this->request->post['shipping_usps_domestic_18'])) { 168 $data['shipping_usps_domestic_18'] = $this->request->post['shipping_usps_domestic_18']; 169 } else { 170 $data['shipping_usps_domestic_18'] = $this->config->get('shipping_usps_domestic_18'); 171 } 172 173 if (isset($this->request->post['shipping_usps_domestic_19'])) { 174 $data['shipping_usps_domestic_19'] = $this->request->post['shipping_usps_domestic_19']; 175 } else { 176 $data['shipping_usps_domestic_19'] = $this->config->get('shipping_usps_domestic_19'); 177 } 178 179 if (isset($this->request->post['shipping_usps_domestic_22'])) { 180 $data['shipping_usps_domestic_22'] = $this->request->post['shipping_usps_domestic_22']; 181 } else { 182 $data['shipping_usps_domestic_22'] = $this->config->get('shipping_usps_domestic_22'); 183 } 184 185 if (isset($this->request->post['shipping_usps_domestic_23'])) { 186 $data['shipping_usps_domestic_23'] = $this->request->post['shipping_usps_domestic_23']; 187 } else { 188 $data['shipping_usps_domestic_23'] = $this->config->get('shipping_usps_domestic_23'); 189 } 190 191 if (isset($this->request->post['shipping_usps_domestic_25'])) { 192 $data['shipping_usps_domestic_25'] = $this->request->post['shipping_usps_domestic_25']; 193 } else { 194 $data['shipping_usps_domestic_25'] = $this->config->get('shipping_usps_domestic_25'); 195 } 196 197 if (isset($this->request->post['shipping_usps_domestic_27'])) { 198 $data['shipping_usps_domestic_27'] = $this->request->post['shipping_usps_domestic_27']; 199 } else { 200 $data['shipping_usps_domestic_27'] = $this->config->get('shipping_usps_domestic_27'); 201 } 202 203 if (isset($this->request->post['shipping_usps_domestic_28'])) { 204 $data['shipping_usps_domestic_28'] = $this->request->post['shipping_usps_domestic_28']; 205 } else { 206 $data['shipping_usps_domestic_28'] = $this->config->get('shipping_usps_domestic_28'); 207 } 208 209 if (isset($this->request->post['shipping_usps_international_1'])) { 210 $data['shipping_usps_international_1'] = $this->request->post['shipping_usps_international_1']; 211 } else { 212 $data['shipping_usps_international_1'] = $this->config->get('shipping_usps_international_1'); 213 } 214 215 if (isset($this->request->post['shipping_usps_international_2'])) { 216 $data['shipping_usps_international_2'] = $this->request->post['shipping_usps_international_2']; 217 } else { 218 $data['shipping_usps_international_2'] = $this->config->get('shipping_usps_international_2'); 219 } 220 221 if (isset($this->request->post['shipping_usps_international_4'])) { 222 $data['shipping_usps_international_4'] = $this->request->post['shipping_usps_international_4']; 223 } else { 224 $data['shipping_usps_international_4'] = $this->config->get('shipping_usps_international_4'); 225 } 226 227 if (isset($this->request->post['shipping_usps_international_5'])) { 228 $data['shipping_usps_international_5'] = $this->request->post['shipping_usps_international_5']; 229 } else { 230 $data['shipping_usps_international_5'] = $this->config->get('shipping_usps_international_5'); 231 } 232 233 if (isset($this->request->post['shipping_usps_international_6'])) { 234 $data['shipping_usps_international_6'] = $this->request->post['shipping_usps_international_6']; 235 } else { 236 $data['shipping_usps_international_6'] = $this->config->get('shipping_usps_international_6'); 237 } 238 239 if (isset($this->request->post['shipping_usps_international_7'])) { 240 $data['shipping_usps_international_7'] = $this->request->post['shipping_usps_international_7']; 241 } else { 242 $data['shipping_usps_international_7'] = $this->config->get('shipping_usps_international_7'); 243 } 244 245 if (isset($this->request->post['shipping_usps_international_8'])) { 246 $data['shipping_usps_international_8'] = $this->request->post['shipping_usps_international_8']; 247 } else { 248 $data['shipping_usps_international_8'] = $this->config->get('shipping_usps_international_8'); 249 } 250 251 if (isset($this->request->post['shipping_usps_international_9'])) { 252 $data['shipping_usps_international_9'] = $this->request->post['shipping_usps_international_9']; 253 } else { 254 $data['shipping_usps_international_9'] = $this->config->get('shipping_usps_international_9'); 255 } 256 257 if (isset($this->request->post['shipping_usps_international_10'])) { 258 $data['shipping_usps_international_10'] = $this->request->post['shipping_usps_international_10']; 259 } else { 260 $data['shipping_usps_international_10'] = $this->config->get('shipping_usps_international_10'); 261 } 262 263 if (isset($this->request->post['shipping_usps_international_11'])) { 264 $data['shipping_usps_international_11'] = $this->request->post['shipping_usps_international_11']; 265 } else { 266 $data['shipping_usps_international_11'] = $this->config->get('shipping_usps_international_11'); 267 } 268 269 if (isset($this->request->post['shipping_usps_international_12'])) { 270 $data['shipping_usps_international_12'] = $this->request->post['shipping_usps_international_12']; 271 } else { 272 $data['shipping_usps_international_12'] = $this->config->get('shipping_usps_international_12'); 273 } 274 275 if (isset($this->request->post['shipping_usps_international_13'])) { 276 $data['shipping_usps_international_13'] = $this->request->post['shipping_usps_international_13']; 277 } else { 278 $data['shipping_usps_international_13'] = $this->config->get('shipping_usps_international_13'); 279 } 280 281 if (isset($this->request->post['shipping_usps_international_14'])) { 282 $data['shipping_usps_international_14'] = $this->request->post['shipping_usps_international_14']; 283 } else { 284 $data['shipping_usps_international_14'] = $this->config->get('shipping_usps_international_14'); 285 } 286 287 if (isset($this->request->post['shipping_usps_international_15'])) { 288 $data['shipping_usps_international_15'] = $this->request->post['shipping_usps_international_15']; 289 } else { 290 $data['shipping_usps_international_15'] = $this->config->get('shipping_usps_international_15'); 291 } 292 293 if (isset($this->request->post['shipping_usps_international_16'])) { 294 $data['shipping_usps_international_16'] = $this->request->post['shipping_usps_international_16']; 295 } else { 296 $data['shipping_usps_international_16'] = $this->config->get('shipping_usps_international_16'); 297 } 298 299 if (isset($this->request->post['shipping_usps_international_21'])) { 300 $data['shipping_usps_international_21'] = $this->request->post['shipping_usps_international_21']; 301 } else { 302 $data['shipping_usps_international_21'] = $this->config->get('shipping_usps_international_21'); 303 } 304 305 if (isset($this->request->post['shipping_usps_size'])) { 306 $data['shipping_usps_size'] = $this->request->post['shipping_usps_size']; 307 } else { 308 $data['shipping_usps_size'] = $this->config->get('shipping_usps_size'); 309 } 310 311 $data['sizes'] = array(); 312 313 $data['sizes'][] = array( 314 'text' => $this->language->get('text_regular'), 315 'value' => 'REGULAR' 316 ); 317 318 $data['sizes'][] = array( 319 'text' => $this->language->get('text_large'), 320 'value' => 'LARGE' 321 ); 322 323 if (isset($this->request->post['shipping_usps_container'])) { 324 $data['shipping_usps_container'] = $this->request->post['shipping_usps_container']; 325 } else { 326 $data['shipping_usps_container'] = $this->config->get('shipping_usps_container'); 327 } 328 329 $data['containers'] = array(); 330 331 $data['containers'][] = array( 332 'text' => $this->language->get('text_rectangular'), 333 'value' => 'RECTANGULAR' 334 ); 335 336 $data['containers'][] = array( 337 'text' => $this->language->get('text_non_rectangular'), 338 'value' => 'NONRECTANGULAR' 339 ); 340 341 $data['containers'][] = array( 342 'text' => $this->language->get('text_variable'), 343 'value' => 'VARIABLE' 344 ); 345 346 if (isset($this->request->post['shipping_usps_machinable'])) { 347 $data['shipping_usps_machinable'] = $this->request->post['shipping_usps_machinable']; 348 } else { 349 $data['shipping_usps_machinable'] = $this->config->get('shipping_usps_machinable'); 350 } 351 352 if (isset($this->request->post['shipping_usps_length'])) { 353 $data['shipping_usps_length'] = $this->request->post['shipping_usps_length']; 354 } else { 355 $data['shipping_usps_length'] = $this->config->get('shipping_usps_length'); 356 } 357 358 if (isset($this->request->post['shipping_usps_width'])) { 359 $data['shipping_usps_width'] = $this->request->post['shipping_usps_width']; 360 } else { 361 $data['shipping_usps_width'] = $this->config->get('shipping_usps_width'); 362 } 363 364 if (isset($this->request->post['shipping_usps_height'])) { 365 $data['shipping_usps_height'] = $this->request->post['shipping_usps_height']; 366 } else { 367 $data['shipping_usps_height'] = $this->config->get('shipping_usps_height'); 368 } 369 370 if (isset($this->request->post['shipping_usps_display_time'])) { 371 $data['shipping_usps_display_time'] = $this->request->post['shipping_usps_display_time']; 372 } else { 373 $data['shipping_usps_display_time'] = $this->config->get('shipping_usps_display_time'); 374 } 375 376 if (isset($this->request->post['shipping_usps_display_weight'])) { 377 $data['shipping_usps_display_weight'] = $this->request->post['shipping_usps_display_weight']; 378 } else { 379 $data['shipping_usps_display_weight'] = $this->config->get('shipping_usps_display_weight'); 380 } 381 382 if (isset($this->request->post['shipping_usps_weight_class_id'])) { 383 $data['shipping_usps_weight_class_id'] = $this->request->post['shipping_usps_weight_class_id']; 384 } else { 385 $data['shipping_usps_weight_class_id'] = $this->config->get('shipping_usps_weight_class_id'); 386 } 387 388 $this->load->model('localisation/weight_class'); 389 390 $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); 391 392 if (isset($this->request->post['shipping_usps_tax_class_id'])) { 393 $data['shipping_usps_tax_class_id'] = $this->request->post['shipping_usps_tax_class_id']; 394 } else { 395 $data['shipping_usps_tax_class_id'] = $this->config->get('shipping_usps_tax_class_id'); 396 } 397 398 $this->load->model('localisation/tax_class'); 399 400 $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); 401 402 if (isset($this->request->post['shipping_usps_geo_zone_id'])) { 403 $data['shipping_usps_geo_zone_id'] = $this->request->post['shipping_usps_geo_zone_id']; 404 } else { 405 $data['shipping_usps_geo_zone_id'] = $this->config->get('shipping_usps_geo_zone_id'); 406 } 407 408 $this->load->model('localisation/geo_zone'); 409 410 $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); 411 412 if (isset($this->request->post['shipping_usps_debug'])) { 413 $data['shipping_usps_debug'] = $this->request->post['shipping_usps_debug']; 414 } else { 415 $data['shipping_usps_debug'] = $this->config->get('shipping_usps_debug'); 416 } 417 418 if (isset($this->request->post['shipping_usps_status'])) { 419 $data['shipping_usps_status'] = $this->request->post['shipping_usps_status']; 420 } else { 421 $data['shipping_usps_status'] = $this->config->get('shipping_usps_status'); 422 } 423 424 if (isset($this->request->post['shipping_usps_sort_order'])) { 425 $data['shipping_usps_sort_order'] = $this->request->post['shipping_usps_sort_order']; 426 } else { 427 $data['shipping_usps_sort_order'] = $this->config->get('shipping_usps_sort_order'); 428 } 429 430 $data['header'] = $this->load->controller('common/header'); 431 $data['column_left'] = $this->load->controller('common/column_left'); 432 $data['footer'] = $this->load->controller('common/footer'); 433 434 $this->response->setOutput($this->load->view('extension/shipping/usps', $data)); 435 } 436 437 protected function validate() { 438 if (!$this->user->hasPermission('modify', 'extension/shipping/usps')) { 439 $this->error['warning'] = $this->language->get('error_permission'); 440 } 441 442 if (!$this->request->post['shipping_usps_user_id']) { 443 $this->error['user_id'] = $this->language->get('error_user_id'); 444 } 445 446 if (!$this->request->post['shipping_usps_postcode']) { 447 $this->error['postcode'] = $this->language->get('error_postcode'); 448 } 449 450 if (!$this->request->post['shipping_usps_width']) { 451 $this->error['dimension'] = $this->language->get('error_width'); 452 } 453 454 if (!$this->request->post['shipping_usps_height']) { 455 $this->error['dimension'] = $this->language->get('error_height'); 456 } 457 458 if (!$this->request->post['shipping_usps_length']) { 459 $this->error['dimension'] = $this->language->get('error_length'); 460 } 461 462 return !$this->error; 463 } 464 }