shop.balmet.com

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

checkout.php (5933B)


      1 <?php
      2 class ControllerCheckoutCheckout extends Controller {
      3 	public function index() {
      4 		// Validate cart has products and has stock.
      5 		if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
      6 			$this->response->redirect($this->url->link('checkout/cart'));
      7 		}
      8 
      9 		// Validate minimum quantity requirements.
     10 		$products = $this->cart->getProducts();
     11 
     12 		foreach ($products as $product) {
     13 			$product_total = 0;
     14 
     15 			foreach ($products as $product_2) {
     16 				if ($product_2['product_id'] == $product['product_id']) {
     17 					$product_total += $product_2['quantity'];
     18 				}
     19 			}
     20 
     21 			if ($product['minimum'] > $product_total) {
     22 				$this->response->redirect($this->url->link('checkout/cart'));
     23 			}
     24 		}
     25 
     26 		$this->load->language('checkout/checkout');
     27 
     28 		$this->document->setTitle($this->language->get('heading_title'));
     29 
     30 		$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment/moment.min.js');
     31 		$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment/moment-with-locales.min.js');
     32 		$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js');
     33 		$this->document->addStyle('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css');
     34 
     35 		// Required by klarna
     36 		if ($this->config->get('payment_klarna_account') || $this->config->get('payment_klarna_invoice')) {
     37 			$this->document->addScript('http://cdn.klarna.com/public/kitt/toc/v1.0/js/klarna.terms.min.js');
     38 		}
     39 
     40 		$data['breadcrumbs'] = array();
     41 
     42 		$data['breadcrumbs'][] = array(
     43 			'text' => $this->language->get('text_home'),
     44 			'href' => $this->url->link('common/home')
     45 		);
     46 
     47 		$data['breadcrumbs'][] = array(
     48 			'text' => $this->language->get('text_cart'),
     49 			'href' => $this->url->link('checkout/cart')
     50 		);
     51 
     52 		$data['breadcrumbs'][] = array(
     53 			'text' => $this->language->get('heading_title'),
     54 			'href' => $this->url->link('checkout/checkout', '', true)
     55 		);
     56 
     57 		$data['text_checkout_option'] = sprintf($this->language->get('text_checkout_option'), 1);
     58 		$data['text_checkout_account'] = sprintf($this->language->get('text_checkout_account'), 2);
     59 		$data['text_checkout_payment_address'] = sprintf($this->language->get('text_checkout_payment_address'), 2);
     60 		$data['text_checkout_shipping_address'] = sprintf($this->language->get('text_checkout_shipping_address'), 3);
     61 		$data['text_checkout_shipping_method'] = sprintf($this->language->get('text_checkout_shipping_method'), 4);
     62 		
     63 		if ($this->cart->hasShipping()) {
     64 			$data['text_checkout_payment_method'] = sprintf($this->language->get('text_checkout_payment_method'), 5);
     65 			$data['text_checkout_confirm'] = sprintf($this->language->get('text_checkout_confirm'), 6);
     66 		} else {
     67 			$data['text_checkout_payment_method'] = sprintf($this->language->get('text_checkout_payment_method'), 3);
     68 			$data['text_checkout_confirm'] = sprintf($this->language->get('text_checkout_confirm'), 4);	
     69 		}
     70 
     71 		if (isset($this->session->data['error'])) {
     72 			$data['error_warning'] = $this->session->data['error'];
     73 			unset($this->session->data['error']);
     74 		} else {
     75 			$data['error_warning'] = '';
     76 		}
     77 
     78 		$data['logged'] = $this->customer->isLogged();
     79 
     80 		if (isset($this->session->data['account'])) {
     81 			$data['account'] = $this->session->data['account'];
     82 		} else {
     83 			$data['account'] = '';
     84 		}
     85 
     86 		$data['shipping_required'] = $this->cart->hasShipping();
     87 
     88 		$data['column_left'] = $this->load->controller('common/column_left');
     89 		$data['column_right'] = $this->load->controller('common/column_right');
     90 		$data['content_top'] = $this->load->controller('common/content_top');
     91 		$data['content_bottom'] = $this->load->controller('common/content_bottom');
     92 		$data['footer'] = $this->load->controller('common/footer');
     93 		$data['header'] = $this->load->controller('common/header');
     94 
     95 		$this->response->setOutput($this->load->view('checkout/checkout', $data));
     96 	}
     97 
     98 	public function country() {
     99 		$json = array();
    100 
    101 		$this->load->model('localisation/country');
    102 
    103 		$country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']);
    104 
    105 		if ($country_info) {
    106 			$this->load->model('localisation/zone');
    107 
    108 			$json = array(
    109 				'country_id'        => $country_info['country_id'],
    110 				'name'              => $country_info['name'],
    111 				'iso_code_2'        => $country_info['iso_code_2'],
    112 				'iso_code_3'        => $country_info['iso_code_3'],
    113 				'address_format'    => $country_info['address_format'],
    114 				'postcode_required' => $country_info['postcode_required'],
    115 				'zone'              => $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']),
    116 				'status'            => $country_info['status']
    117 			);
    118 		}
    119 
    120 		$this->response->addHeader('Content-Type: application/json');
    121 		$this->response->setOutput(json_encode($json));
    122 	}
    123 
    124 	public function customfield() {
    125 		$json = array();
    126 
    127 		$this->load->model('account/custom_field');
    128 
    129 		// Customer Group
    130 		if (isset($this->request->get['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->get['customer_group_id'], $this->config->get('config_customer_group_display'))) {
    131 			$customer_group_id = $this->request->get['customer_group_id'];
    132 		} else {
    133 			$customer_group_id = $this->config->get('config_customer_group_id');
    134 		}
    135 
    136 		$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
    137 
    138 		foreach ($custom_fields as $custom_field) {
    139 			$json[] = array(
    140 				'custom_field_id' => $custom_field['custom_field_id'],
    141 				'required'        => $custom_field['required']
    142 			);
    143 		}
    144 
    145 		$this->response->addHeader('Content-Type: application/json');
    146 		$this->response->setOutput(json_encode($json));
    147 	}
    148 }