shop.balmet.com

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

order.php (14827B)


      1 <?php
      2 class ControllerAccountOrder extends Controller {
      3 	public function index() {
      4 		if (!$this->customer->isLogged()) {
      5 			$this->session->data['redirect'] = $this->url->link('account/order', '', true);
      6 
      7 			$this->response->redirect($this->url->link('account/login', '', true));
      8 		}
      9 
     10 		$this->load->language('account/order');
     11 
     12 		$this->document->setTitle($this->language->get('heading_title'));
     13 		
     14 		$url = '';
     15 
     16 		if (isset($this->request->get['page'])) {
     17 			$url .= '&page=' . $this->request->get['page'];
     18 		}
     19 		
     20 		$data['breadcrumbs'] = array();
     21 
     22 		$data['breadcrumbs'][] = array(
     23 			'text' => $this->language->get('text_home'),
     24 			'href' => $this->url->link('common/home')
     25 		);
     26 
     27 		$data['breadcrumbs'][] = array(
     28 			'text' => $this->language->get('text_account'),
     29 			'href' => $this->url->link('account/account', '', true)
     30 		);
     31 		
     32 		$data['breadcrumbs'][] = array(
     33 			'text' => $this->language->get('heading_title'),
     34 			'href' => $this->url->link('account/order', $url, true)
     35 		);
     36 
     37 		if (isset($this->request->get['page'])) {
     38 			$page = $this->request->get['page'];
     39 		} else {
     40 			$page = 1;
     41 		}
     42 
     43 		$data['orders'] = array();
     44 
     45 		$this->load->model('account/order');
     46 
     47 		$order_total = $this->model_account_order->getTotalOrders();
     48 
     49 		$results = $this->model_account_order->getOrders(($page - 1) * 10, 10);
     50 
     51 		foreach ($results as $result) {
     52 			$product_total = $this->model_account_order->getTotalOrderProductsByOrderId($result['order_id']);
     53 			$voucher_total = $this->model_account_order->getTotalOrderVouchersByOrderId($result['order_id']);
     54 
     55 			$data['orders'][] = array(
     56 				'order_id'   => $result['order_id'],
     57 				'name'       => $result['firstname'] . ' ' . $result['lastname'],
     58 				'status'     => $result['status'],
     59 				'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
     60 				'products'   => ($product_total + $voucher_total),
     61 				'total'      => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
     62 				'view'       => $this->url->link('account/order/info', 'order_id=' . $result['order_id'], true),
     63 			);
     64 		}
     65 
     66 		$pagination = new Pagination();
     67 		$pagination->total = $order_total;
     68 		$pagination->page = $page;
     69 		$pagination->limit = 10;
     70 		$pagination->url = $this->url->link('account/order', 'page={page}', true);
     71 
     72 		$data['pagination'] = $pagination->render();
     73 
     74 		$data['results'] = sprintf($this->language->get('text_pagination'), ($order_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($order_total - 10)) ? $order_total : ((($page - 1) * 10) + 10), $order_total, ceil($order_total / 10));
     75 
     76 		$data['continue'] = $this->url->link('account/account', '', true);
     77 
     78 		$data['column_left'] = $this->load->controller('common/column_left');
     79 		$data['column_right'] = $this->load->controller('common/column_right');
     80 		$data['content_top'] = $this->load->controller('common/content_top');
     81 		$data['content_bottom'] = $this->load->controller('common/content_bottom');
     82 		$data['footer'] = $this->load->controller('common/footer');
     83 		$data['header'] = $this->load->controller('common/header');
     84 
     85 		$this->response->setOutput($this->load->view('account/order_list', $data));
     86 	}
     87 
     88 	public function info() {
     89 		$this->load->language('account/order');
     90 
     91 		if (isset($this->request->get['order_id'])) {
     92 			$order_id = $this->request->get['order_id'];
     93 		} else {
     94 			$order_id = 0;
     95 		}
     96 
     97 		if (!$this->customer->isLogged()) {
     98 			$this->session->data['redirect'] = $this->url->link('account/order/info', 'order_id=' . $order_id, true);
     99 
    100 			$this->response->redirect($this->url->link('account/login', '', true));
    101 		}
    102 
    103 		$this->load->model('account/order');
    104 
    105 		$order_info = $this->model_account_order->getOrder($order_id);
    106 
    107 		if ($order_info) {
    108 			$this->document->setTitle($this->language->get('text_order'));
    109 
    110 			$url = '';
    111 
    112 			if (isset($this->request->get['page'])) {
    113 				$url .= '&page=' . $this->request->get['page'];
    114 			}
    115 
    116 			$data['breadcrumbs'] = array();
    117 
    118 			$data['breadcrumbs'][] = array(
    119 				'text' => $this->language->get('text_home'),
    120 				'href' => $this->url->link('common/home')
    121 			);
    122 
    123 			$data['breadcrumbs'][] = array(
    124 				'text' => $this->language->get('text_account'),
    125 				'href' => $this->url->link('account/account', '', true)
    126 			);
    127 
    128 			$data['breadcrumbs'][] = array(
    129 				'text' => $this->language->get('heading_title'),
    130 				'href' => $this->url->link('account/order', $url, true)
    131 			);
    132 
    133 			$data['breadcrumbs'][] = array(
    134 				'text' => $this->language->get('text_order'),
    135 				'href' => $this->url->link('account/order/info', 'order_id=' . $this->request->get['order_id'] . $url, true)
    136 			);
    137 
    138 			if (isset($this->session->data['error'])) {
    139 				$data['error_warning'] = $this->session->data['error'];
    140 
    141 				unset($this->session->data['error']);
    142 			} else {
    143 				$data['error_warning'] = '';
    144 			}
    145 
    146 			if (isset($this->session->data['success'])) {
    147 				$data['success'] = $this->session->data['success'];
    148 
    149 				unset($this->session->data['success']);
    150 			} else {
    151 				$data['success'] = '';
    152 			}
    153 
    154 			if ($order_info['invoice_no']) {
    155 				$data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
    156 			} else {
    157 				$data['invoice_no'] = '';
    158 			}
    159 
    160 			$data['order_id'] = $this->request->get['order_id'];
    161 			$data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
    162 
    163 			if ($order_info['payment_address_format']) {
    164 				$format = $order_info['payment_address_format'];
    165 			} else {
    166 				$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
    167 			}
    168 
    169 			$find = array(
    170 				'{firstname}',
    171 				'{lastname}',
    172 				'{company}',
    173 				'{address_1}',
    174 				'{address_2}',
    175 				'{city}',
    176 				'{postcode}',
    177 				'{zone}',
    178 				'{zone_code}',
    179 				'{country}'
    180 			);
    181 
    182 			$replace = array(
    183 				'firstname' => $order_info['payment_firstname'],
    184 				'lastname'  => $order_info['payment_lastname'],
    185 				'company'   => $order_info['payment_company'],
    186 				'address_1' => $order_info['payment_address_1'],
    187 				'address_2' => $order_info['payment_address_2'],
    188 				'city'      => $order_info['payment_city'],
    189 				'postcode'  => $order_info['payment_postcode'],
    190 				'zone'      => $order_info['payment_zone'],
    191 				'zone_code' => $order_info['payment_zone_code'],
    192 				'country'   => $order_info['payment_country']
    193 			);
    194 
    195 			$data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
    196 
    197 			$data['payment_method'] = $order_info['payment_method'];
    198 
    199 			if ($order_info['shipping_address_format']) {
    200 				$format = $order_info['shipping_address_format'];
    201 			} else {
    202 				$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
    203 			}
    204 
    205 			$find = array(
    206 				'{firstname}',
    207 				'{lastname}',
    208 				'{company}',
    209 				'{address_1}',
    210 				'{address_2}',
    211 				'{city}',
    212 				'{postcode}',
    213 				'{zone}',
    214 				'{zone_code}',
    215 				'{country}'
    216 			);
    217 
    218 			$replace = array(
    219 				'firstname' => $order_info['shipping_firstname'],
    220 				'lastname'  => $order_info['shipping_lastname'],
    221 				'company'   => $order_info['shipping_company'],
    222 				'address_1' => $order_info['shipping_address_1'],
    223 				'address_2' => $order_info['shipping_address_2'],
    224 				'city'      => $order_info['shipping_city'],
    225 				'postcode'  => $order_info['shipping_postcode'],
    226 				'zone'      => $order_info['shipping_zone'],
    227 				'zone_code' => $order_info['shipping_zone_code'],
    228 				'country'   => $order_info['shipping_country']
    229 			);
    230 
    231 			$data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
    232 
    233 			$data['shipping_method'] = $order_info['shipping_method'];
    234 
    235 			$this->load->model('catalog/product');
    236 			$this->load->model('tool/upload');
    237 
    238 			// Products
    239 			$data['products'] = array();
    240 
    241 			$products = $this->model_account_order->getOrderProducts($this->request->get['order_id']);
    242 
    243 			foreach ($products as $product) {
    244 				$option_data = array();
    245 
    246 				$options = $this->model_account_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']);
    247 
    248 				foreach ($options as $option) {
    249 					if ($option['type'] != 'file') {
    250 						$value = $option['value'];
    251 					} else {
    252 						$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
    253 
    254 						if ($upload_info) {
    255 							$value = $upload_info['name'];
    256 						} else {
    257 							$value = '';
    258 						}
    259 					}
    260 
    261 					$option_data[] = array(
    262 						'name'  => $option['name'],
    263 						'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value)
    264 					);
    265 				}
    266 
    267 				$product_info = $this->model_catalog_product->getProduct($product['product_id']);
    268 
    269 				if ($product_info) {
    270 					$reorder = $this->url->link('account/order/reorder', 'order_id=' . $order_id . '&order_product_id=' . $product['order_product_id'], true);
    271 				} else {
    272 					$reorder = '';
    273 				}
    274 
    275 				$data['products'][] = array(
    276 					'name'     => $product['name'],
    277 					'model'    => $product['model'],
    278 					'option'   => $option_data,
    279 					'quantity' => $product['quantity'],
    280 					'price'    => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
    281 					'total'    => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']),
    282 					'reorder'  => $reorder,
    283 					'return'   => $this->url->link('account/return/add', 'order_id=' . $order_info['order_id'] . '&product_id=' . $product['product_id'], true)
    284 				);
    285 			}
    286 
    287 			// Voucher
    288 			$data['vouchers'] = array();
    289 
    290 			$vouchers = $this->model_account_order->getOrderVouchers($this->request->get['order_id']);
    291 
    292 			foreach ($vouchers as $voucher) {
    293 				$data['vouchers'][] = array(
    294 					'description' => $voucher['description'],
    295 					'amount'      => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'])
    296 				);
    297 			}
    298 
    299 			// Totals
    300 			$data['totals'] = array();
    301 
    302 			$totals = $this->model_account_order->getOrderTotals($this->request->get['order_id']);
    303 
    304 			foreach ($totals as $total) {
    305 				$data['totals'][] = array(
    306 					'title' => $total['title'],
    307 					'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
    308 				);
    309 			}
    310 
    311 			$data['comment'] = nl2br($order_info['comment']);
    312 
    313 			// History
    314 			$data['histories'] = array();
    315 
    316 			$results = $this->model_account_order->getOrderHistories($this->request->get['order_id']);
    317 
    318 			foreach ($results as $result) {
    319 				$data['histories'][] = array(
    320 					'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
    321 					'status'     => $result['status'],
    322 					'comment'    => $result['notify'] ? nl2br($result['comment']) : ''
    323 				);
    324 			}
    325 
    326 			$data['continue'] = $this->url->link('account/order', '', true);
    327 
    328 			$data['column_left'] = $this->load->controller('common/column_left');
    329 			$data['column_right'] = $this->load->controller('common/column_right');
    330 			$data['content_top'] = $this->load->controller('common/content_top');
    331 			$data['content_bottom'] = $this->load->controller('common/content_bottom');
    332 			$data['footer'] = $this->load->controller('common/footer');
    333 			$data['header'] = $this->load->controller('common/header');
    334 
    335 			$this->response->setOutput($this->load->view('account/order_info', $data));
    336 		} else {
    337 			return new Action('error/not_found');
    338 		}
    339 	}
    340 
    341 	public function reorder() {
    342 		$this->load->language('account/order');
    343 
    344 		if (isset($this->request->get['order_id'])) {
    345 			$order_id = $this->request->get['order_id'];
    346 		} else {
    347 			$order_id = 0;
    348 		}
    349 
    350 		$this->load->model('account/order');
    351 
    352 		$order_info = $this->model_account_order->getOrder($order_id);
    353 
    354 		if ($order_info) {
    355 			if (isset($this->request->get['order_product_id'])) {
    356 				$order_product_id = $this->request->get['order_product_id'];
    357 			} else {
    358 				$order_product_id = 0;
    359 			}
    360 
    361 			$order_product_info = $this->model_account_order->getOrderProduct($order_id, $order_product_id);
    362 
    363 			if ($order_product_info) {
    364 				$this->load->model('catalog/product');
    365 
    366 				$product_info = $this->model_catalog_product->getProduct($order_product_info['product_id']);
    367 
    368 				if ($product_info) {
    369 					$option_data = array();
    370 
    371 					$order_options = $this->model_account_order->getOrderOptions($order_product_info['order_id'], $order_product_id);
    372 
    373 					foreach ($order_options as $order_option) {
    374 						if ($order_option['type'] == 'select' || $order_option['type'] == 'radio' || $order_option['type'] == 'image') {
    375 							$option_data[$order_option['product_option_id']] = $order_option['product_option_value_id'];
    376 						} elseif ($order_option['type'] == 'checkbox') {
    377 							$option_data[$order_option['product_option_id']][] = $order_option['product_option_value_id'];
    378 						} elseif ($order_option['type'] == 'text' || $order_option['type'] == 'textarea' || $order_option['type'] == 'date' || $order_option['type'] == 'datetime' || $order_option['type'] == 'time') {
    379 							$option_data[$order_option['product_option_id']] = $order_option['value'];
    380 						} elseif ($order_option['type'] == 'file') {
    381 							$option_data[$order_option['product_option_id']] = $this->encryption->encrypt($this->config->get('config_encryption'), $order_option['value']);
    382 						}
    383 					}
    384 
    385 					$this->cart->add($order_product_info['product_id'], $order_product_info['quantity'], $option_data);
    386 
    387 					$this->session->data['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $product_info['product_id']), $product_info['name'], $this->url->link('checkout/cart'));
    388 
    389 					unset($this->session->data['shipping_method']);
    390 					unset($this->session->data['shipping_methods']);
    391 					unset($this->session->data['payment_method']);
    392 					unset($this->session->data['payment_methods']);
    393 				} else {
    394 					$this->session->data['error'] = sprintf($this->language->get('error_reorder'), $order_product_info['name']);
    395 				}
    396 			}
    397 		}
    398 
    399 		$this->response->redirect($this->url->link('account/order/info', 'order_id=' . $order_id));
    400 	}
    401 }