/admin/controller/shipping/auspost.php

https://gitlab.com/reclamare/mao · PHP · 161 lines · 122 code · 39 blank · 0 comment · 27 complexity · df0e4de16c13b626dee963ab64c1d1f4 MD5 · raw file

  1. <?php
  2. class ControllerShippingAusPost extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->load->language('shipping/auspost');
  6. $this->document->setTitle($this->language->get('heading_title'));
  7. $this->load->model('setting/setting');
  8. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
  9. $this->model_setting_setting->editSetting('auspost', $this->request->post);
  10. $this->session->data['success'] = $this->language->get('text_success');
  11. $this->response->redirect($this->url->link('extension/shipping', 'token=' . $this->session->data['token'], 'SSL'));
  12. }
  13. $data['heading_title'] = $this->language->get('heading_title');
  14. $data['text_edit'] = $this->language->get('text_edit');
  15. $data['text_enabled'] = $this->language->get('text_enabled');
  16. $data['text_disabled'] = $this->language->get('text_disabled');
  17. $data['text_all_zones'] = $this->language->get('text_all_zones');
  18. $data['text_none'] = $this->language->get('text_none');
  19. $data['entry_postcode'] = $this->language->get('entry_postcode');
  20. $data['entry_standard'] = $this->language->get('entry_standard');
  21. $data['entry_express'] = $this->language->get('entry_express');
  22. $data['entry_display_time'] = $this->language->get('entry_display_time');
  23. $data['entry_weight_class'] = $this->language->get('entry_weight_class');
  24. $data['entry_tax_class'] = $this->language->get('entry_tax_class');
  25. $data['entry_geo_zone'] = $this->language->get('entry_geo_zone');
  26. $data['entry_status'] = $this->language->get('entry_status');
  27. $data['entry_sort_order'] = $this->language->get('entry_sort_order');
  28. $data['help_display_time'] = $this->language->get('help_display_time');
  29. $data['help_weight_class'] = $this->language->get('help_weight_class');
  30. $data['button_save'] = $this->language->get('button_save');
  31. $data['button_cancel'] = $this->language->get('button_cancel');
  32. if (isset($this->error['warning'])) {
  33. $data['error_warning'] = $this->error['warning'];
  34. } else {
  35. $data['error_warning'] = '';
  36. }
  37. if (isset($this->error['postcode'])) {
  38. $data['error_postcode'] = $this->error['postcode'];
  39. } else {
  40. $data['error_postcode'] = '';
  41. }
  42. $data['breadcrumbs'] = array();
  43. $data['breadcrumbs'][] = array(
  44. 'text' => $this->language->get('text_home'),
  45. 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
  46. );
  47. $data['breadcrumbs'][] = array(
  48. 'text' => $this->language->get('text_shipping'),
  49. 'href' => $this->url->link('extension/shipping', 'token=' . $this->session->data['token'], 'SSL')
  50. );
  51. $data['breadcrumbs'][] = array(
  52. 'text' => $this->language->get('heading_title'),
  53. 'href' => $this->url->link('shipping/auspost', 'token=' . $this->session->data['token'], 'SSL')
  54. );
  55. $data['action'] = $this->url->link('shipping/auspost', 'token=' . $this->session->data['token'], 'SSL');
  56. $data['cancel'] = $this->url->link('extension/shipping', 'token=' . $this->session->data['token'], 'SSL');
  57. if (isset($this->request->post['auspost_postcode'])) {
  58. $data['auspost_postcode'] = $this->request->post['auspost_postcode'];
  59. } else {
  60. $data['auspost_postcode'] = $this->config->get('auspost_postcode');
  61. }
  62. if (isset($this->request->post['auspost_standard'])) {
  63. $data['auspost_standard'] = $this->request->post['auspost_standard'];
  64. } else {
  65. $data['auspost_standard'] = $this->config->get('auspost_standard');
  66. }
  67. if (isset($this->request->post['auspost_express'])) {
  68. $data['auspost_express'] = $this->request->post['auspost_express'];
  69. } else {
  70. $data['auspost_express'] = $this->config->get('auspost_express');
  71. }
  72. if (isset($this->request->post['auspost_display_time'])) {
  73. $data['auspost_display_time'] = $this->request->post['auspost_display_time'];
  74. } else {
  75. $data['auspost_display_time'] = $this->config->get('auspost_display_time');
  76. }
  77. if (isset($this->request->post['auspost_weight_class_id'])) {
  78. $data['auspost_weight_class_id'] = $this->request->post['auspost_weight_class_id'];
  79. } else {
  80. $data['auspost_weight_class_id'] = $this->config->get('auspost_weight_class_id');
  81. }
  82. $this->load->model('localisation/weight_class');
  83. $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses();
  84. if (isset($this->request->post['auspost_tax_class_id'])) {
  85. $data['auspost_tax_class_id'] = $this->request->post['auspost_tax_class_id'];
  86. } else {
  87. $data['auspost_tax_class_id'] = $this->config->get('auspost_tax_class_id');
  88. }
  89. $this->load->model('localisation/tax_class');
  90. $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses();
  91. if (isset($this->request->post['auspost_geo_zone_id'])) {
  92. $data['auspost_geo_zone_id'] = $this->request->post['auspost_geo_zone_id'];
  93. } else {
  94. $data['auspost_geo_zone_id'] = $this->config->get('auspost_geo_zone_id');
  95. }
  96. $this->load->model('localisation/geo_zone');
  97. $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
  98. if (isset($this->request->post['auspost_status'])) {
  99. $data['auspost_status'] = $this->request->post['auspost_status'];
  100. } else {
  101. $data['auspost_status'] = $this->config->get('auspost_status');
  102. }
  103. if (isset($this->request->post['auspost_sort_order'])) {
  104. $data['auspost_sort_order'] = $this->request->post['auspost_sort_order'];
  105. } else {
  106. $data['auspost_sort_order'] = $this->config->get('auspost_sort_order');
  107. }
  108. $data['header'] = $this->load->controller('common/header');
  109. $data['column_left'] = $this->load->controller('common/column_left');
  110. $data['footer'] = $this->load->controller('common/footer');
  111. $this->response->setOutput($this->load->view('shipping/auspost.tpl', $data));
  112. }
  113. protected function validate() {
  114. if (!$this->user->hasPermission('modify', 'shipping/auspost')) {
  115. $this->error['warning'] = $this->language->get('error_permission');
  116. }
  117. if (!preg_match('/^[0-9]{4}$/', $this->request->post['auspost_postcode'])) {
  118. $this->error['postcode'] = $this->language->get('error_postcode');
  119. }
  120. return !$this->error;
  121. }
  122. }