shop.balmet.com

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

confirm.php (17465B)


      1 <?php
      2 class ControllerCheckoutConfirm extends Controller {
      3 	public function index() {
      4 		$redirect = '';
      5 
      6 		if ($this->cart->hasShipping()) {
      7 			// Validate if shipping address has been set.
      8 			if (!isset($this->session->data['shipping_address'])) {
      9 				$redirect = $this->url->link('checkout/checkout', '', true);
     10 			}
     11 
     12 			// Validate if shipping method has been set.
     13 			if (!isset($this->session->data['shipping_method'])) {
     14 				$redirect = $this->url->link('checkout/checkout', '', true);
     15 			}
     16 		} else {
     17 			unset($this->session->data['shipping_address']);
     18 			unset($this->session->data['shipping_method']);
     19 			unset($this->session->data['shipping_methods']);
     20 		}
     21 
     22 		// Validate if payment address has been set.
     23 		if (!isset($this->session->data['payment_address'])) {
     24 			$redirect = $this->url->link('checkout/checkout', '', true);
     25 		}
     26 
     27 		// Validate if payment method has been set.
     28 		if (!isset($this->session->data['payment_method'])) {
     29 			$redirect = $this->url->link('checkout/checkout', '', true);
     30 		}
     31 
     32 		// Validate cart has products and has stock.
     33 		if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
     34 			$redirect = $this->url->link('checkout/cart');
     35 		}
     36 
     37 		// Validate minimum quantity requirements.
     38 		$products = $this->cart->getProducts();
     39 
     40 		foreach ($products as $product) {
     41 			$product_total = 0;
     42 
     43 			foreach ($products as $product_2) {
     44 				if ($product_2['product_id'] == $product['product_id']) {
     45 					$product_total += $product_2['quantity'];
     46 				}
     47 			}
     48 
     49 			if ($product['minimum'] > $product_total) {
     50 				$redirect = $this->url->link('checkout/cart');
     51 
     52 				break;
     53 			}
     54 		}
     55 
     56 		if (!$redirect) {
     57 			$order_data = array();
     58 
     59 			$totals = array();
     60 			$taxes = $this->cart->getTaxes();
     61 			$total = 0;
     62 
     63 			// Because __call can not keep var references so we put them into an array.
     64 			$total_data = array(
     65 				'totals' => &$totals,
     66 				'taxes'  => &$taxes,
     67 				'total'  => &$total
     68 			);
     69 
     70 			$this->load->model('setting/extension');
     71 
     72 			$sort_order = array();
     73 
     74 			$results = $this->model_setting_extension->getExtensions('total');
     75 
     76 			foreach ($results as $key => $value) {
     77 				$sort_order[$key] = $this->config->get('total_' . $value['code'] . '_sort_order');
     78 			}
     79 
     80 			array_multisort($sort_order, SORT_ASC, $results);
     81 
     82 			foreach ($results as $result) {
     83 				if ($this->config->get('total_' . $result['code'] . '_status')) {
     84 					$this->load->model('extension/total/' . $result['code']);
     85 
     86 					// We have to put the totals in an array so that they pass by reference.
     87 					$this->{'model_extension_total_' . $result['code']}->getTotal($total_data);
     88 				}
     89 			}
     90 
     91 			$sort_order = array();
     92 
     93 			foreach ($totals as $key => $value) {
     94 				$sort_order[$key] = $value['sort_order'];
     95 			}
     96 
     97 			array_multisort($sort_order, SORT_ASC, $totals);
     98 
     99 			$order_data['totals'] = $totals;
    100 
    101 			$this->load->language('checkout/checkout');
    102 
    103 			$order_data['invoice_prefix'] = $this->config->get('config_invoice_prefix');
    104 			$order_data['store_id'] = $this->config->get('config_store_id');
    105 			$order_data['store_name'] = $this->config->get('config_name');
    106 
    107 			if ($order_data['store_id']) {
    108 				$order_data['store_url'] = $this->config->get('config_url');
    109 			} else {
    110 				if ($this->request->server['HTTPS']) {
    111 					$order_data['store_url'] = HTTPS_SERVER;
    112 				} else {
    113 					$order_data['store_url'] = HTTP_SERVER;
    114 				}
    115 			}
    116 			
    117 			$this->load->model('account/customer');
    118 
    119 			if ($this->customer->isLogged()) {
    120 				$customer_info = $this->model_account_customer->getCustomer($this->customer->getId());
    121 
    122 				$order_data['customer_id'] = $this->customer->getId();
    123 				$order_data['customer_group_id'] = $customer_info['customer_group_id'];
    124 				$order_data['firstname'] = $customer_info['firstname'];
    125 				$order_data['lastname'] = $customer_info['lastname'];
    126 				$order_data['email'] = $customer_info['email'];
    127 				$order_data['telephone'] = $customer_info['telephone'];
    128 				$order_data['custom_field'] = json_decode($customer_info['custom_field'], true);
    129 			} elseif (isset($this->session->data['guest'])) {
    130 				$order_data['customer_id'] = 0;
    131 				$order_data['customer_group_id'] = $this->session->data['guest']['customer_group_id'];
    132 				$order_data['firstname'] = $this->session->data['guest']['firstname'];
    133 				$order_data['lastname'] = $this->session->data['guest']['lastname'];
    134 				$order_data['email'] = $this->session->data['guest']['email'];
    135 				$order_data['telephone'] = $this->session->data['guest']['telephone'];
    136 				$order_data['custom_field'] = $this->session->data['guest']['custom_field'];
    137 			}
    138 
    139 			$order_data['payment_firstname'] = $this->session->data['payment_address']['firstname'];
    140 			$order_data['payment_lastname'] = $this->session->data['payment_address']['lastname'];
    141 			$order_data['payment_company'] = $this->session->data['payment_address']['company'];
    142 			$order_data['payment_address_1'] = $this->session->data['payment_address']['address_1'];
    143 			$order_data['payment_address_2'] = $this->session->data['payment_address']['address_2'];
    144 			$order_data['payment_city'] = $this->session->data['payment_address']['city'];
    145 			$order_data['payment_postcode'] = $this->session->data['payment_address']['postcode'];
    146 			$order_data['payment_zone'] = $this->session->data['payment_address']['zone'];
    147 			$order_data['payment_zone_id'] = $this->session->data['payment_address']['zone_id'];
    148 			$order_data['payment_country'] = $this->session->data['payment_address']['country'];
    149 			$order_data['payment_country_id'] = $this->session->data['payment_address']['country_id'];
    150 			$order_data['payment_address_format'] = $this->session->data['payment_address']['address_format'];
    151 			$order_data['payment_custom_field'] = (isset($this->session->data['payment_address']['custom_field']) ? $this->session->data['payment_address']['custom_field'] : array());
    152 
    153 			if (isset($this->session->data['payment_method']['title'])) {
    154 				$order_data['payment_method'] = $this->session->data['payment_method']['title'];
    155 			} else {
    156 				$order_data['payment_method'] = '';
    157 			}
    158 
    159 			if (isset($this->session->data['payment_method']['code'])) {
    160 				$order_data['payment_code'] = $this->session->data['payment_method']['code'];
    161 			} else {
    162 				$order_data['payment_code'] = '';
    163 			}
    164 
    165 			if ($this->cart->hasShipping()) {
    166 				$order_data['shipping_firstname'] = $this->session->data['shipping_address']['firstname'];
    167 				$order_data['shipping_lastname'] = $this->session->data['shipping_address']['lastname'];
    168 				$order_data['shipping_company'] = $this->session->data['shipping_address']['company'];
    169 				$order_data['shipping_address_1'] = $this->session->data['shipping_address']['address_1'];
    170 				$order_data['shipping_address_2'] = $this->session->data['shipping_address']['address_2'];
    171 				$order_data['shipping_city'] = $this->session->data['shipping_address']['city'];
    172 				$order_data['shipping_postcode'] = $this->session->data['shipping_address']['postcode'];
    173 				$order_data['shipping_zone'] = $this->session->data['shipping_address']['zone'];
    174 				$order_data['shipping_zone_id'] = $this->session->data['shipping_address']['zone_id'];
    175 				$order_data['shipping_country'] = $this->session->data['shipping_address']['country'];
    176 				$order_data['shipping_country_id'] = $this->session->data['shipping_address']['country_id'];
    177 				$order_data['shipping_address_format'] = $this->session->data['shipping_address']['address_format'];
    178 				$order_data['shipping_custom_field'] = (isset($this->session->data['shipping_address']['custom_field']) ? $this->session->data['shipping_address']['custom_field'] : array());
    179 
    180 				if (isset($this->session->data['shipping_method']['title'])) {
    181 					$order_data['shipping_method'] = $this->session->data['shipping_method']['title'];
    182 				} else {
    183 					$order_data['shipping_method'] = '';
    184 				}
    185 
    186 				if (isset($this->session->data['shipping_method']['code'])) {
    187 					$order_data['shipping_code'] = $this->session->data['shipping_method']['code'];
    188 				} else {
    189 					$order_data['shipping_code'] = '';
    190 				}
    191 			} else {
    192 				$order_data['shipping_firstname'] = '';
    193 				$order_data['shipping_lastname'] = '';
    194 				$order_data['shipping_company'] = '';
    195 				$order_data['shipping_address_1'] = '';
    196 				$order_data['shipping_address_2'] = '';
    197 				$order_data['shipping_city'] = '';
    198 				$order_data['shipping_postcode'] = '';
    199 				$order_data['shipping_zone'] = '';
    200 				$order_data['shipping_zone_id'] = '';
    201 				$order_data['shipping_country'] = '';
    202 				$order_data['shipping_country_id'] = '';
    203 				$order_data['shipping_address_format'] = '';
    204 				$order_data['shipping_custom_field'] = array();
    205 				$order_data['shipping_method'] = '';
    206 				$order_data['shipping_code'] = '';
    207 			}
    208 
    209 			$order_data['products'] = array();
    210 
    211 			foreach ($this->cart->getProducts() as $product) {
    212 				$option_data = array();
    213 
    214 				foreach ($product['option'] as $option) {
    215 					$option_data[] = array(
    216 						'product_option_id'       => $option['product_option_id'],
    217 						'product_option_value_id' => $option['product_option_value_id'],
    218 						'option_id'               => $option['option_id'],
    219 						'option_value_id'         => $option['option_value_id'],
    220 						'name'                    => $option['name'],
    221 						'value'                   => $option['value'],
    222 						'type'                    => $option['type']
    223 					);
    224 				}
    225 
    226 				$order_data['products'][] = array(
    227 					'product_id' => $product['product_id'],
    228 					'name'       => $product['name'],
    229 					'model'      => $product['model'],
    230 					'option'     => $option_data,
    231 					'download'   => $product['download'],
    232 					'quantity'   => $product['quantity'],
    233 					'subtract'   => $product['subtract'],
    234 					'price'      => $product['price'],
    235 					'total'      => $product['total'],
    236 					'tax'        => $this->tax->getTax($product['price'], $product['tax_class_id']),
    237 					'reward'     => $product['reward']
    238 				);
    239 			}
    240 
    241 			// Gift Voucher
    242 			$order_data['vouchers'] = array();
    243 
    244 			if (!empty($this->session->data['vouchers'])) {
    245 				foreach ($this->session->data['vouchers'] as $voucher) {
    246 					$order_data['vouchers'][] = array(
    247 						'description'      => $voucher['description'],
    248 						'code'             => token(10),
    249 						'to_name'          => $voucher['to_name'],
    250 						'to_email'         => $voucher['to_email'],
    251 						'from_name'        => $voucher['from_name'],
    252 						'from_email'       => $voucher['from_email'],
    253 						'voucher_theme_id' => $voucher['voucher_theme_id'],
    254 						'message'          => $voucher['message'],
    255 						'amount'           => $voucher['amount']
    256 					);
    257 				}
    258 			}
    259 
    260 			$order_data['comment'] = $this->session->data['comment'];
    261 			$order_data['total'] = $total_data['total'];
    262 
    263 			if (isset($this->request->cookie['tracking'])) {
    264 				$order_data['tracking'] = $this->request->cookie['tracking'];
    265 
    266 				$subtotal = $this->cart->getSubTotal();
    267 
    268 				// Affiliate
    269 				$affiliate_info = $this->model_account_customer->getAffiliateByTracking($this->request->cookie['tracking']);
    270 
    271 				if ($affiliate_info) {
    272 					$order_data['affiliate_id'] = $affiliate_info['customer_id'];
    273 					$order_data['commission'] = ($subtotal / 100) * $affiliate_info['commission'];
    274 				} else {
    275 					$order_data['affiliate_id'] = 0;
    276 					$order_data['commission'] = 0;
    277 				}
    278 
    279 				// Marketing
    280 				$this->load->model('checkout/marketing');
    281 
    282 				$marketing_info = $this->model_checkout_marketing->getMarketingByCode($this->request->cookie['tracking']);
    283 
    284 				if ($marketing_info) {
    285 					$order_data['marketing_id'] = $marketing_info['marketing_id'];
    286 				} else {
    287 					$order_data['marketing_id'] = 0;
    288 				}
    289 			} else {
    290 				$order_data['affiliate_id'] = 0;
    291 				$order_data['commission'] = 0;
    292 				$order_data['marketing_id'] = 0;
    293 				$order_data['tracking'] = '';
    294 			}
    295 
    296 			$order_data['language_id'] = $this->config->get('config_language_id');
    297 			$order_data['currency_id'] = $this->currency->getId($this->session->data['currency']);
    298 			$order_data['currency_code'] = $this->session->data['currency'];
    299 			$order_data['currency_value'] = $this->currency->getValue($this->session->data['currency']);
    300 			$order_data['ip'] = $this->request->server['REMOTE_ADDR'];
    301 
    302 			if (!empty($this->request->server['HTTP_X_FORWARDED_FOR'])) {
    303 				$order_data['forwarded_ip'] = $this->request->server['HTTP_X_FORWARDED_FOR'];
    304 			} elseif (!empty($this->request->server['HTTP_CLIENT_IP'])) {
    305 				$order_data['forwarded_ip'] = $this->request->server['HTTP_CLIENT_IP'];
    306 			} else {
    307 				$order_data['forwarded_ip'] = '';
    308 			}
    309 
    310 			if (isset($this->request->server['HTTP_USER_AGENT'])) {
    311 				$order_data['user_agent'] = $this->request->server['HTTP_USER_AGENT'];
    312 			} else {
    313 				$order_data['user_agent'] = '';
    314 			}
    315 
    316 			if (isset($this->request->server['HTTP_ACCEPT_LANGUAGE'])) {
    317 				$order_data['accept_language'] = $this->request->server['HTTP_ACCEPT_LANGUAGE'];
    318 			} else {
    319 				$order_data['accept_language'] = '';
    320 			}
    321 
    322 			$this->load->model('checkout/order');
    323 
    324 			$this->session->data['order_id'] = $this->model_checkout_order->addOrder($order_data);
    325 
    326 			$this->load->model('tool/upload');
    327 
    328 			$data['products'] = array();
    329 
    330 			foreach ($this->cart->getProducts() as $product) {
    331 				$option_data = array();
    332 
    333 				foreach ($product['option'] as $option) {
    334 					if ($option['type'] != 'file') {
    335 						$value = $option['value'];
    336 					} else {
    337 						$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
    338 
    339 						if ($upload_info) {
    340 							$value = $upload_info['name'];
    341 						} else {
    342 							$value = '';
    343 						}
    344 					}
    345 
    346 					$option_data[] = array(
    347 						'name'  => $option['name'],
    348 						'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
    349 					);
    350 				}
    351 
    352 				$recurring = '';
    353 
    354 				if ($product['recurring']) {
    355 					$frequencies = array(
    356 						'day'        => $this->language->get('text_day'),
    357 						'week'       => $this->language->get('text_week'),
    358 						'semi_month' => $this->language->get('text_semi_month'),
    359 						'month'      => $this->language->get('text_month'),
    360 						'year'       => $this->language->get('text_year'),
    361 					);
    362 
    363 					if ($product['recurring']['trial']) {
    364 						$recurring = sprintf($this->language->get('text_trial_description'), $this->currency->format($this->tax->calculate($product['recurring']['trial_price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']), $product['recurring']['trial_cycle'], $frequencies[$product['recurring']['trial_frequency']], $product['recurring']['trial_duration']) . ' ';
    365 					}
    366 
    367 					if ($product['recurring']['duration']) {
    368 						$recurring .= sprintf($this->language->get('text_payment_description'), $this->currency->format($this->tax->calculate($product['recurring']['price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']), $product['recurring']['cycle'], $frequencies[$product['recurring']['frequency']], $product['recurring']['duration']);
    369 					} else {
    370 						$recurring .= sprintf($this->language->get('text_payment_cancel'), $this->currency->format($this->tax->calculate($product['recurring']['price'] * $product['quantity'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']), $product['recurring']['cycle'], $frequencies[$product['recurring']['frequency']], $product['recurring']['duration']);
    371 					}
    372 				}
    373 
    374 				$data['products'][] = array(
    375 					'cart_id'    => $product['cart_id'],
    376 					'product_id' => $product['product_id'],
    377 					'name'       => $product['name'],
    378 					'model'      => $product['model'],
    379 					'option'     => $option_data,
    380 					'recurring'  => $recurring,
    381 					'quantity'   => $product['quantity'],
    382 					'subtract'   => $product['subtract'],
    383 					'price'      => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
    384 					'total'      => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity'], $this->session->data['currency']),
    385 					'href'       => $this->url->link('product/product', 'product_id=' . $product['product_id'])
    386 				);
    387 			}
    388 
    389 			// Gift Voucher
    390 			$data['vouchers'] = array();
    391 
    392 			if (!empty($this->session->data['vouchers'])) {
    393 				foreach ($this->session->data['vouchers'] as $voucher) {
    394 					$data['vouchers'][] = array(
    395 						'description' => $voucher['description'],
    396 						'amount'      => $this->currency->format($voucher['amount'], $this->session->data['currency'])
    397 					);
    398 				}
    399 			}
    400 
    401 			$data['totals'] = array();
    402 
    403 			foreach ($order_data['totals'] as $total) {
    404 				$data['totals'][] = array(
    405 					'title' => $total['title'],
    406 					'text'  => $this->currency->format($total['value'], $this->session->data['currency'])
    407 				);
    408 			}
    409 
    410 			$data['payment'] = $this->load->controller('extension/payment/' . $this->session->data['payment_method']['code']);
    411 		} else {
    412 			$data['redirect'] = $redirect;
    413 		}
    414 
    415 		$this->response->setOutput($this->load->view('checkout/confirm', $data));
    416 	}
    417 }