shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

auspost.php (5234B)


      1 <?php
      2 class ControllerExtensionShippingAusPost extends Controller {
      3 	private $error = array();
      4 
      5 	public function index() {
      6 		$this->load->language('extension/shipping/auspost');
      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_auspost', $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['api'])) {
     27 			$data['error_api'] = $this->error['api'];
     28 		} else {
     29 			$data['error_api'] = '';
     30 		}
     31 
     32 		if (isset($this->error['postcode'])) {
     33 			$data['error_postcode'] = $this->error['postcode'];
     34 		} else {
     35 			$data['error_postcode'] = '';
     36 		}
     37 
     38 		$data['breadcrumbs'] = array();
     39 
     40 		$data['breadcrumbs'][] = array(
     41 			'text' => $this->language->get('text_home'),
     42 			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
     43 		);
     44 
     45 		$data['breadcrumbs'][] = array(
     46 			'text' => $this->language->get('text_extension'),
     47 			'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)
     48 		);
     49 
     50 		$data['breadcrumbs'][] = array(
     51 			'text' => $this->language->get('heading_title'),
     52 			'href' => $this->url->link('extension/shipping/auspost', 'user_token=' . $this->session->data['user_token'], true)
     53 		);
     54 
     55 		$data['action'] = $this->url->link('extension/shipping/auspost', 'user_token=' . $this->session->data['user_token'], true);
     56 
     57 		$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true);
     58 
     59 		if (isset($this->request->post['shipping_auspost_postcode'])) {
     60 			$data['shipping_auspost_postcode'] = $this->request->post['shipping_auspost_postcode'];
     61 		} else {
     62 			$data['shipping_auspost_postcode'] = $this->config->get('shipping_auspost_postcode');
     63 		}
     64 
     65 		if (isset($this->request->post['shipping_auspost_api'])) {
     66 			$data['shipping_auspost_api'] = $this->request->post['shipping_auspost_api'];
     67 		} else {
     68 			$data['shipping_auspost_api'] = $this->config->get('shipping_auspost_api');
     69 		}
     70 
     71 		if (isset($this->request->post['shipping_auspost_weight_class_id'])) {
     72 			$data['shipping_auspost_weight_class_id'] = $this->request->post['shipping_auspost_weight_class_id'];
     73 		} else {
     74 			$data['shipping_auspost_weight_class_id'] = $this->config->get('shipping_auspost_weight_class_id');
     75 		}
     76 
     77 		$this->load->model('localisation/weight_class');
     78 
     79 		$data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses();
     80 
     81 		if (isset($this->request->post['shipping_auspost_tax_class_id'])) {
     82 			$data['shipping_auspost_tax_class_id'] = $this->request->post['shipping_auspost_tax_class_id'];
     83 		} else {
     84 			$data['shipping_auspost_tax_class_id'] = $this->config->get('shipping_auspost_tax_class_id');
     85 		}
     86 
     87 		$this->load->model('localisation/tax_class');
     88 
     89 		$data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses();
     90 
     91 		if (isset($this->request->post['shipping_auspost_geo_zone_id'])) {
     92 			$data['shipping_auspost_geo_zone_id'] = $this->request->post['shipping_auspost_geo_zone_id'];
     93 		} else {
     94 			$data['shipping_auspost_geo_zone_id'] = $this->config->get('shipping_auspost_geo_zone_id');
     95 		}
     96 
     97 		$this->load->model('localisation/geo_zone');
     98 
     99 		$data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
    100 
    101 		if (isset($this->request->post['shipping_auspost_status'])) {
    102 			$data['shipping_auspost_status'] = $this->request->post['shipping_auspost_status'];
    103 		} else {
    104 			$data['shipping_auspost_status'] = $this->config->get('shipping_auspost_status');
    105 		}
    106 
    107 		if (isset($this->request->post['shipping_auspost_sort_order'])) {
    108 			$data['shipping_auspost_sort_order'] = $this->request->post['shipping_auspost_sort_order'];
    109 		} else {
    110 			$data['shipping_auspost_sort_order'] = $this->config->get('shipping_auspost_sort_order');
    111 		}
    112 
    113 		$data['header'] = $this->load->controller('common/header');
    114 		$data['column_left'] = $this->load->controller('common/column_left');
    115 		$data['footer'] = $this->load->controller('common/footer');
    116 
    117 		$this->response->setOutput($this->load->view('extension/shipping/auspost', $data));
    118 	}
    119 
    120 	protected function validate() {
    121 		if (!$this->user->hasPermission('modify', 'extension/shipping/auspost')) {
    122 			$this->error['warning'] = $this->language->get('error_permission');
    123 		}
    124 
    125 		if (empty($this->request->post['shipping_auspost_api'])) {
    126 			$this->error['api'] = $this->language->get('error_api');
    127 		}
    128 
    129 		if (!preg_match('/^[0-9]{4}$/', $this->request->post['shipping_auspost_postcode'])) {
    130 			$this->error['postcode'] = $this->language->get('error_postcode');
    131 		}
    132 
    133 		return !$this->error;
    134 	}
    135 }